Fixed multiline pasting for checklist (#99)

This commit is contained in:
Agnieszka C
2025-03-19 22:00:36 +01:00
parent 470ee6d0ae
commit 70b82194e1

View File

@@ -57,7 +57,7 @@ class NewChecklistItemDialog(val activity: Activity, callback: (titles: ArrayLis
}
}
private fun addNewEditText() {
private fun addNewEditText(initialText: String? = null) {
ItemAddChecklistBinding.inflate(activity.layoutInflater).apply {
titleEditText.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_NEXT || actionId == EditorInfo.IME_ACTION_DONE || actionId == KeyEvent.KEYCODE_ENTER) {
@@ -67,6 +67,21 @@ class NewChecklistItemDialog(val activity: Activity, callback: (titles: ArrayLis
false
}
}
titleEditText.onTextChangeListener { text ->
val lines = text.split("\n").filter { it.trim().isNotEmpty() }
if (lines.size > 1) {
lines.forEachIndexed { i, line ->
if (i == 0) {
titleEditText.setText(line)
} else {
addNewEditText(line)
}
}
}
}
if (initialText != null) {
titleEditText.setText(initialText)
}
titles.add(titleEditText)
binding.checklistHolder.addView(this.root)
activity.updateTextColors(binding.checklistHolder)