Skip to content

Commit 0dec633

Browse files
committed
migrate TextEditor to use new text navigation keys
1 parent a963f12 commit 0dec633

File tree

3 files changed

+53
-49
lines changed

3 files changed

+53
-49
lines changed

docs/gui/journal.rst

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,28 @@ gui/journal
88
The `gui/journal` interface makes it easy to take notes and document
99
important details for the fortresses.
1010

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

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

1918
Supported Features
2019
------------------
2120

22-
- Cursor Control: Navigate through text using arrow keys (left, right, up, down) for precise cursor placement.
23-
- 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.
24-
- Longest X Position Memory: The cursor remembers the longest x position when moving up or down, making vertical navigation more intuitive.
25-
- Mouse Control: Use the mouse to position the cursor within the text, providing an alternative to keyboard navigation.
26-
- New Lines: Easily insert new lines using the :kbd:`Enter` key, supporting multiline text input.
27-
- Text Wrapping: Text automatically wraps within the editor, ensuring lines fit within the display without manual adjustments.
21+
- Cursor Control: Navigate through text using arrow keys (Left, Right, Up,
22+
and Down) for precise cursor placement.
23+
- Fast Rewind: Use :kbd:`Ctrl` + :kbd:`Left` and :kbd:`Ctrl` + :kbd:`Right` to
24+
move the cursor one word back or forward.
25+
- Longest X Position Memory: The cursor remembers the longest x position when
26+
moving up or down, making vertical navigation more intuitive.
27+
- Mouse Control: Use the mouse to position the cursor within the text,
28+
providing an alternative to keyboard navigation.
29+
- New Lines: Easily insert new lines using the :kbd:`Enter` key, supporting
30+
multiline text input.
31+
- Text Wrapping: Text automatically wraps within the editor, ensuring lines fit
32+
within the display without manual adjustments.
2833
- Backspace Support: Use the backspace key to delete characters to the left of the cursor.
2934
- Delete Character: :kbd:`Ctrl` + :kbd:`D` deletes the character under the cursor.
3035
- 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.

internal/journal/text_editor.lua

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -768,23 +768,23 @@ function TextEditorView:onCursorInput(keys)
768768
-- go to text end
769769
self:setCursor(#self.text + 1)
770770
return true
771-
elseif keys.CUSTOM_CTRL_B or keys.A_MOVE_W_DOWN then
771+
elseif keys.CUSTOM_CTRL_LEFT then
772772
-- back one word
773773
local word_start = self:wordStartOffset()
774774
self:setCursor(word_start)
775775
return true
776-
elseif keys.CUSTOM_CTRL_F or keys.A_MOVE_E_DOWN then
776+
elseif keys.CUSTOM_CTRL_RIGHT then
777777
-- forward one word
778778
local word_end = self:wordEndOffset()
779779
self:setCursor(word_end)
780780
return true
781-
elseif keys.CUSTOM_CTRL_H then
781+
elseif keys.CUSTOM_HOME then
782782
-- line start
783783
self:setCursor(
784784
self:lineStartOffset()
785785
)
786786
return true
787-
elseif keys.CUSTOM_CTRL_E then
787+
elseif keys.CUSTOM_END then
788788
-- line end
789789
self:setCursor(
790790
self:lineEndOffset()
@@ -878,8 +878,7 @@ function TextEditorView:onTextManipulationInput(keys)
878878
self:eraseSelection()
879879

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

885884
if (self:hasSelection()) then

test/gui/journal.lua

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ function test.handle_delete()
772772
text_area:setCursor(1)
773773
journal:onRender()
774774

775-
simulate_input_keys('CUSTOM_CTRL_D')
775+
simulate_input_keys('CUSTOM_DELETE')
776776

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

784784
text_area:setCursor(124)
785785
journal:onRender()
786-
simulate_input_keys('CUSTOM_CTRL_D')
786+
simulate_input_keys('CUSTOM_DELETE')
787787

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

795795
text_area:setCursor(123)
796796
journal:onRender()
797-
simulate_input_keys('CUSTOM_CTRL_D')
797+
simulate_input_keys('CUSTOM_DELETE')
798798

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

806806
text_area:setCursor(171)
807807
journal:onRender()
808-
simulate_input_keys('CUSTOM_CTRL_D')
808+
simulate_input_keys('CUSTOM_DELETE')
809809

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

817817
for i=1,59 do
818-
simulate_input_keys('CUSTOM_CTRL_D')
818+
simulate_input_keys('CUSTOM_DELETE')
819819
end
820820

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

827-
simulate_input_keys('CUSTOM_CTRL_D')
827+
simulate_input_keys('CUSTOM_DELETE')
828828

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

852-
simulate_input_keys('CUSTOM_CTRL_E')
852+
simulate_input_keys('CUSTOM_END')
853853

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

864-
simulate_input_keys('CUSTOM_CTRL_E')
864+
simulate_input_keys('CUSTOM_END')
865865

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

876-
simulate_input_keys('CUSTOM_CTRL_E')
876+
simulate_input_keys('CUSTOM_END')
877877

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

885-
simulate_input_keys('CUSTOM_CTRL_E')
885+
simulate_input_keys('CUSTOM_END')
886886

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

906906
simulate_input_text(text)
907907

908-
simulate_input_keys('CUSTOM_CTRL_H')
908+
simulate_input_keys('CUSTOM_HOME')
909909

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

920-
simulate_input_keys('CUSTOM_CTRL_H')
920+
simulate_input_keys('CUSTOM_HOME')
921921

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

932-
simulate_input_keys('CUSTOM_CTRL_H')
932+
simulate_input_keys('CUSTOM_HOME')
933933

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

1358-
simulate_input_keys('CUSTOM_CTRL_H')
1358+
simulate_input_keys('CUSTOM_HOME')
13591359
expect.eq(read_selected_text(text_area), '')
13601360

1361-
simulate_input_keys('CUSTOM_CTRL_E')
1361+
simulate_input_keys('CUSTOM_END')
13621362
expect.eq(read_selected_text(text_area), '')
13631363

13641364
journal:dismiss()
@@ -1496,7 +1496,7 @@ function test.delete_char_delete_selection()
14961496
'porttitor mi, vitae rutrum ero',
14971497
}, '\n'));
14981498

1499-
simulate_input_keys('CUSTOM_CTRL_D')
1499+
simulate_input_keys('CUSTOM_DELETE')
15001500

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

22382238
simulate_input_keys('CUSTOM_CTRL_A')
2239-
simulate_input_keys('CUSTOM_CTRL_D')
2239+
simulate_input_keys('CUSTOM_DELETE')
22402240

22412241
local text = table.concat({
22422242
'60: Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
@@ -2861,7 +2861,7 @@ function test.fast_rewind_words_right()
28612861
text_area:setCursor(1)
28622862
journal:onRender()
28632863

2864-
simulate_input_keys('A_MOVE_E_DOWN')
2864+
simulate_input_keys('CUSTOM_CTRL_RIGHT')
28652865

28662866
expect.eq(read_rendered_text(text_area), table.concat({
28672867
'60:_Lorem ipsum dolor sit amet, consectetur adipiscing ',
@@ -2871,7 +2871,7 @@ function test.fast_rewind_words_right()
28712871
'libero.',
28722872
}, '\n'));
28732873

2874-
simulate_input_keys('A_MOVE_E_DOWN')
2874+
simulate_input_keys('CUSTOM_CTRL_RIGHT')
28752875

28762876
expect.eq(read_rendered_text(text_area), table.concat({
28772877
'60: Lorem_ipsum dolor sit amet, consectetur adipiscing ',
@@ -2882,7 +2882,7 @@ function test.fast_rewind_words_right()
28822882
}, '\n'));
28832883

28842884
for i=1,6 do
2885-
simulate_input_keys('A_MOVE_E_DOWN')
2885+
simulate_input_keys('CUSTOM_CTRL_RIGHT')
28862886
end
28872887

28882888
expect.eq(read_rendered_text(text_area), table.concat({
@@ -2893,7 +2893,7 @@ function test.fast_rewind_words_right()
28932893
'libero.',
28942894
}, '\n'));
28952895

2896-
simulate_input_keys('A_MOVE_E_DOWN')
2896+
simulate_input_keys('CUSTOM_CTRL_RIGHT')
28972897

28982898
expect.eq(read_rendered_text(text_area), table.concat({
28992899
'60: Lorem ipsum dolor sit amet, consectetur adipiscing ',
@@ -2903,7 +2903,7 @@ function test.fast_rewind_words_right()
29032903
'libero.',
29042904
}, '\n'));
29052905

2906-
simulate_input_keys('A_MOVE_E_DOWN')
2906+
simulate_input_keys('CUSTOM_CTRL_RIGHT')
29072907

29082908
expect.eq(read_rendered_text(text_area), table.concat({
29092909
'60: Lorem ipsum dolor sit amet, consectetur adipiscing ',
@@ -2914,7 +2914,7 @@ function test.fast_rewind_words_right()
29142914
}, '\n'));
29152915

29162916
for i=1,17 do
2917-
simulate_input_keys('A_MOVE_E_DOWN')
2917+
simulate_input_keys('CUSTOM_CTRL_RIGHT')
29182918
end
29192919

29202920
expect.eq(read_rendered_text(text_area), table.concat({
@@ -2925,7 +2925,7 @@ function test.fast_rewind_words_right()
29252925
'libero._',
29262926
}, '\n'));
29272927

2928-
simulate_input_keys('A_MOVE_E_DOWN')
2928+
simulate_input_keys('CUSTOM_CTRL_RIGHT')
29292929

29302930
expect.eq(read_rendered_text(text_area), table.concat({
29312931
'60: Lorem ipsum dolor sit amet, consectetur adipiscing ',
@@ -2948,7 +2948,7 @@ function test.fast_rewind_words_left()
29482948

29492949
simulate_input_text(text)
29502950

2951-
simulate_input_keys('A_MOVE_W_DOWN')
2951+
simulate_input_keys('CUSTOM_CTRL_LEFT')
29522952

29532953
expect.eq(read_rendered_text(text_area), table.concat({
29542954
'60: Lorem ipsum dolor sit amet, consectetur adipiscing ',
@@ -2958,7 +2958,7 @@ function test.fast_rewind_words_left()
29582958
'_ibero.',
29592959
}, '\n'));
29602960

2961-
simulate_input_keys('A_MOVE_W_DOWN')
2961+
simulate_input_keys('CUSTOM_CTRL_LEFT')
29622962

29632963
expect.eq(read_rendered_text(text_area), table.concat({
29642964
'60: Lorem ipsum dolor sit amet, consectetur adipiscing ',
@@ -2969,7 +2969,7 @@ function test.fast_rewind_words_left()
29692969
}, '\n'));
29702970

29712971
for i=1,8 do
2972-
simulate_input_keys('A_MOVE_W_DOWN')
2972+
simulate_input_keys('CUSTOM_CTRL_LEFT')
29732973
end
29742974

29752975
expect.eq(read_rendered_text(text_area), table.concat({
@@ -2980,7 +2980,7 @@ function test.fast_rewind_words_left()
29802980
'libero.',
29812981
}, '\n'));
29822982

2983-
simulate_input_keys('A_MOVE_W_DOWN')
2983+
simulate_input_keys('CUSTOM_CTRL_LEFT')
29842984

29852985
expect.eq(read_rendered_text(text_area), table.concat({
29862986
'60: Lorem ipsum dolor sit amet, consectetur adipiscing ',
@@ -2991,7 +2991,7 @@ function test.fast_rewind_words_left()
29912991
}, '\n'));
29922992

29932993
for i=1,16 do
2994-
simulate_input_keys('A_MOVE_W_DOWN')
2994+
simulate_input_keys('CUSTOM_CTRL_LEFT')
29952995
end
29962996

29972997
expect.eq(read_rendered_text(text_area), table.concat({
@@ -3002,7 +3002,7 @@ function test.fast_rewind_words_left()
30023002
'libero.',
30033003
}, '\n'));
30043004

3005-
simulate_input_keys('A_MOVE_W_DOWN')
3005+
simulate_input_keys('CUSTOM_CTRL_LEFT')
30063006

30073007
expect.eq(read_rendered_text(text_area), table.concat({
30083008
'_0: Lorem ipsum dolor sit amet, consectetur adipiscing ',
@@ -3039,12 +3039,12 @@ function test.fast_rewind_reset_selection()
30393039
'porttitor mi, vitae rutrum eros metus nec libero.',
30403040
}, '\n'));
30413041

3042-
simulate_input_keys('A_MOVE_W_DOWN')
3042+
simulate_input_keys('CUSTOM_CTRL_LEFT')
30433043
expect.eq(read_selected_text(text_area), '')
30443044

30453045
simulate_input_keys('CUSTOM_CTRL_A')
30463046

3047-
simulate_input_keys('A_MOVE_E_DOWN')
3047+
simulate_input_keys('CUSTOM_CTRL_RIGHT')
30483048
expect.eq(read_selected_text(text_area), '')
30493049

30503050
journal:dismiss()

0 commit comments

Comments
 (0)