Skip to content

Commit

Permalink
Improve gui/notes and gui/journal keyboard control
Browse files Browse the repository at this point in the history
  • Loading branch information
wiktor-obrebski committed Sep 19, 2024
1 parent 8ad4fa1 commit a37ebe1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 36 deletions.
4 changes: 2 additions & 2 deletions docs/gui/journal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Supported Features
- New Lines: Easily insert new lines using the :kbd:`Enter` key, supporting multiline text input.
- Text Wrapping: Text automatically wraps within the editor, ensuring lines fit within the display without manual adjustments.
- Backspace Support: Use the backspace key to delete characters to the left of the cursor.
- Delete Character: :kbd:`Ctrl` + :kbd:`D` deletes the character under the cursor.
- Line Navigation: :kbd:`Ctrl` + :kbd:`H` (like "Home") moves the cursor to the beginning of the current line, and :kbd:`Ctrl` + :kbd:`E` (like "End") moves it to the end.
- Delete Character: :kbd:`Delete` deletes the character under the cursor.
- Line Navigation: :kbd:`Home` moves the cursor to the beginning of the current line, and :kbd:`End` moves it to the end.
- Delete Current Line: :kbd:`Ctrl` + :kbd:`U` deletes the entire current line where the cursor is located.
- Delete Rest of Line: :kbd:`Ctrl` + :kbd:`K` deletes text from the cursor to the end of the line.
- Delete Last Word: :kbd:`Ctrl` + :kbd:`W` removes the word immediately before the cursor.
Expand Down
2 changes: 1 addition & 1 deletion docs/notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Creating a Note
1. Use the keyboard cursor to select the desired map tile where you want to place a note.
2. Execute ``notes add`` via the DFHack console.
3. In the pop-up dialog, fill in the note's title and detailed comment.
4. Press :kbd:`Alt` + :kbd:`S` to create the note.
4. Press :kbd:`Ctrl` + :kbd:`S` to create the note.

Editing or Deleting a Note
--------------------------
Expand Down
13 changes: 3 additions & 10 deletions gui/notes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ function NotesWindow:init()
frame_inset={l=1,t=1,b=1,r=1},
autoarrange_subviews=true,
subviews={
widgets.HotkeyLabel {
key='CUSTOM_ALT_S',
label='Search',
frame={l=0},
auto_width=true,
on_activate=function() self.subviews.search:setFocus(true) end,
},
NotesSearchField{
view_id='search',
frame={l=0,h=3},
Expand Down Expand Up @@ -94,7 +87,7 @@ function NotesWindow:init()
frame={l=1,b=1,h=1},
auto_width=true,
label='New note',
key='CUSTOM_ALT_N',
key='CUSTOM_CTRL_N',
visible=edit_mode,
on_activate=function()
if self.on_note_add then
Expand Down Expand Up @@ -151,15 +144,15 @@ function NotesWindow:init()
frame={l=0,t=0,h=1},
auto_width=true,
label='Edit',
key='CUSTOM_ALT_U',
key='CUSTOM_CTRL_E',
on_activate=function() self:showNoteManager(self.selected_note) end,
},
widgets.HotkeyLabel{
view_id='delete',
frame={r=0,t=0,h=1},
auto_width=true,
label='Delete',
key='CUSTOM_ALT_D',
key='CUSTOM_CTRL_D',
on_activate=function() self:deleteNote(self.selected_note) end,
},
}
Expand Down
6 changes: 3 additions & 3 deletions internal/journal/text_editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -786,13 +786,13 @@ function TextEditorView:onCursorInput(keys)
local word_end = self:wordEndOffset()
self:setCursor(word_end)
return true
elseif keys.CUSTOM_CTRL_H then
elseif keys.CUSTOM_HOME then
-- line start
self:setCursor(
self:lineStartOffset()
)
return true
elseif keys.CUSTOM_CTRL_E then
elseif keys.CUSTOM_END then
-- line end
self:setCursor(
self:lineEndOffset()
Expand Down Expand Up @@ -890,7 +890,7 @@ function TextEditorView:onTextManipulationInput(keys)
self:eraseSelection()

return true
elseif keys.CUSTOM_CTRL_D then
elseif keys.CUSTOM_DELETE then
-- delete char, there is no support for `Delete` key
self.history:store(HISTORY_ENTRY.DELETE, self.text, self.cursor)

Expand Down
6 changes: 3 additions & 3 deletions internal/notes/note_manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function NoteManager:init()
frame={l=0,t=0,h=1},
auto_width=true,
label='Save',
key='CUSTOM_ALT_S',
key='CUSTOM_CTRL_S',
visible=edit_mode,
on_activate=function() self:saveNote() end,
enabled=function() return #self.subviews.name:getText() > 0 end,
Expand All @@ -75,7 +75,7 @@ function NoteManager:init()
frame={l=0,t=0,h=1},
auto_width=true,
label='Create',
key='CUSTOM_ALT_S',
key='CUSTOM_CTRL_S',
visible=not edit_mode,
on_activate=function() self:createNote() end,
enabled=function() return #self.subviews.name:getText() > 0 end,
Expand All @@ -85,7 +85,7 @@ function NoteManager:init()
frame={r=0,t=0,h=1},
auto_width=true,
label='Delete',
key='CUSTOM_ALT_D',
key='CUSTOM_CTRL_D',
visible=edit_mode,
on_activate=function() self:deleteNote() end,
},
Expand Down
34 changes: 17 additions & 17 deletions test/gui/journal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ function test.handle_delete()
text_area:setCursor(1)
journal:onRender()

simulate_input_keys('CUSTOM_CTRL_D')
simulate_input_keys('CUSTOM_DELETE')

expect.eq(read_rendered_text(text_area), table.concat({
'_: Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
Expand All @@ -783,7 +783,7 @@ function test.handle_delete()

text_area:setCursor(124)
journal:onRender()
simulate_input_keys('CUSTOM_CTRL_D')
simulate_input_keys('CUSTOM_DELETE')

expect.eq(read_rendered_text(text_area), table.concat({
'0: Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
Expand All @@ -794,7 +794,7 @@ function test.handle_delete()

text_area:setCursor(123)
journal:onRender()
simulate_input_keys('CUSTOM_CTRL_D')
simulate_input_keys('CUSTOM_DELETE')

expect.eq(read_rendered_text(text_area), table.concat({
'0: Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
Expand All @@ -805,7 +805,7 @@ function test.handle_delete()

text_area:setCursor(171)
journal:onRender()
simulate_input_keys('CUSTOM_CTRL_D')
simulate_input_keys('CUSTOM_DELETE')

expect.eq(read_rendered_text(text_area), table.concat({
'0: Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
Expand All @@ -815,7 +815,7 @@ function test.handle_delete()
}, '\n'));

for i=1,59 do
simulate_input_keys('CUSTOM_CTRL_D')
simulate_input_keys('CUSTOM_DELETE')
end

expect.eq(read_rendered_text(text_area), table.concat({
Expand All @@ -824,7 +824,7 @@ function test.handle_delete()
'nibhorttitor mi, vitae rutrum eros metus nec libero._',
}, '\n'));

simulate_input_keys('CUSTOM_CTRL_D')
simulate_input_keys('CUSTOM_DELETE')

expect.eq(read_rendered_text(text_area), table.concat({
'0: Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
Expand All @@ -849,7 +849,7 @@ function test.line_end()
text_area:setCursor(1)
journal:onRender()

simulate_input_keys('CUSTOM_CTRL_E')
simulate_input_keys('CUSTOM_END')

expect.eq(read_rendered_text(text_area), table.concat({
'60: Lorem ipsum dolor sit amet, consectetur adipiscing elit._',
Expand All @@ -861,7 +861,7 @@ function test.line_end()
text_area:setCursor(70)
journal:onRender()

simulate_input_keys('CUSTOM_CTRL_E')
simulate_input_keys('CUSTOM_END')

expect.eq(read_rendered_text(text_area), table.concat({
'60: Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
Expand All @@ -873,7 +873,7 @@ function test.line_end()
text_area:setCursor(200)
journal:onRender()

simulate_input_keys('CUSTOM_CTRL_E')
simulate_input_keys('CUSTOM_END')

expect.eq(read_rendered_text(text_area), table.concat({
'60: Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
Expand All @@ -882,7 +882,7 @@ function test.line_end()
'60: Lorem ipsum dolor sit amet, consectetur adipiscing elit._',
}, '\n'));

simulate_input_keys('CUSTOM_CTRL_E')
simulate_input_keys('CUSTOM_END')

expect.eq(read_rendered_text(text_area), table.concat({
'60: Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
Expand All @@ -905,7 +905,7 @@ function test.line_beging()

simulate_input_text(text)

simulate_input_keys('CUSTOM_CTRL_H')
simulate_input_keys('CUSTOM_HOME')

expect.eq(read_rendered_text(text_area), table.concat({
'60: Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
Expand All @@ -917,7 +917,7 @@ function test.line_beging()
text_area:setCursor(173)
journal:onRender()

simulate_input_keys('CUSTOM_CTRL_H')
simulate_input_keys('CUSTOM_HOME')

expect.eq(read_rendered_text(text_area), table.concat({
'60: Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
Expand All @@ -929,7 +929,7 @@ function test.line_beging()
text_area:setCursor(1)
journal:onRender()

simulate_input_keys('CUSTOM_CTRL_H')
simulate_input_keys('CUSTOM_HOME')

expect.eq(read_rendered_text(text_area), table.concat({
'_0: Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
Expand Down Expand Up @@ -1355,10 +1355,10 @@ function test.line_navigation_reset_selection()
'porttitor mi, vitae rutrum eros metus nec libero.',
}, '\n'));

simulate_input_keys('CUSTOM_CTRL_H')
simulate_input_keys('CUSTOM_HOME')
expect.eq(read_selected_text(text_area), '')

simulate_input_keys('CUSTOM_CTRL_E')
simulate_input_keys('CUSTOM_END')
expect.eq(read_selected_text(text_area), '')

journal:dismiss()
Expand Down Expand Up @@ -1496,7 +1496,7 @@ function test.delete_char_delete_selection()
'porttitor mi, vitae rutrum ero',
}, '\n'));

simulate_input_keys('CUSTOM_CTRL_D')
simulate_input_keys('CUSTOM_DELETE')

expect.eq(read_rendered_text(text_area), table.concat({
'60: _ metus nec libero.',
Expand Down Expand Up @@ -2236,7 +2236,7 @@ function test.restore_text_between_sessions()
local journal, text_area = arrange_empty_journal({w=80,save_on_change=true})

simulate_input_keys('CUSTOM_CTRL_A')
simulate_input_keys('CUSTOM_CTRL_D')
simulate_input_keys('CUSTOM_DELETE')

local text = table.concat({
'60: Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
Expand Down

0 comments on commit a37ebe1

Please sign in to comment.