Remove text from text field when doing right mouse click, and text field is not multiline

This commit is contained in:
DBotThePony 2024-01-04 20:01:14 +07:00
parent 54ba7e94c6
commit 486c9b00c9
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 14 additions and 12 deletions

View File

@ -27,7 +27,7 @@ class HoloSignScreen(menu: HoloSignMenu, inventory: Inventory, title: Component)
val input = NetworkedStringInputPanel(this, frame, backend = menu.text)
input.dock = Dock.FILL
input.multiLine = true
input.isMultiLine = true
val lock = CheckBoxLabelInputPanel(this, frame, menu.locked, TranslatableComponent("otm.gui.lock_holo_screen"))
lock.dock = Dock.BOTTOM

View File

@ -86,19 +86,19 @@ open class TextInputPanel<out S : Screen>(
private val cursorLine = this@TextInputPanel.cursorLine
private val cursorCharacter = this@TextInputPanel.cursorRow
private val selections = Int2ObjectAVLTreeMap(this@TextInputPanel.selections)
private val multiLine = this@TextInputPanel.multiLine
private val multiLine = this@TextInputPanel.isMultiLine
fun apply() {
this@TextInputPanel.lines.clear()
if (this@TextInputPanel.multiLine)
if (this@TextInputPanel.isMultiLine)
this@TextInputPanel.lines.addAll(lines)
else
this@TextInputPanel.lines.add(lines.joinToString(""))
this@TextInputPanel.selections.clear()
if (this@TextInputPanel.multiLine && multiLine)
if (this@TextInputPanel.isMultiLine && multiLine)
this@TextInputPanel.selections.putAll(selections)
this@TextInputPanel.cursorRow = cursorCharacter
@ -129,7 +129,7 @@ open class TextInputPanel<out S : Screen>(
}
var debugDraw = false
var multiLine = false
var isMultiLine = false
set(value) {
if (field == value) return
@ -279,7 +279,7 @@ open class TextInputPanel<out S : Screen>(
if (index < 0)
throw IndexOutOfBoundsException("negative index $index")
if (!multiLine && index != 0)
if (!isMultiLine && index != 0)
throw IllegalStateException("Not accepting newlines")
lines.ensureCapacity(index)
@ -305,7 +305,7 @@ open class TextInputPanel<out S : Screen>(
}
fun insertLine(index: Int, value: String = "") {
if (!multiLine && lines.isNotEmpty())
if (!isMultiLine && lines.isNotEmpty())
throw IllegalStateException("Not accepting newlines")
lines.ensureCapacity(index)
@ -461,7 +461,7 @@ open class TextInputPanel<out S : Screen>(
cursorRow = 0
textCache = null
if (multiLine) {
if (isMultiLine) {
lines.addAll(value.split(NEWLINES))
} else {
lines.add(value.replace(NEWLINES, ""))
@ -668,7 +668,7 @@ open class TextInputPanel<out S : Screen>(
}
if (key == InputConstants.KEY_RETURN) {
if (multiLine) {
if (isMultiLine) {
if (!minecraft.window.isShiftDown && !minecraft.window.isCtrlDown)
wipeSelection()
@ -905,7 +905,7 @@ open class TextInputPanel<out S : Screen>(
wipeSelection()
pushbackSnapshot()
if (multiLine) {
if (isMultiLine) {
var index = cursorRow + (0 until cursorLine).iterator().map { this[it]?.length ?: 0 }.reduce(0, Int::plus)
val insert = minecraft.keyboardHandler.clipboard.replace("\t", " ").filter { acceptsCharacter(it, 0, index++) }.split(NEWLINES).toMutableList()
val actualLastSize = insert.lastOrNull()?.length ?: 0
@ -1068,7 +1068,7 @@ open class TextInputPanel<out S : Screen>(
wipeSelection()
if (!multiLine)
if (!isMultiLine)
cursorLine = 0
var line = this[cursorLine]
@ -1125,7 +1125,7 @@ open class TextInputPanel<out S : Screen>(
var topPadding = dockPadding.top
if (multiLine) {
if (isMultiLine) {
val heightInLines = ((height - dockPadding.top - dockPadding.bottom) / (font.lineHeight + rowSpacing)).toInt()
if (heightInLines > 0) {
@ -1301,6 +1301,8 @@ open class TextInputPanel<out S : Screen>(
isSelecting = true
tryToGrabMouseInput()
} else if (button == InputConstants.MOUSE_BUTTON_RIGHT && !isMultiLine) {
text = ""
}
return true