mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 11:34:05 +09:00
TextLineInput endcompose of IME
This commit is contained in:
@@ -90,10 +90,6 @@ class UIItemTextLineInput(
|
|||||||
)
|
)
|
||||||
|
|
||||||
var isActive: Boolean = true
|
var isActive: Boolean = true
|
||||||
set(value) {
|
|
||||||
resetIME()
|
|
||||||
field = value
|
|
||||||
}
|
|
||||||
|
|
||||||
var cursorX = 0
|
var cursorX = 0
|
||||||
var cursorDrawScroll = 0
|
var cursorDrawScroll = 0
|
||||||
@@ -171,10 +167,11 @@ class UIItemTextLineInput(
|
|||||||
val ime = getIME()
|
val ime = getIME()
|
||||||
|
|
||||||
if (keycodes.contains(Input.Keys.V) && (keycodes.contains(Input.Keys.CONTROL_LEFT) || keycodes.contains(Input.Keys.CONTROL_RIGHT))) {
|
if (keycodes.contains(Input.Keys.V) && (keycodes.contains(Input.Keys.CONTROL_LEFT) || keycodes.contains(Input.Keys.CONTROL_RIGHT))) {
|
||||||
paste()
|
endComposing()
|
||||||
tryCursorBack()
|
paste(Clipboard.fetch().substringBefore('\n').substringBefore('\t').toCodePoints())
|
||||||
}
|
}
|
||||||
else if (keycodes.contains(Input.Keys.C) && (keycodes.contains(Input.Keys.CONTROL_LEFT) || keycodes.contains(Input.Keys.CONTROL_RIGHT))) {
|
else if (keycodes.contains(Input.Keys.C) && (keycodes.contains(Input.Keys.CONTROL_LEFT) || keycodes.contains(Input.Keys.CONTROL_RIGHT))) {
|
||||||
|
endComposing()
|
||||||
copyToClipboard()
|
copyToClipboard()
|
||||||
}
|
}
|
||||||
else if (keycodes.contains(Input.Keys.BACKSPACE)) {
|
else if (keycodes.contains(Input.Keys.BACKSPACE)) {
|
||||||
@@ -200,22 +197,28 @@ class UIItemTextLineInput(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (cursorX > 0 && keycodes.contains(Input.Keys.LEFT)) {
|
else if (keycodes.contains(Input.Keys.LEFT)) {
|
||||||
// TODO IME endComposing()
|
endComposing()
|
||||||
cursorX -= 1
|
|
||||||
cursorDrawX = App.fontGame.getWidth(CodepointSequence(textbuf.subList(0, cursorX)))
|
if (cursorX > 0) {
|
||||||
tryCursorForward()
|
cursorX -= 1
|
||||||
if (cursorX <= 0) {
|
cursorDrawX = App.fontGame.getWidth(CodepointSequence(textbuf.subList(0, cursorX)))
|
||||||
cursorX = 0
|
tryCursorForward()
|
||||||
cursorDrawX = 0
|
if (cursorX <= 0) {
|
||||||
cursorDrawScroll = 0
|
cursorX = 0
|
||||||
|
cursorDrawX = 0
|
||||||
|
cursorDrawScroll = 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (cursorX < textbuf.size && keycodes.contains(Input.Keys.RIGHT)) {
|
else if (keycodes.contains(Input.Keys.RIGHT)) {
|
||||||
// TODO IME endComposing()
|
endComposing()
|
||||||
cursorX += 1
|
|
||||||
cursorDrawX = App.fontGame.getWidth(CodepointSequence(textbuf.subList(0, cursorX)))
|
if (cursorX < textbuf.size) {
|
||||||
tryCursorBack()
|
cursorX += 1
|
||||||
|
cursorDrawX = App.fontGame.getWidth(CodepointSequence(textbuf.subList(0, cursorX)))
|
||||||
|
tryCursorBack()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// accept:
|
// accept:
|
||||||
// - literal "<"
|
// - literal "<"
|
||||||
@@ -232,7 +235,7 @@ class UIItemTextLineInput(
|
|||||||
}
|
}
|
||||||
else char.toCodePoints()
|
else char.toCodePoints()
|
||||||
|
|
||||||
println("textinput codepoints: ${codepoints.map { it.toString(16) }.joinToString()}")
|
// println("textinput codepoints: ${codepoints.map { it.toString(16) }.joinToString()}")
|
||||||
|
|
||||||
if (!maxLen.exceeds(textbuf, codepoints)) {
|
if (!maxLen.exceeds(textbuf, codepoints)) {
|
||||||
textbuf.addAll(cursorX, codepoints)
|
textbuf.addAll(cursorX, codepoints)
|
||||||
@@ -243,7 +246,9 @@ class UIItemTextLineInput(
|
|||||||
tryCursorBack()
|
tryCursorBack()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO IME endComposing() on hitting Enter
|
else if (keycodes.contains(Input.Keys.ENTER) || keycodes.contains(Input.Keys.NUMPAD_ENTER)) {
|
||||||
|
endComposing()
|
||||||
|
}
|
||||||
|
|
||||||
// don't put innards of tryCursorBack/Forward here -- you absolutely don't want that behaviour
|
// don't put innards of tryCursorBack/Forward here -- you absolutely don't want that behaviour
|
||||||
|
|
||||||
@@ -260,8 +265,8 @@ class UIItemTextLineInput(
|
|||||||
cursorOn = !cursorOn
|
cursorOn = !cursorOn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (oldActive) { // just became disactivated
|
else if (oldActive) { // just became deactivated
|
||||||
// TODO IME endComposing()
|
endComposing()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mouseDown && !mouseLatched && (enablePasteButton && enableIMEButton && mouseUpOnButton1 || enableIMEButton && !enablePasteButton && mouseUpOnButton2)) {
|
if (mouseDown && !mouseLatched && (enablePasteButton && enableIMEButton && mouseUpOnButton1 || enableIMEButton && !enablePasteButton && mouseUpOnButton2)) {
|
||||||
@@ -269,7 +274,7 @@ class UIItemTextLineInput(
|
|||||||
mouseLatched = true
|
mouseLatched = true
|
||||||
}
|
}
|
||||||
else if (mouseDown && !mouseLatched && (enablePasteButton && enableIMEButton && mouseUpOnButton2 || enablePasteButton && !enableIMEButton && mouseUpOnButton2)) {
|
else if (mouseDown && !mouseLatched && (enablePasteButton && enableIMEButton && mouseUpOnButton2 || enablePasteButton && !enableIMEButton && mouseUpOnButton2)) {
|
||||||
paste()
|
paste(Clipboard.fetch().substringBefore('\n').substringBefore('\t').toCodePoints())
|
||||||
mouseLatched = true
|
mouseLatched = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,6 +283,15 @@ class UIItemTextLineInput(
|
|||||||
|
|
||||||
private fun String.toCodePoints() = this.codePoints().toList().filter { it > 0 }
|
private fun String.toCodePoints() = this.codePoints().toList().filter { it > 0 }
|
||||||
|
|
||||||
|
private fun endComposing() {
|
||||||
|
getIME()?.let {
|
||||||
|
val s = it.endCompose()
|
||||||
|
paste(s.toCodePoints())
|
||||||
|
}
|
||||||
|
fboUpdateLatch = true
|
||||||
|
resetIME()
|
||||||
|
}
|
||||||
|
|
||||||
private fun toggleIME() {
|
private fun toggleIME() {
|
||||||
if (App.getConfigString("inputmethod") == "none") {
|
if (App.getConfigString("inputmethod") == "none") {
|
||||||
imeOn = false
|
imeOn = false
|
||||||
@@ -294,11 +308,9 @@ class UIItemTextLineInput(
|
|||||||
composingView = CodepointSequence()
|
composingView = CodepointSequence()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun paste() {
|
private fun paste(codepoints: List<Int>) {
|
||||||
resetIME()
|
resetIME()
|
||||||
|
|
||||||
val codepoints = Clipboard.fetch().substringBefore('\n').substringBefore('\t').toCodePoints()
|
|
||||||
|
|
||||||
val actuallyInserted = arrayListOf(0)
|
val actuallyInserted = arrayListOf(0)
|
||||||
|
|
||||||
for (c in codepoints) {
|
for (c in codepoints) {
|
||||||
|
|||||||
Reference in New Issue
Block a user