diff --git a/docs/changelog.txt b/docs/changelog.txt index e6baf71475..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 diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index 232daea9eb..4967c58f0e 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -5479,9 +5479,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/scripts b/scripts index f15dd350e7..7b8adddf4b 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit f15dd350e71440d7347f6fefd810bc5093b89d61 +Subproject commit 7b8adddf4b0380ef4503c2f4d810307acb1c5f59 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()