1
1
package com.unciv.ui.screens.devconsole
2
2
3
+ import com.badlogic.gdx.Gdx
3
4
import com.badlogic.gdx.Input
4
5
import com.badlogic.gdx.graphics.Color
5
6
import com.badlogic.gdx.scenes.scene2d.Actor
@@ -11,10 +12,8 @@ import com.unciv.Constants
11
12
import com.unciv.GUI
12
13
import com.unciv.logic.civilization.Civilization
13
14
import com.unciv.logic.map.mapunit.MapUnit
15
+ import com.unciv.ui.components.extensions.*
14
16
import com.unciv.ui.components.widgets.UncivTextField
15
- import com.unciv.ui.components.extensions.surroundWithCircle
16
- import com.unciv.ui.components.extensions.toCheckBox
17
- import com.unciv.ui.components.extensions.toLabel
18
17
import com.unciv.ui.components.input.KeyCharAndCode
19
18
import com.unciv.ui.components.input.keyShortcuts
20
19
import com.unciv.ui.components.input.onClick
@@ -23,6 +22,7 @@ import com.unciv.ui.images.ImageGetter
23
22
import com.unciv.ui.popups.Popup
24
23
import com.unciv.ui.screens.devconsole.CliInput.Companion.splitToCliInput
25
24
import com.unciv.ui.screens.worldscreen.WorldScreen
25
+ import com.unciv.utils.Concurrency
26
26
27
27
28
28
class DevConsolePopup (val screen : WorldScreen ) : Popup(screen) {
@@ -65,6 +65,9 @@ class DevConsolePopup(val screen: WorldScreen) : Popup(screen) {
65
65
66
66
textField.keyShortcuts.add(Input .Keys .ENTER , ::onEnter)
67
67
textField.keyShortcuts.add(KeyCharAndCode .TAB , ::onAutocomplete)
68
+ textField.keyShortcuts.add(KeyCharAndCode .ctrlFromCode(Input .Keys .BACKSPACE ), ::onAltDelete)
69
+ textField.keyShortcuts.add(KeyCharAndCode .ctrlFromCode(Input .Keys .RIGHT ), ::onAltRight)
70
+ textField.keyShortcuts.add(KeyCharAndCode .ctrlFromCode(Input .Keys .LEFT ), ::onAltLeft)
68
71
69
72
keyShortcuts.add(Input .Keys .UP ) { navigateHistory(- 1 ) }
70
73
keyShortcuts.add(Input .Keys .DOWN ) { navigateHistory(1 ) }
@@ -102,6 +105,51 @@ class DevConsolePopup(val screen: WorldScreen) : Popup(screen) {
102
105
textField.text = textField.text.removeFromEnd(toRemove) + toAdd
103
106
textField.cursorPosition = Int .MAX_VALUE // because the setText implementation actively resets it after the paste it uses (auto capped at length)
104
107
}
108
+
109
+ private fun onAltDelete () {
110
+ if (! Gdx .input.isAltKeyPressed()) return
111
+
112
+ Concurrency .runOnGLThread {
113
+ val text = textField.text
114
+ // textField.cursorPosition-1 to avoid the case where we're currently on a space catching the space we're on
115
+ val lastSpace = text.lastIndexOf(' ' , textField.cursorPosition- 1 )
116
+ if (lastSpace == - 1 ) {
117
+ textField.text = text.removeRange(0 , textField.cursorPosition)
118
+ return @runOnGLThread
119
+ }
120
+ // KEEP the last space
121
+ textField.text = text.removeRange(lastSpace + 1 , textField.cursorPosition)
122
+ textField.cursorPosition = lastSpace + 1
123
+ }
124
+ }
125
+
126
+ private fun onAltRight () {
127
+ if (! Gdx .input.isAltKeyPressed()) return
128
+
129
+ Concurrency .runOnGLThread {
130
+ val text = textField.text
131
+ val nextSpace = text.indexOf(' ' , textField.cursorPosition)
132
+ if (nextSpace == - 1 ) {
133
+ textField.cursorPosition = text.length
134
+ return @runOnGLThread
135
+ }
136
+ textField.cursorPosition = nextSpace
137
+ }
138
+ }
139
+
140
+ private fun onAltLeft () {
141
+ if (! Gdx .input.isAltKeyPressed()) return
142
+
143
+ Concurrency .runOnGLThread {
144
+ val text = textField.text
145
+ val previousSpace = text.lastIndexOf(' ' , textField.cursorPosition- 1 )
146
+ if (previousSpace == - 1 ) {
147
+ textField.cursorPosition = 0
148
+ return @runOnGLThread
149
+ }
150
+ textField.cursorPosition = previousSpace
151
+ }
152
+ }
105
153
106
154
private fun navigateHistory (delta : Int ) {
107
155
if (history.isEmpty()) return
0 commit comments