diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2023-06-04 15:11:24 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2023-06-04 15:11:24 -0700 |
commit | bf2c2555d662865b94256e6e854acc0715fda6d1 (patch) | |
tree | 5c444b3e2abe7c3b220e4c03c09ece70a9e04946 /source_text.lua | |
parent | 074f4d9b0a51dc99df9183a45a9c2301f575b35b (diff) | |
parent | 637e28f300def4172459dd1d6fdf6efd53200ea8 (diff) | |
download | text.love-bf2c2555d662865b94256e6e854acc0715fda6d1.tar.gz |
Merge lines.love
Diffstat (limited to 'source_text.lua')
-rw-r--r-- | source_text.lua | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/source_text.lua b/source_text.lua index 290d982..1a42310 100644 --- a/source_text.lua +++ b/source_text.lua @@ -650,6 +650,7 @@ function Text.right_without_scroll(State) end end +-- result: pos, index of screen line function Text.pos_at_start_of_screen_line(State, loc1) Text.populate_screen_line_starting_pos(State, loc1.line) local line_cache = State.line_cache[loc1.line] @@ -662,6 +663,20 @@ function Text.pos_at_start_of_screen_line(State, loc1) assert(false) end +function Text.pos_at_end_of_screen_line(State, loc1) + Text.populate_screen_line_starting_pos(State, loc1.line) + local line_cache = State.line_cache[loc1.line] + local most_recent_final_pos = utf8.len(State.lines[loc1.line].data)+1 + for i=#line_cache.screen_line_starting_pos,1,-1 do + local spos = line_cache.screen_line_starting_pos[i] + if spos <= loc1.pos then + return most_recent_final_pos + end + most_recent_final_pos = spos-1 + end + assert(false) +end + function Text.cursor_at_final_screen_line(State) Text.populate_screen_line_starting_pos(State, State.cursor1.line) local screen_lines = State.line_cache[State.cursor1.line].screen_line_starting_pos |