From c4b36d497f534f4d1262c187133b13d54c6441ba Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Wed, 8 Mar 2023 16:59:27 +0700 Subject: [PATCH] Polishing fixes to TextInputPanel --- .../screen/panels/input/TextInputPanel.kt | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/input/TextInputPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/input/TextInputPanel.kt index c93619f69..d6d118db5 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/input/TextInputPanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/input/TextInputPanel.kt @@ -881,6 +881,11 @@ open class TextInputPanel( selections[i] = TextSelection(0, line.length + 1) } + if (lines.isNotEmpty()) { + cursorLine = lines.size - 1 + cursorRow = lines[lines.size - 1].length + } + return true } @@ -889,30 +894,43 @@ open class TextInputPanel( pushbackSnapshot() if (multiLine) { - val insert = minecraft.keyboardHandler.clipboard.replace("\t", " ").split(NEWLINES) - + val insert = minecraft.keyboardHandler.clipboard.replace("\t", " ").split(NEWLINES).toMutableList() + val actualLastSize = insert.lastOrNull()?.length ?: 0 val line = this[cursorLine] if (line == null) { insertLine(cursorLine, insert[0]) + cursorRow = insert[0].length } else if (line.isEmpty()) { this[cursorLine] = insert[0] + cursorRow = insert[0].length } else { - this[cursorLine] = line.substring(0, cursorRow.coerceAtMost(line.length - 1)) + insert[0] + line.substring(cursorRow.coerceAtMost(line.length)) + if (insert.size == 1) { + this[cursorLine] = line.substring(0, cursorRow.coerceAtMost(line.length - 1)) + insert[0] + line.substring(cursorRow.coerceAtMost(line.length)) + } else { + this[cursorLine] = line.substring(0, cursorRow.coerceAtMost(line.length - 1)) + insert[0] + insert[insert.size - 1] += line.substring(cursorRow.coerceAtMost(line.length)) + } + + cursorRow += insert[0].length } for (i in 1 until insert.size - 1) { insertLine(++cursorLine, insert[i]) + cursorRow = insert[i].length } - if (insert.size >= 3) { + if (insert.size >= 2) { val line2 = this[++cursorLine] + val last = insert.last() if (line2 == null) { - insertLine(cursorLine, insert.last()) + insertLine(cursorLine, last) } else { - this[cursorLine] = insert.last() + line2 + this[cursorLine] = last + line2 } + + cursorRow = actualLastSize } } else { val insert = minecraft.keyboardHandler.clipboard.replace("\t", " ").replace(NEWLINES, "") @@ -920,10 +938,13 @@ open class TextInputPanel( if (line == null) { insertLine(cursorLine, insert) + cursorRow = insert.length } else if (line.isEmpty()) { this[cursorLine] = insert + cursorRow = insert.length } else { this[cursorLine] = line.substring(0, cursorRow.coerceAtMost(line.length - 1)) + insert + line.substring(cursorRow.coerceAtMost(line.length)) + cursorRow += insert.length } } @@ -1082,6 +1103,8 @@ open class TextInputPanel( } else if (w >= width - dockPadding.right) { scrollPixels += 30f } + } else { + scrollPixels = 0f } stack.pushPose()