Skip to content

Commit 70b8219

Browse files
committed
Fixed multiline pasting for checklist (#99)
1 parent 470ee6d commit 70b8219

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

app/src/main/kotlin/org/fossify/notes/dialogs/NewChecklistItemDialog.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class NewChecklistItemDialog(val activity: Activity, callback: (titles: ArrayLis
5757
}
5858
}
5959

60-
private fun addNewEditText() {
60+
private fun addNewEditText(initialText: String? = null) {
6161
ItemAddChecklistBinding.inflate(activity.layoutInflater).apply {
6262
titleEditText.setOnEditorActionListener { _, actionId, _ ->
6363
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
6767
false
6868
}
6969
}
70+
titleEditText.onTextChangeListener { text ->
71+
val lines = text.split("\n").filter { it.trim().isNotEmpty() }
72+
if (lines.size > 1) {
73+
lines.forEachIndexed { i, line ->
74+
if (i == 0) {
75+
titleEditText.setText(line)
76+
} else {
77+
addNewEditText(line)
78+
}
79+
}
80+
}
81+
}
82+
if (initialText != null) {
83+
titleEditText.setText(initialText)
84+
}
7085
titles.add(titleEditText)
7186
binding.checklistHolder.addView(this.root)
7287
activity.updateTextColors(binding.checklistHolder)

0 commit comments

Comments
 (0)