another piece of support for line wrapping in cursor up

This commit is contained in:
Kartik K. Agaram 2022-05-20 15:19:43 -07:00
parent 7e6705a113
commit ce94f8bf79
2 changed files with 10 additions and 1 deletions

View File

@ -23,5 +23,6 @@ scrolling:
cursor remains on text line
'up' arrow with cursor at top of screen scrolls up one line (drawings still fully in or out)
if top line wrapped before, it scrolls up by only one screen line
if previous line (above top of screen) wrapped, it scrolls up by only one screen line
'down' arrow with cursor at bottom of screen scrolls down one line (drawings still fully in or out)
if top line wrapped before, it scrolls down by only one screen line

View File

@ -227,7 +227,15 @@ function Text.keychord_pressed(chord)
if Lines[new_cursor_line].mode == 'text' then
local old_x = Text.cursor_x(Lines[new_cursor_line].data, Cursor_pos)
Cursor_line = new_cursor_line
Cursor_pos = Text.nearest_cursor_pos(Lines[Cursor_line].data, old_x)
if Lines[Cursor_line].screen_line_starting_pos == nil then
Cursor_pos = Text.nearest_cursor_pos(Lines[Cursor_line].data, old_x)
break
end
local screen_line_starting_pos = Lines[Cursor_line].screen_line_starting_pos
screen_line_starting_pos = screen_line_starting_pos[#screen_line_starting_pos]
Top_screen_line_starting_pos = screen_line_starting_pos
local s = string.sub(Lines[Cursor_line].data, screen_line_starting_pos)
Cursor_pos = screen_line_starting_pos + Text.nearest_cursor_pos(s, old_x) - 1
break
end
end