diff --git a/app/src/main/kotlin/org/fossify/notes/dialogs/NewChecklistItemDialog.kt b/app/src/main/kotlin/org/fossify/notes/dialogs/NewChecklistItemDialog.kt index 9f57ac2f..df91d613 100644 --- a/app/src/main/kotlin/org/fossify/notes/dialogs/NewChecklistItemDialog.kt +++ b/app/src/main/kotlin/org/fossify/notes/dialogs/NewChecklistItemDialog.kt @@ -57,18 +57,39 @@ class NewChecklistItemDialog(val activity: Activity, callback: (titles: ArrayLis } } - private fun addNewEditText() { + private fun addNewEditText(initialText: String? = null, position: Int? = null) { ItemAddChecklistBinding.inflate(activity.layoutInflater).apply { titleEditText.setOnEditorActionListener { _, actionId, _ -> if (actionId == EditorInfo.IME_ACTION_NEXT || actionId == EditorInfo.IME_ACTION_DONE || actionId == KeyEvent.KEYCODE_ENTER) { - addNewEditText() + addNewEditText(position = titles.indexOf(titleEditText) + 1) true } else { false } } - titles.add(titleEditText) - binding.checklistHolder.addView(this.root) + titleEditText.onTextChangeListener { text -> + val lines = text.lines().filter { it.trim().isNotEmpty() } + if (lines.size > 1) { + val currentPosition = titles.indexOf(titleEditText) + lines.forEachIndexed { i, line -> + if (i == 0) { + titleEditText.setText(line) + } else { + addNewEditText(line, currentPosition + i) + } + } + } + } + if (initialText != null) { + titleEditText.append(initialText) + } + if (position != null && position < titles.size) { + titles.add(position, titleEditText) + binding.checklistHolder.addView(this.root, position) + } else { + titles.add(titleEditText) + binding.checklistHolder.addView(this.root) + } activity.updateTextColors(binding.checklistHolder) binding.dialogHolder.post { binding.dialogHolder.fullScroll(View.FOCUS_DOWN)