about summary refs log tree commit diff stats
path: root/text.lua
diff options
context:
space:
mode:
Diffstat (limited to 'text.lua')
-rw-r--r--text.lua15
1 files changed, 15 insertions, 0 deletions
diff --git a/text.lua b/text.lua
index b6389e4..d89fb63 100644
--- a/text.lua
+++ b/text.lua
@@ -591,6 +591,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]
@@ -603,6 +604,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