about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-08-10 22:56:10 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-08-10 22:56:10 -0700
commitda34fabf729e7cf51f4af2c499105350104bd525 (patch)
tree8fd9e86a4dcc2a27ee85e406cbcbfcc64fd3d813
parentba48aadaa71ac01db2a9d9bd06a26dec30fd31b3 (diff)
downloadview.love-da34fabf729e7cf51f4af2c499105350104bd525.tar.gz
bugfix: pagedown was sometimes bouncing up
-rw-r--r--text.lua2
-rw-r--r--text_tests.lua17
2 files changed, 18 insertions, 1 deletions
diff --git a/text.lua b/text.lua
index 4e6c072..e255cb7 100644
--- a/text.lua
+++ b/text.lua
@@ -17,7 +17,7 @@ function Text.draw(State, line_index, y, startpos)
   -- wrap long lines
   local x = State.left
   local pos = 1
-  local screen_line_starting_pos = 1
+  local screen_line_starting_pos = State.screen_top1.pos
   if line_cache.fragments == nil then
     Text.compute_fragments(State, line_index)
   end
diff --git a/text_tests.lua b/text_tests.lua
index 9983e2d..e5e7823 100644
--- a/text_tests.lua
+++ b/text_tests.lua
@@ -1084,6 +1084,23 @@ function test_pagedown_can_start_from_middle_of_long_wrapping_line()
   App.screen.check(y, 'mno ', 'F - test_pagedown_can_start_from_middle_of_long_wrapping_line/screen:3')
 end
 
+function test_pagedown_never_moves_up()
+  io.write('\ntest_pagedown_never_moves_up')
+  -- draw the final screen line of a wrapping line
+  App.screen.init{width=Editor_state.left+30, height=60}
+  Editor_state = edit.initialize_test_state()
+  Editor_state.lines = load_array{'abc def ghi'}
+  Text.redraw_all(Editor_state)
+  Editor_state.cursor1 = {line=1, pos=9}
+  Editor_state.screen_top1 = {line=1, pos=9}
+  Editor_state.screen_bottom1 = {}
+  edit.draw(Editor_state)
+  -- pagedown makes no change
+  edit.run_after_keychord(Editor_state, 'pagedown')
+  check_eq(Editor_state.screen_top1.line, 1, 'F - test_pagedown_never_moves_up/screen_top:line')
+  check_eq(Editor_state.screen_top1.pos, 9, 'F - test_pagedown_never_moves_up/screen_top:pos')
+end
+
 function test_down_arrow_moves_cursor()
   io.write('\ntest_down_arrow_moves_cursor')
   App.screen.init{width=120, height=60}
'n196' href='#n196'>196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247