Remove text from text field when doing right mouse click, and text field is not multiline
This commit is contained in:
parent
54ba7e94c6
commit
486c9b00c9
@ -27,7 +27,7 @@ class HoloSignScreen(menu: HoloSignMenu, inventory: Inventory, title: Component)
|
|||||||
|
|
||||||
val input = NetworkedStringInputPanel(this, frame, backend = menu.text)
|
val input = NetworkedStringInputPanel(this, frame, backend = menu.text)
|
||||||
input.dock = Dock.FILL
|
input.dock = Dock.FILL
|
||||||
input.multiLine = true
|
input.isMultiLine = true
|
||||||
|
|
||||||
val lock = CheckBoxLabelInputPanel(this, frame, menu.locked, TranslatableComponent("otm.gui.lock_holo_screen"))
|
val lock = CheckBoxLabelInputPanel(this, frame, menu.locked, TranslatableComponent("otm.gui.lock_holo_screen"))
|
||||||
lock.dock = Dock.BOTTOM
|
lock.dock = Dock.BOTTOM
|
||||||
|
@ -86,19 +86,19 @@ open class TextInputPanel<out S : Screen>(
|
|||||||
private val cursorLine = this@TextInputPanel.cursorLine
|
private val cursorLine = this@TextInputPanel.cursorLine
|
||||||
private val cursorCharacter = this@TextInputPanel.cursorRow
|
private val cursorCharacter = this@TextInputPanel.cursorRow
|
||||||
private val selections = Int2ObjectAVLTreeMap(this@TextInputPanel.selections)
|
private val selections = Int2ObjectAVLTreeMap(this@TextInputPanel.selections)
|
||||||
private val multiLine = this@TextInputPanel.multiLine
|
private val multiLine = this@TextInputPanel.isMultiLine
|
||||||
|
|
||||||
fun apply() {
|
fun apply() {
|
||||||
this@TextInputPanel.lines.clear()
|
this@TextInputPanel.lines.clear()
|
||||||
|
|
||||||
if (this@TextInputPanel.multiLine)
|
if (this@TextInputPanel.isMultiLine)
|
||||||
this@TextInputPanel.lines.addAll(lines)
|
this@TextInputPanel.lines.addAll(lines)
|
||||||
else
|
else
|
||||||
this@TextInputPanel.lines.add(lines.joinToString(""))
|
this@TextInputPanel.lines.add(lines.joinToString(""))
|
||||||
|
|
||||||
|
|
||||||
this@TextInputPanel.selections.clear()
|
this@TextInputPanel.selections.clear()
|
||||||
if (this@TextInputPanel.multiLine && multiLine)
|
if (this@TextInputPanel.isMultiLine && multiLine)
|
||||||
this@TextInputPanel.selections.putAll(selections)
|
this@TextInputPanel.selections.putAll(selections)
|
||||||
|
|
||||||
this@TextInputPanel.cursorRow = cursorCharacter
|
this@TextInputPanel.cursorRow = cursorCharacter
|
||||||
@ -129,7 +129,7 @@ open class TextInputPanel<out S : Screen>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
var debugDraw = false
|
var debugDraw = false
|
||||||
var multiLine = false
|
var isMultiLine = false
|
||||||
set(value) {
|
set(value) {
|
||||||
if (field == value) return
|
if (field == value) return
|
||||||
|
|
||||||
@ -279,7 +279,7 @@ open class TextInputPanel<out S : Screen>(
|
|||||||
if (index < 0)
|
if (index < 0)
|
||||||
throw IndexOutOfBoundsException("negative index $index")
|
throw IndexOutOfBoundsException("negative index $index")
|
||||||
|
|
||||||
if (!multiLine && index != 0)
|
if (!isMultiLine && index != 0)
|
||||||
throw IllegalStateException("Not accepting newlines")
|
throw IllegalStateException("Not accepting newlines")
|
||||||
|
|
||||||
lines.ensureCapacity(index)
|
lines.ensureCapacity(index)
|
||||||
@ -305,7 +305,7 @@ open class TextInputPanel<out S : Screen>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun insertLine(index: Int, value: String = "") {
|
fun insertLine(index: Int, value: String = "") {
|
||||||
if (!multiLine && lines.isNotEmpty())
|
if (!isMultiLine && lines.isNotEmpty())
|
||||||
throw IllegalStateException("Not accepting newlines")
|
throw IllegalStateException("Not accepting newlines")
|
||||||
|
|
||||||
lines.ensureCapacity(index)
|
lines.ensureCapacity(index)
|
||||||
@ -461,7 +461,7 @@ open class TextInputPanel<out S : Screen>(
|
|||||||
cursorRow = 0
|
cursorRow = 0
|
||||||
textCache = null
|
textCache = null
|
||||||
|
|
||||||
if (multiLine) {
|
if (isMultiLine) {
|
||||||
lines.addAll(value.split(NEWLINES))
|
lines.addAll(value.split(NEWLINES))
|
||||||
} else {
|
} else {
|
||||||
lines.add(value.replace(NEWLINES, ""))
|
lines.add(value.replace(NEWLINES, ""))
|
||||||
@ -668,7 +668,7 @@ open class TextInputPanel<out S : Screen>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (key == InputConstants.KEY_RETURN) {
|
if (key == InputConstants.KEY_RETURN) {
|
||||||
if (multiLine) {
|
if (isMultiLine) {
|
||||||
if (!minecraft.window.isShiftDown && !minecraft.window.isCtrlDown)
|
if (!minecraft.window.isShiftDown && !minecraft.window.isCtrlDown)
|
||||||
wipeSelection()
|
wipeSelection()
|
||||||
|
|
||||||
@ -905,7 +905,7 @@ open class TextInputPanel<out S : Screen>(
|
|||||||
wipeSelection()
|
wipeSelection()
|
||||||
pushbackSnapshot()
|
pushbackSnapshot()
|
||||||
|
|
||||||
if (multiLine) {
|
if (isMultiLine) {
|
||||||
var index = cursorRow + (0 until cursorLine).iterator().map { this[it]?.length ?: 0 }.reduce(0, Int::plus)
|
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 insert = minecraft.keyboardHandler.clipboard.replace("\t", " ").filter { acceptsCharacter(it, 0, index++) }.split(NEWLINES).toMutableList()
|
||||||
val actualLastSize = insert.lastOrNull()?.length ?: 0
|
val actualLastSize = insert.lastOrNull()?.length ?: 0
|
||||||
@ -1068,7 +1068,7 @@ open class TextInputPanel<out S : Screen>(
|
|||||||
|
|
||||||
wipeSelection()
|
wipeSelection()
|
||||||
|
|
||||||
if (!multiLine)
|
if (!isMultiLine)
|
||||||
cursorLine = 0
|
cursorLine = 0
|
||||||
|
|
||||||
var line = this[cursorLine]
|
var line = this[cursorLine]
|
||||||
@ -1125,7 +1125,7 @@ open class TextInputPanel<out S : Screen>(
|
|||||||
|
|
||||||
var topPadding = dockPadding.top
|
var topPadding = dockPadding.top
|
||||||
|
|
||||||
if (multiLine) {
|
if (isMultiLine) {
|
||||||
val heightInLines = ((height - dockPadding.top - dockPadding.bottom) / (font.lineHeight + rowSpacing)).toInt()
|
val heightInLines = ((height - dockPadding.top - dockPadding.bottom) / (font.lineHeight + rowSpacing)).toInt()
|
||||||
|
|
||||||
if (heightInLines > 0) {
|
if (heightInLines > 0) {
|
||||||
@ -1301,6 +1301,8 @@ open class TextInputPanel<out S : Screen>(
|
|||||||
|
|
||||||
isSelecting = true
|
isSelecting = true
|
||||||
tryToGrabMouseInput()
|
tryToGrabMouseInput()
|
||||||
|
} else if (button == InputConstants.MOUSE_BUTTON_RIGHT && !isMultiLine) {
|
||||||
|
text = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
Loading…
Reference in New Issue
Block a user