From a37ebe170c05e889429dc9dde7138b23184fc472 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiktor=20Obr=C4=99bski?= Date: Thu, 19 Sep 2024 19:01:57 +0200 Subject: [PATCH] Improve gui/notes and gui/journal keyboard control --- docs/gui/journal.rst | 4 ++-- docs/notes.rst | 2 +- gui/notes.lua | 13 +++--------- internal/journal/text_editor.lua | 6 +++--- internal/notes/note_manager.lua | 6 +++--- test/gui/journal.lua | 34 ++++++++++++++++---------------- 6 files changed, 29 insertions(+), 36 deletions(-) diff --git a/docs/gui/journal.rst b/docs/gui/journal.rst index d6004ec95..0063ff63a 100644 --- a/docs/gui/journal.rst +++ b/docs/gui/journal.rst @@ -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. diff --git a/docs/notes.rst b/docs/notes.rst index faed2c8fb..19e169428 100644 --- a/docs/notes.rst +++ b/docs/notes.rst @@ -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 -------------------------- diff --git a/gui/notes.lua b/gui/notes.lua index b0c263e12..7254d5b93 100644 --- a/gui/notes.lua +++ b/gui/notes.lua @@ -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}, @@ -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 @@ -151,7 +144,7 @@ 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{ @@ -159,7 +152,7 @@ function NotesWindow:init() 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, }, } diff --git a/internal/journal/text_editor.lua b/internal/journal/text_editor.lua index b5da3950b..abbca900e 100644 --- a/internal/journal/text_editor.lua +++ b/internal/journal/text_editor.lua @@ -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() @@ -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) diff --git a/internal/notes/note_manager.lua b/internal/notes/note_manager.lua index 5affb69b6..b7a8d8059 100644 --- a/internal/notes/note_manager.lua +++ b/internal/notes/note_manager.lua @@ -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, @@ -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, @@ -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, }, diff --git a/test/gui/journal.lua b/test/gui/journal.lua index d845aef20..d86e415d1 100644 --- a/test/gui/journal.lua +++ b/test/gui/journal.lua @@ -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.', @@ -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.', @@ -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.', @@ -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.', @@ -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({ @@ -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.', @@ -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._', @@ -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.', @@ -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.', @@ -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.', @@ -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.', @@ -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.', @@ -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.', @@ -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() @@ -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.', @@ -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.',