about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-08-18 13:04:04 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-08-18 13:04:04 -0700
commit72866ec0adb9e744e40bc5e1eba027f5dd32d41b (patch)
treec0a8d79ef224e91844a46efa1f9a74f914f81fef
parent0bf34a9ce043b04ba99fc5236f69fb724705cc52 (diff)
downloadview.love-72866ec0adb9e744e40bc5e1eba027f5dd32d41b.tar.gz
get rid of some ridiculous code
I guess I wrote it before I settled into the idiom of:
* first change cursor
* then scroll if necessary
-rw-r--r--text.lua20
1 files changed, 5 insertions, 15 deletions
diff --git a/text.lua b/text.lua
index 071b52d..451ab51 100644
--- a/text.lua
+++ b/text.lua
@@ -442,36 +442,26 @@ function Text.up(State)
         local screen_line_starting_pos = State.line_cache[State.cursor1.line].screen_line_starting_pos
 --?         print(#screen_line_starting_pos)
         screen_line_starting_pos = screen_line_starting_pos[#screen_line_starting_pos]
---?         print('previous screen line starts at pos '..tostring(screen_line_starting_pos)..' of its line')
-        if State.screen_top1.line > State.cursor1.line then
-          State.screen_top1.line = State.cursor1.line
-          State.screen_top1.pos = screen_line_starting_pos
---?           print('pos of top of screen is also '..tostring(State.screen_top1.pos)..' of the same line')
-        end
         local screen_line_starting_byte_offset = Text.offset(State.lines[State.cursor1.line].data, screen_line_starting_pos)
         local s = string.sub(State.lines[State.cursor1.line].data, screen_line_starting_byte_offset)
         State.cursor1.pos = screen_line_starting_pos + Text.nearest_cursor_pos(s, State.cursor_x, State.left) - 1
         break
       end
     end
-    if State.cursor1.line < State.screen_top1.line then
-      State.screen_top1.line = State.cursor1.line
-    end
   else
     -- move up one screen line in current line
---?     print('cursor is NOT at first screen line of its line')
     assert(screen_line_index > 1)
     new_screen_line_starting_pos = State.line_cache[State.cursor1.line].screen_line_starting_pos[screen_line_index-1]
---?     print('switching pos of screen line at cursor from '..tostring(screen_line_starting_pos)..' to '..tostring(new_screen_line_starting_pos))
-    if State.screen_top1.line == State.cursor1.line and State.screen_top1.pos == screen_line_starting_pos then
-      State.screen_top1.pos = new_screen_line_starting_pos
---?       print('also setting pos of top of screen to '..tostring(State.screen_top1.pos))
-    end
     local new_screen_line_starting_byte_offset = Text.offset(State.lines[State.cursor1.line].data, new_screen_line_starting_pos)
     local s = string.sub(State.lines[State.cursor1.line].data, new_screen_line_starting_byte_offset)
     State.cursor1.pos = new_screen_line_starting_pos + Text.nearest_cursor_pos(s, State.cursor_x, State.left) - 1
 --?     print('cursor pos is now '..tostring(State.cursor1.pos))
   end
+  if Text.lt1(State.cursor1, State.screen_top1) then
+    local top2 = Text.to2(State, State.screen_top1)
+    top2 = Text.previous_screen_line(State, top2)
+    State.screen_top1 = Text.to1(State, top2)
+  end
 end
 
 function Text.down(State)