about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-06-26 16:34:06 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-06-26 16:34:06 -0700
commit44fb3ecd55a7b0cd45b604d5431811e0852a4714 (patch)
tree31bcf4d5c4d78638de820ac5d32515c1c4af33b8
parent22330664098826620ab783f2d6f68e3639660f9e (diff)
downloadview.love-44fb3ecd55a7b0cd45b604d5431811e0852a4714.tar.gz
bugfix: deleting a selection spanning pages
-rw-r--r--select.lua4
-rw-r--r--text_tests.lua25
2 files changed, 29 insertions, 0 deletions
diff --git a/select.lua b/select.lua
index 219fe3e..59f79d0 100644
--- a/select.lua
+++ b/select.lua
@@ -133,6 +133,10 @@ function Text.delete_selection_without_undo()
   -- update Cursor1 and Selection1
   Cursor1.line = minl
   Cursor1.pos = minp
+  if Text.lt1(Cursor1, Screen_top1) then
+    Screen_top1.line = Cursor1.line
+    _,Screen_top1.pos = Text.pos_at_start_of_cursor_screen_line()
+  end
   Selection1 = {}
   -- delete everything between min (inclusive) and max (exclusive)
   Text.clear_cache(Lines[minl])
diff --git a/text_tests.lua b/text_tests.lua
index 64de74c..3c4349a 100644
--- a/text_tests.lua
+++ b/text_tests.lua
@@ -317,6 +317,31 @@ function test_paste_replaces_selection()
   check_eq(Lines[1].data, 'xyzdef', 'F - test_paste_replaces_selection')
 end
 
+function test_deleting_selection_may_scroll()
+  io.write('\ntest_deleting_selection_may_scroll')
+  -- display lines 2/3/4
+  App.screen.init{width=120, height=60}
+  Lines = load_array{'abc', 'def', 'ghi', 'jkl'}
+  Line_width = App.screen.width
+  Cursor1 = {line=3, pos=2}
+  Screen_top1 = {line=2, pos=1}
+  Screen_bottom1 = {}
+  App.draw()
+  local y = Margin_top
+  App.screen.check(y, 'def', 'F - test_deleting_selection_may_scroll/baseline/screen:1')
+  y = y + Line_height
+  App.screen.check(y, 'ghi', 'F - test_deleting_selection_may_scroll/baseline/screen:2')
+  y = y + Line_height
+  App.screen.check(y, 'jkl', 'F - test_deleting_selection_may_scroll/baseline/screen:3')
+  -- set up a selection starting above the currently displayed page
+  Selection1 = {line=1, pos=2}
+  -- delete selection
+  App.run_after_keychord('backspace')
+  -- page scrolls up
+  check_eq(Screen_top1.line, 1, 'F - test_deleting_selection_may_scroll')
+  check_eq(Lines[1].data, 'ahi', 'F - test_deleting_selection_may_scroll/data')
+end
+
 function test_edit_wrapping_text()
   io.write('\ntest_edit_wrapping_text')
   App.screen.init{width=50, height=60}