about summary refs log tree commit diff stats
path: root/source_text.lua
diff options
context:
space:
mode:
Diffstat (limited to 'source_text.lua')
-rw-r--r--source_text.lua15
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