Polishing fixes to TextInputPanel
This commit is contained in:
parent
fc0bc69488
commit
c4b36d497f
@ -881,6 +881,11 @@ open class TextInputPanel<out S : Screen>(
|
|||||||
selections[i] = TextSelection(0, line.length + 1)
|
selections[i] = TextSelection(0, line.length + 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lines.isNotEmpty()) {
|
||||||
|
cursorLine = lines.size - 1
|
||||||
|
cursorRow = lines[lines.size - 1].length
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -889,30 +894,43 @@ open class TextInputPanel<out S : Screen>(
|
|||||||
pushbackSnapshot()
|
pushbackSnapshot()
|
||||||
|
|
||||||
if (multiLine) {
|
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]
|
val line = this[cursorLine]
|
||||||
|
|
||||||
if (line == null) {
|
if (line == null) {
|
||||||
insertLine(cursorLine, insert[0])
|
insertLine(cursorLine, insert[0])
|
||||||
|
cursorRow = insert[0].length
|
||||||
} else if (line.isEmpty()) {
|
} else if (line.isEmpty()) {
|
||||||
this[cursorLine] = insert[0]
|
this[cursorLine] = insert[0]
|
||||||
|
cursorRow = insert[0].length
|
||||||
} else {
|
} else {
|
||||||
|
if (insert.size == 1) {
|
||||||
this[cursorLine] = line.substring(0, cursorRow.coerceAtMost(line.length - 1)) + insert[0] + line.substring(cursorRow.coerceAtMost(line.length))
|
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) {
|
for (i in 1 until insert.size - 1) {
|
||||||
insertLine(++cursorLine, insert[i])
|
insertLine(++cursorLine, insert[i])
|
||||||
|
cursorRow = insert[i].length
|
||||||
}
|
}
|
||||||
|
|
||||||
if (insert.size >= 3) {
|
if (insert.size >= 2) {
|
||||||
val line2 = this[++cursorLine]
|
val line2 = this[++cursorLine]
|
||||||
|
val last = insert.last()
|
||||||
|
|
||||||
if (line2 == null) {
|
if (line2 == null) {
|
||||||
insertLine(cursorLine, insert.last())
|
insertLine(cursorLine, last)
|
||||||
} else {
|
} else {
|
||||||
this[cursorLine] = insert.last() + line2
|
this[cursorLine] = last + line2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cursorRow = actualLastSize
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val insert = minecraft.keyboardHandler.clipboard.replace("\t", " ").replace(NEWLINES, "")
|
val insert = minecraft.keyboardHandler.clipboard.replace("\t", " ").replace(NEWLINES, "")
|
||||||
@ -920,10 +938,13 @@ open class TextInputPanel<out S : Screen>(
|
|||||||
|
|
||||||
if (line == null) {
|
if (line == null) {
|
||||||
insertLine(cursorLine, insert)
|
insertLine(cursorLine, insert)
|
||||||
|
cursorRow = insert.length
|
||||||
} else if (line.isEmpty()) {
|
} else if (line.isEmpty()) {
|
||||||
this[cursorLine] = insert
|
this[cursorLine] = insert
|
||||||
|
cursorRow = insert.length
|
||||||
} else {
|
} else {
|
||||||
this[cursorLine] = line.substring(0, cursorRow.coerceAtMost(line.length - 1)) + insert + line.substring(cursorRow.coerceAtMost(line.length))
|
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<out S : Screen>(
|
|||||||
} else if (w >= width - dockPadding.right) {
|
} else if (w >= width - dockPadding.right) {
|
||||||
scrollPixels += 30f
|
scrollPixels += 30f
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
scrollPixels = 0f
|
||||||
}
|
}
|
||||||
|
|
||||||
stack.pushPose()
|
stack.pushPose()
|
||||||
|
Loading…
Reference in New Issue
Block a user