Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gui/journal] migrate TextEditor to use new text navigation keys #1306

Merged
merged 4 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 52 additions & 31 deletions docs/gui/journal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,68 @@ gui/journal
The `gui/journal` interface makes it easy to take notes and document
important details for the fortresses.

With this multi-line text editor,
you can keep track of your fortress's background story, goals, notable events,
and both short-term and long-term plans.
With this multi-line text editor, you can keep track of your fortress's
background story, goals, notable events, and both short- and long-term plans.

This is particularly useful when you need to take a longer break from the game.
Having detailed notes makes it much easier to resume your game after
a few weeks or months, without losing track of your progress and objectives.
Having detailed notes makes it much easier to resume your game after a few
weeks or months without losing track of your progress and objectives.

Supported Features
------------------

- Cursor Control: Navigate through text using arrow keys (left, right, up, down) for precise cursor placement.
- Fast Rewind: Use :kbd:`Ctrl` + :kbd:`Left` / :kbd:`Ctrl` + :kbd:`B` and :kbd:`Ctrl` + :kbd:`Right` / :kbd:`Ctrl` + :kbd:`F` to move the cursor one word back or forward.
- Longest X Position Memory: The cursor remembers the longest x position when moving up or down, making vertical navigation more intuitive.
- Mouse Control: Use the mouse to position the cursor within the text, providing an alternative to keyboard navigation.
- 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 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.
- Text Selection: Select text with the mouse, with support for replacing or removing selected text.
- Jump to Beginning/End: Quickly move the cursor to the beginning or end of the text using :kbd:`Shift` + :kbd:`Up` and :kbd:`Shift` + :kbd:`Down`.
- Select Word/Line: Use double click to select current word, or triple click to select current line
- Cursor Control: Navigate through text using arrow keys (Left, Right, Up,
and Down) for precise cursor placement.
- Fast Rewind: Use :kbd:`Ctrl` + :kbd:`Left` and :kbd:`Ctrl` + :kbd:`Right` to
move the cursor one word back or forward.
- Longest X Position Memory: The cursor remembers the longest x position when
moving up or down, making vertical navigation more intuitive.
- Mouse Control: Use the mouse to position the cursor within the text,
providing an alternative to keyboard navigation.
- 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:`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.
- Text Selection: Select text with the mouse, with support for replacing or
removing selected text.
- Jump to Beginning/End: Quickly move the cursor to the beginning or end of the
text using :kbd:`Ctrl` + :kbd:`Home` and :kbd:`Ctrl` + :kbd:`End`.
- Select Word/Line: Use double click to select current word, or triple click to
select current line
- Select All: Select entire text by :kbd:`Ctrl` + :kbd:`A`
- Undo/Redo: Undo/Redo changes by :kbd:`Ctrl` + :kbd:`Z` / :kbd:`Ctrl` + :kbd:`Y`
- Clipboard Operations: Perform OS clipboard cut, copy, and paste operations on selected text, allowing you to paste the copied content into other applications.
- Undo/Redo: Undo/Redo changes by :kbd:`Ctrl` + :kbd:`Z` / :kbd:`Ctrl` +
:kbd:`Y`
- Clipboard Operations: Perform OS clipboard cut, copy, and paste operations on
selected text, allowing you to paste the copied content into other
applications.
- Copy Text: Use :kbd:`Ctrl` + :kbd:`C` to copy selected text.
- copy selected text, if available
- If no text is selected it copy the entire current line, including the terminating newline if present.
- copy selected text, if available
- If no text is selected it copy the entire current line, including the
terminating newline if present.
- Cut Text: Use :kbd:`Ctrl` + :kbd:`X` to cut selected text.
- cut selected text, if available
- If no text is selected it will cut the entire current line, including the terminating newline if present
- Paste Text: Use :kbd:`Ctrl` + :kbd:`V` to paste text from the clipboard into the editor.
- replace selected text, if available
- If no text is selected, paste text in the cursor position
- cut selected text, if available
- If no text is selected it will cut the entire current line, including the
terminating newline if present
- Paste Text: Use :kbd:`Ctrl` + :kbd:`V` to paste text from the clipboard into
the editor.
- replace selected text, if available
- If no text is selected, paste text in the cursor position
- Scrolling behaviour for long text build-in
- Table of contents (:kbd:`Ctrl` + :kbd:`O`), with headers line prefixed by '#', e.g. '# Fort history', '## Year 1'
- Table of contents navigation: jump to previous/next section by :kbd:`Ctrl` + :kbd:`Up` / :kbd:`Ctrl` + :kbd:`Down`
- Table of contents (:kbd:`Ctrl` + :kbd:`O`), with headers line prefixed by
``#``, e.g. ``# Fort history``, ``## Year 1``
- Table of contents navigation: jump to previous/next section by :kbd:`Ctrl` +
:kbd:`Up` / :kbd:`Ctrl` + :kbd:`Down`

Usage
-----
Expand Down
15 changes: 7 additions & 8 deletions internal/journal/text_editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -761,30 +761,30 @@ function TextEditorView:onCursorInput(keys)
self:setCursor(offset)
self.last_cursor_x = last_cursor_x
return true
elseif keys.KEYBOARD_CURSOR_UP_FAST then
elseif keys.CUSTOM_CTRL_HOME then
self:setCursor(1)
return true
elseif keys.KEYBOARD_CURSOR_DOWN_FAST then
elseif keys.CUSTOM_CTRL_END then
-- go to text end
self:setCursor(#self.text + 1)
return true
elseif keys.CUSTOM_CTRL_B or keys.A_MOVE_W_DOWN then
elseif keys.CUSTOM_CTRL_LEFT then
-- back one word
local word_start = self:wordStartOffset()
self:setCursor(word_start)
return true
elseif keys.CUSTOM_CTRL_F or keys.A_MOVE_E_DOWN then
elseif keys.CUSTOM_CTRL_RIGHT then
-- forward one word
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 @@ -878,8 +878,7 @@ function TextEditorView:onTextManipulationInput(keys)
self:eraseSelection()

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

if (self:hasSelection()) then
Expand Down
Loading
Loading