about summary refs log tree commit diff stats
path: root/select.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-06-19 09:03:09 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-06-19 09:06:41 -0700
commit703ed905c13a837c683aed0bf09bb68b0d7c9430 (patch)
tree646003b6fe6ec9d54581174c17062b9c2e12475c /select.lua
parentb6fa2aae6e9b0793280139ad7e5edd2468eac494 (diff)
downloadtext.love-703ed905c13a837c683aed0bf09bb68b0d7c9430.tar.gz
bugfix: crash in Text.up() after return
Let's just make all the utf8.offset calculations more defensive.
Diffstat (limited to 'select.lua')
-rw-r--r--select.lua14
1 files changed, 7 insertions, 7 deletions
diff --git a/select.lua b/select.lua
index 839e770..5659015 100644
--- a/select.lua
+++ b/select.lua
@@ -55,9 +55,9 @@ end
 -- Returns some intermediate computation useful elsewhere.
 function Text.draw_highlight(line, x,y, pos, lo,hi)
   if lo then
-    local lo_offset = utf8.offset(line.data, lo)
-    local hi_offset = utf8.offset(line.data, hi)
-    local pos_offset = utf8.offset(line.data, pos)
+    local lo_offset = Text.offset(line.data, lo)
+    local hi_offset = Text.offset(line.data, hi)
+    local pos_offset = Text.offset(line.data, pos)
     local lo_px
     if pos == lo then
       lo_px = 0
@@ -137,8 +137,8 @@ function Text.delete_selection_without_undo()
   -- delete everything between min (inclusive) and max (exclusive)
   Lines[minl].fragments = nil
   Lines[minl].screen_line_starting_pos = nil
-  local min_offset = utf8.offset(Lines[minl].data, minp)
-  local max_offset = utf8.offset(Lines[maxl].data, maxp)
+  local min_offset = Text.offset(Lines[minl].data, minp)
+  local max_offset = Text.offset(Lines[maxl].data, maxp)
   if minl == maxl then
 --?     print('minl == maxl')
     Lines[minl].data = Lines[minl].data:sub(1, min_offset-1)..Lines[minl].data:sub(max_offset)
@@ -165,8 +165,8 @@ function Text.selection()
       minp,maxp = maxp,minp
     end
   end
-  local min_offset = utf8.offset(Lines[minl].data, minp)
-  local max_offset = utf8.offset(Lines[maxl].data, maxp)
+  local min_offset = Text.offset(Lines[minl].data, minp)
+  local max_offset = Text.offset(Lines[maxl].data, maxp)
   if minl == maxl then
     return Lines[minl].data:sub(min_offset, max_offset-1)
   end