diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-07-17 09:21:57 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-07-17 09:21:57 -0700 |
commit | 860cd49f67487c4ebb8e0d1c218cf112471eab5c (patch) | |
tree | ef5ce13cc200c41d786cd949f7ad3f66c89680bc | |
parent | 2859063d9d10f05a3db695cf3ccd142a7432a43f (diff) | |
download | text.love-860cd49f67487c4ebb8e0d1c218cf112471eab5c.tar.gz |
make a function oblivious to line data structure
- Text.screen_line_index
-rw-r--r-- | text.lua | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/text.lua b/text.lua index 50c9c15..6591023 100644 --- a/text.lua +++ b/text.lua @@ -699,7 +699,7 @@ function Text.in_line(State, line_index, x,y) if x < State.left then return false end if y < line.starty then return false end Text.populate_screen_line_starting_pos(State, line_index) - return y < line.starty + State.line_height*(#line.screen_line_starting_pos - Text.screen_line_index(line, line.startpos) + 1) + return y < line.starty + State.line_height*(#line.screen_line_starting_pos - Text.screen_line_index(line.screen_line_starting_pos, line.startpos) + 1) end -- convert mx,my in pixels to schema-1 coordinates @@ -711,7 +711,7 @@ function Text.to_pos_on_line(State, line_index, mx, my) assert(my >= line.starty) -- duplicate some logic from Text.draw local y = line.starty - local start_screen_line_index = Text.screen_line_index(line, line.startpos) + local start_screen_line_index = Text.screen_line_index(line.screen_line_starting_pos, line.startpos) for screen_line_index = start_screen_line_index,#line.screen_line_starting_pos do local screen_line_starting_pos = line.screen_line_starting_pos[screen_line_index] local screen_line_starting_byte_offset = Text.offset(line.data, screen_line_starting_pos) @@ -749,9 +749,9 @@ function Text.screen_line_width(line, i) return App.width(screen_line_text) end -function Text.screen_line_index(line, pos) - for i = #line.screen_line_starting_pos,1,-1 do - if line.screen_line_starting_pos[i] <= pos then +function Text.screen_line_index(screen_line_starting_pos, pos) + for i = #screen_line_starting_pos,1,-1 do + if screen_line_starting_pos[i] <= pos then return i end end |