Skip to content

Commit

Permalink
Merge branch 'develop' into adv-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed Sep 27, 2024
2 parents 9f00c90 + 7df9089 commit 05c0e55
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 35 deletions.
17 changes: 3 additions & 14 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions docs/dev/Lua API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
23 changes: 14 additions & 9 deletions library/lua/gui/widgets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts
16 changes: 8 additions & 8 deletions test/library/gui/widgets.EditField.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 05c0e55

Please sign in to comment.