mirror of
https://github.com/FossifyOrg/Notes.git
synced 2026-06-11 10:09:29 -04:00
Merge pull request #105 from Aga-C/fix-multiline-pasting
Fixed multiline pasting for checklist (#99)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user