Skip to content

Commit 956b58d

Browse files
authored
Merge pull request #4934 from DFHack/revert-4933-myk_keys
Revert "[widgets.EditField] use new text navigation keys"
2 parents 232ebeb + 9cb260d commit 956b58d

4 files changed

Lines changed: 20 additions & 28 deletions

File tree

docs/changelog.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ Template for new versions:
7878
- `buildingplan`: only consider building materials that can be accessed by at least one citizen/resident
7979
- Dreamfort: integrate with `preserve-rooms` to assign relevant rooms to nobles/adimistrators
8080
- Dreamfort: smooth tiles under statues and other large furniture that you can't easily smooth later
81-
- DFHack text edit fields now delete the character at the cursor when you hit the Delete key
82-
- DFHack text edit fields now move the cursor by one word left or right with Ctrl-Left and Ctrl-Right
83-
- DFHack text edit fields now move the cursor to the beginning or end of the line with Home and End
8481

8582
## Documentation
8683
- add documentation for ``dfhack.items.findType(string)`` and ``dfhack.items.findSubtype(string)``

docs/dev/Lua API.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5478,9 +5478,9 @@ The ``EditField`` cursor can be moved to where you want to insert/remove text.
54785478
You can click where you want the cursor to move or you can use any of the
54795479
following keyboard hotkeys:
54805480

5481-
- Left/Right arrow: move the cursor one character to the left or right
5482-
- Ctrl-Left/Ctrl-Right: move the cursor one word back or forward
5483-
- Home/End: move the cursor to the beginning/end of the text
5481+
- Left/Right arrow: move the cursor one character to the left or right.
5482+
- Ctrl-B/Ctrl-F: move the cursor one word back or forward.
5483+
- Ctrl-A/Ctrl-E: move the cursor to the beginning/end of the text.
54845484

54855485
The widget also supports integration with the system clipboard:
54865486

library/lua/gui/widgets.lua

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -988,20 +988,14 @@ function EditField:onInput(keys)
988988
end
989989
end
990990
return not not self.key
991-
elseif keys.CUSTOM_DELETE then
992-
local old = self.text
993-
local del_pos = self.cursor
994-
if del_pos <= #old then
995-
self:setText(old:sub(1, del_pos-1) .. old:sub(del_pos+1), del_pos)
996-
end
997-
return true
998991
elseif keys._STRING then
999992
local old = self.text
1000993
if keys._STRING == 0 then
1001994
-- handle backspace
1002995
local del_pos = self.cursor - 1
1003996
if del_pos > 0 then
1004-
self:setText(old:sub(1, del_pos-1) .. old:sub(del_pos+1), del_pos)
997+
self:setText(old:sub(1, del_pos-1) .. old:sub(del_pos+1),
998+
del_pos)
1005999
end
10061000
else
10071001
local cv = string.char(keys._STRING)
@@ -1015,22 +1009,23 @@ function EditField:onInput(keys)
10151009
elseif keys.KEYBOARD_CURSOR_LEFT then
10161010
self:setCursor(self.cursor - 1)
10171011
return true
1018-
elseif keys.CUSTOM_CTRL_LEFT then -- back one word
1012+
elseif keys.CUSTOM_CTRL_B then -- back one word
10191013
local _, prev_word_end = self.text:sub(1, self.cursor-1):
10201014
find('.*[%w_%-][^%w_%-]')
10211015
self:setCursor(prev_word_end or 1)
10221016
return true
1023-
elseif keys.CUSTOM_HOME then
1024-
self:setCursor(1)
1025-
return true
1017+
-- commented out until we get HOME key support from DF
1018+
-- elseif keys.CUSTOM_CTRL_A then -- home
1019+
-- self:setCursor(1)
1020+
-- return true
10261021
elseif keys.KEYBOARD_CURSOR_RIGHT then
10271022
self:setCursor(self.cursor + 1)
10281023
return true
1029-
elseif keys.CUSTOM_CTRL_RIGHT then -- forward one word
1024+
elseif keys.CUSTOM_CTRL_F then -- forward one word
10301025
local _,next_word_start = self.text:find('[^%w_%-][%w_%-]', self.cursor)
10311026
self:setCursor(next_word_start)
10321027
return true
1033-
elseif keys.CUSTOM_END then
1028+
elseif keys.CUSTOM_CTRL_E then -- end
10341029
self:setCursor()
10351030
return true
10361031
elseif keys.CUSTOM_CTRL_C then

test/library/gui/widgets.EditField.lua

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ function test.editfield_cursor()
2626
expect.eq(4, e.cursor)
2727
e:onInput{KEYBOARD_CURSOR_RIGHT=true}
2828
expect.eq(5, e.cursor)
29-
e:onInput{CUSTOM_HOME=true}
30-
expect.eq(1, e.cursor, 'cursor should be at beginning of string')
31-
e:onInput{CUSTOM_CTRL_RIGHT=true}
32-
expect.eq(6, e.cursor, 'goto beginning of next word')
33-
e:onInput{CUSTOM_END=true}
34-
expect.eq(16, e.cursor, 'cursor should be at end of string')
35-
e:onInput{CUSTOM_CTRL_LEFT=true}
36-
expect.eq(9, e.cursor, 'goto end of previous word')
29+
-- e:onInput{A_CARE_MOVE_W=true}
30+
-- expect.eq(1, e.cursor, 'interpret alt-left as home') -- uncomment when we have a home key
31+
e:onInput{CUSTOM_CTRL_F=true}
32+
expect.eq(6, e.cursor, 'interpret Ctrl-f as goto beginning of next word')
33+
e:onInput{CUSTOM_CTRL_E=true}
34+
expect.eq(16, e.cursor, 'interpret Ctrl-e as end')
35+
e:onInput{CUSTOM_CTRL_B=true}
36+
expect.eq(9, e.cursor, 'interpret Ctrl-b as goto end of previous word')
3737
end
3838

3939
function test.editfield_click()

0 commit comments

Comments
 (0)