about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-01-31 22:47:48 -0800
committerKartik K. Agaram <vc@akkartik.com>2023-01-31 22:48:44 -0800
commit60f3ded88d776c3cb7b9ec3ce1d66b3cfd594dcd (patch)
tree569059b0088937f6d563843a30f0492927e76da5
parent7502b1eccce172f735681134d0bd828ad231876d (diff)
parent33ad6b7e5b5436d9b3e2ddd7119052bf3af5f02f (diff)
downloadview.love-60f3ded88d776c3cb7b9ec3ce1d66b3cfd594dcd.tar.gz
Merge lines.love
-rw-r--r--source_text.lua4
-rw-r--r--source_text_tests.lua50
-rw-r--r--text.lua2
3 files changed, 53 insertions, 3 deletions
diff --git a/source_text.lua b/source_text.lua
index 71f4f7b..7c00191 100644
--- a/source_text.lua
+++ b/source_text.lua
@@ -680,7 +680,7 @@ function Text.upA(State)
       new_cursor_line = new_cursor_line-1
       if State.lines[new_cursor_line].mode == 'text' then
 --?         print('found previous text line')
-        State.cursor1 = {line=State.cursor1.line-1, pos=nil}
+        State.cursor1 = {line=new_cursor_line, pos=nil}
         Text.populate_screen_line_starting_pos(State, State.cursor1.line)
         -- previous text line found, pick its final screen line
 --?         print('has multiple screen lines')
@@ -719,7 +719,7 @@ function Text.upB(State)
     while new_cursor_line > 1 do
       new_cursor_line = new_cursor_line-1
       if State.lines[new_cursor_line].mode == 'text' then
-        State.cursor1 = {line=State.cursor1.line-1, posB=nil}
+        State.cursor1 = {line=new_cursor_line, posB=nil}
         Text.populate_screen_line_starting_pos(State, State.cursor1.line)
         local prev_line_cache = State.line_cache[State.cursor1.line]
         local prev_screen_line_starting_pos = prev_line_cache.screen_line_starting_pos[#prev_line_cache.screen_line_starting_pos]
diff --git a/source_text_tests.lua b/source_text_tests.lua
index b2fdcda..2385325 100644
--- a/source_text_tests.lua
+++ b/source_text_tests.lua
@@ -1025,6 +1025,31 @@ function test_down_arrow_moves_cursor()
   App.screen.check(y, 'ghi', 'screen:3')
 end
 
+function test_down_arrow_skips_drawing()
+  -- some lines of text with a drawing intermixed
+  local drawing_width = 50
+  App.screen.init{width=Editor_state.left+drawing_width, height=100}
+  Editor_state = edit.initialize_test_state()
+  Editor_state.lines = load_array{'abc',               -- height 15
+                                  '```lines', '```',   -- height 25
+                                  'ghi'}
+  Text.redraw_all(Editor_state)
+  Editor_state.cursor1 = {line=1, pos=1}
+  Editor_state.screen_top1 = {line=1, pos=1}
+  Editor_state.screen_bottom1 = {}
+  edit.draw(Editor_state)
+  local y = Editor_state.top
+  App.screen.check(y, 'abc', 'baseline/screen:1')
+  y = y + Editor_state.line_height
+  local drawing_height = Drawing_padding_height + drawing_width/2  -- default
+  y = y + drawing_height
+  App.screen.check(y, 'ghi', 'baseline/screen:3')
+  check(Editor_state.cursor_x, 'baseline/cursor_x')
+  -- after hitting the down arrow the cursor moves down by 2 lines, skipping the drawing
+  edit.run_after_keychord(Editor_state, 'down')
+  check_eq(Editor_state.cursor1.line, 3, 'cursor')
+end
+
 function test_down_arrow_scrolls_down_by_one_line()
   -- display the first three lines with the cursor on the bottom line
   App.screen.init{width=120, height=60}
@@ -1173,6 +1198,31 @@ function test_up_arrow_moves_cursor()
   App.screen.check(y, 'ghi', 'screen:3')
 end
 
+function test_up_arrow_skips_drawing()
+  -- some lines of text with a drawing intermixed
+  local drawing_width = 50
+  App.screen.init{width=Editor_state.left+drawing_width, height=100}
+  Editor_state = edit.initialize_test_state()
+  Editor_state.lines = load_array{'abc',               -- height 15
+                                  '```lines', '```',   -- height 25
+                                  'ghi'}
+  Text.redraw_all(Editor_state)
+  Editor_state.cursor1 = {line=3, pos=1}
+  Editor_state.screen_top1 = {line=1, pos=1}
+  Editor_state.screen_bottom1 = {}
+  edit.draw(Editor_state)
+  local y = Editor_state.top
+  App.screen.check(y, 'abc', 'baseline/screen:1')
+  y = y + Editor_state.line_height
+  local drawing_height = Drawing_padding_height + drawing_width/2  -- default
+  y = y + drawing_height
+  App.screen.check(y, 'ghi', 'baseline/screen:3')
+  check(Editor_state.cursor_x, 'baseline/cursor_x')
+  -- after hitting the up arrow the cursor moves up by 2 lines, skipping the drawing
+  edit.run_after_keychord(Editor_state, 'up')
+  check_eq(Editor_state.cursor1.line, 1, 'cursor')
+end
+
 function test_up_arrow_scrolls_up_by_one_line()
   -- display the lines 2/3/4 with the cursor on line 2
   App.screen.init{width=120, height=60}
diff --git a/text.lua b/text.lua
index 961faba..0e69057 100644
--- a/text.lua
+++ b/text.lua
@@ -410,7 +410,7 @@ function Text.up(State)
     if State.cursor1.line > 1 then
       local new_cursor_line = State.cursor1.line-1
 --?       print('found previous text line')
-      State.cursor1.line = new_cursor_line
+      State.cursor1 = {line=new_cursor_line, pos=nil}
       Text.populate_screen_line_starting_pos(State, State.cursor1.line)
       -- previous text line found, pick its final screen line
 --?       print('has multiple screen lines')