From e042c02d670ee8c93b2bd9de37d0368c70ad0208 Mon Sep 17 00:00:00 2001 From: Myk Date: Sat, 14 Sep 2024 14:10:41 -0700 Subject: [PATCH 1/3] Revert "Revert "[widgets.EditField] use new text navigation keys"" --- docs/changelog.txt | 3 +++ docs/dev/Lua API.rst | 6 +++--- library/lua/gui/widgets.lua | 23 ++++++++++++++--------- test/library/gui/widgets.EditField.lua | 16 ++++++++-------- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index e722cb04d1..f91fceac21 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -78,6 +78,9 @@ Template for new versions: - `buildingplan`: only consider building materials that can be accessed by at least one citizen/resident - Dreamfort: integrate with `preserve-rooms` to assign relevant rooms to nobles/adimistrators - Dreamfort: smooth tiles under statues and other large furniture that you can't easily smooth later +- DFHack text edit fields now delete the character at the cursor when you hit the Delete key +- DFHack text edit fields now move the cursor by one word left or right with Ctrl-Left and Ctrl-Right +- DFHack text edit fields now move the cursor to the beginning or end of the line with Home and End ## Documentation - add documentation for ``dfhack.items.findType(string)`` and ``dfhack.items.findSubtype(string)`` diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index 3b288ddc10..a6d1c1aec4 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -5478,9 +5478,9 @@ The ``EditField`` cursor can be moved to where you want to insert/remove text. You can click where you want the cursor to move or you can use any of the following keyboard hotkeys: -- Left/Right arrow: move the cursor one character to the left or right. -- Ctrl-B/Ctrl-F: move the cursor one word back or forward. -- Ctrl-A/Ctrl-E: move the cursor to the beginning/end of the text. +- Left/Right arrow: move the cursor one character to the left or right +- Ctrl-Left/Ctrl-Right: move the cursor one word back or forward +- Home/End: move the cursor to the beginning/end of the text The widget also supports integration with the system clipboard: diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index 1be57faa8b..a1ae69899e 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -988,14 +988,20 @@ function EditField:onInput(keys) end end return not not self.key + elseif keys.CUSTOM_DELETE then + local old = self.text + local del_pos = self.cursor + if del_pos <= #old then + self:setText(old:sub(1, del_pos-1) .. old:sub(del_pos+1), del_pos) + end + return true elseif keys._STRING then local old = self.text if keys._STRING == 0 then -- handle backspace local del_pos = self.cursor - 1 if del_pos > 0 then - self:setText(old:sub(1, del_pos-1) .. old:sub(del_pos+1), - del_pos) + self:setText(old:sub(1, del_pos-1) .. old:sub(del_pos+1), del_pos) end else local cv = string.char(keys._STRING) @@ -1009,23 +1015,22 @@ function EditField:onInput(keys) elseif keys.KEYBOARD_CURSOR_LEFT then self:setCursor(self.cursor - 1) return true - elseif keys.CUSTOM_CTRL_B then -- back one word + elseif keys.CUSTOM_CTRL_LEFT then -- back one word local _, prev_word_end = self.text:sub(1, self.cursor-1): find('.*[%w_%-][^%w_%-]') self:setCursor(prev_word_end or 1) return true - -- commented out until we get HOME key support from DF - -- elseif keys.CUSTOM_CTRL_A then -- home - -- self:setCursor(1) - -- return true + elseif keys.CUSTOM_HOME then + self:setCursor(1) + return true elseif keys.KEYBOARD_CURSOR_RIGHT then self:setCursor(self.cursor + 1) return true - elseif keys.CUSTOM_CTRL_F then -- forward one word + elseif keys.CUSTOM_CTRL_RIGHT then -- forward one word local _,next_word_start = self.text:find('[^%w_%-][%w_%-]', self.cursor) self:setCursor(next_word_start) return true - elseif keys.CUSTOM_CTRL_E then -- end + elseif keys.CUSTOM_END then self:setCursor() return true elseif keys.CUSTOM_CTRL_C then diff --git a/test/library/gui/widgets.EditField.lua b/test/library/gui/widgets.EditField.lua index 8418b67d46..755c3c54de 100644 --- a/test/library/gui/widgets.EditField.lua +++ b/test/library/gui/widgets.EditField.lua @@ -26,14 +26,14 @@ function test.editfield_cursor() expect.eq(4, e.cursor) e:onInput{KEYBOARD_CURSOR_RIGHT=true} expect.eq(5, e.cursor) - -- e:onInput{A_CARE_MOVE_W=true} - -- expect.eq(1, e.cursor, 'interpret alt-left as home') -- uncomment when we have a home key - e:onInput{CUSTOM_CTRL_F=true} - expect.eq(6, e.cursor, 'interpret Ctrl-f as goto beginning of next word') - e:onInput{CUSTOM_CTRL_E=true} - expect.eq(16, e.cursor, 'interpret Ctrl-e as end') - e:onInput{CUSTOM_CTRL_B=true} - expect.eq(9, e.cursor, 'interpret Ctrl-b as goto end of previous word') + e:onInput{CUSTOM_HOME=true} + expect.eq(1, e.cursor, 'cursor should be at beginning of string') + e:onInput{CUSTOM_CTRL_RIGHT=true} + expect.eq(6, e.cursor, 'goto beginning of next word') + e:onInput{CUSTOM_END=true} + expect.eq(16, e.cursor, 'cursor should be at end of string') + e:onInput{CUSTOM_CTRL_LEFT=true} + expect.eq(9, e.cursor, 'goto end of previous word') end function test.editfield_click() From fbd1ee09f72ca1dedd7bb983f23e6721d38ae120 Mon Sep 17 00:00:00 2001 From: Myk Date: Fri, 27 Sep 2024 04:45:51 -0700 Subject: [PATCH 2/3] Update changelog.txt --- docs/changelog.txt | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 4c7132c47d..f3c68bb4a9 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -58,6 +58,9 @@ Template for new versions: ## Fixes ## Misc Improvements +- DFHack text edit fields now delete the character at the cursor when you hit the Delete key +- DFHack text edit fields now move the cursor by one word left or right with Ctrl-Left and Ctrl-Right +- DFHack text edit fields now move the cursor to the beginning or end of the line with Home and End ## Documentation @@ -69,24 +72,10 @@ Template for new versions: # 50.14-r1 -## New Tools - -## New Features - ## Fixes - `preserve-rooms`: don't reserve a room for citizens that you expel from the fort - `autobutcher`: fix regression in ordering of butcherable animals -## Misc Improvements - -## Documentation - -## API - -## Lua - -## Removed - # 50.13-r5 ## New Tools @@ -114,9 +103,6 @@ Template for new versions: - `buildingplan`: only consider building materials that can be accessed by at least one citizen/resident - Dreamfort: integrate with `preserve-rooms` to assign relevant rooms to nobles/adimistrators - Dreamfort: smooth tiles under statues and other large furniture that you can't easily smooth later -- DFHack text edit fields now delete the character at the cursor when you hit the Delete key -- DFHack text edit fields now move the cursor by one word left or right with Ctrl-Left and Ctrl-Right -- DFHack text edit fields now move the cursor to the beginning or end of the line with Home and End ## Documentation - add documentation for ``dfhack.items.findType(string)`` and ``dfhack.items.findSubtype(string)`` From 7df9089f4d4015d469e3b81324b4f0d98d8836b6 Mon Sep 17 00:00:00 2001 From: DFHack-Urist via GitHub Actions <63161697+DFHack-Urist@users.noreply.github.com> Date: Fri, 27 Sep 2024 12:05:17 +0000 Subject: [PATCH 3/3] Auto-update submodules scripts: master --- scripts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts b/scripts index f15dd350e7..7b8adddf4b 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit f15dd350e71440d7347f6fefd810bc5093b89d61 +Subproject commit 7b8adddf4b0380ef4503c2f4d810307acb1c5f59