about summary refs log tree commit diff stats
path: root/text.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-07-20 07:08:28 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-07-20 07:08:28 -0700
commita472d218f21cc0787a9e52c6cb03819b27a247e9 (patch)
treeff9630ea1c8682dd0be955cdec840c65f31e00ee /text.lua
parent7dc47edde8b1a573cdf503db59a0d0c68ae03ad7 (diff)
downloadlines.love-a472d218f21cc0787a9e52c6cb03819b27a247e9.tar.gz
allow Text.nearest_pos_less_than to return 0
This eliminates another case of overflowing margins.
Diffstat (limited to 'text.lua')
-rw-r--r--text.lua7
1 files changed, 2 insertions, 5 deletions
diff --git a/text.lua b/text.lua
index 1f10a1b..c83a177 100644
--- a/text.lua
+++ b/text.lua
@@ -104,7 +104,7 @@ function Text.compute_fragments(State, line_index)
         -- We're not going to reimplement TeX here.
         local bpos = Text.nearest_pos_less_than(frag, State.right - x)
 --?         print('bpos', bpos)
-        assert(bpos > 0)  -- avoid infinite loop when window is too narrow
+        if bpos == 0 then break end  -- avoid infinite loop when window is too narrow
         local boffset = Text.offset(frag, bpos+1)  -- byte _after_ bpos
 --?         print('space for '..tostring(bpos)..' graphemes, '..tostring(boffset-1)..' bytes')
         local frag1 = string.sub(frag, 1, boffset-1)
@@ -800,15 +800,12 @@ end
 -- within x pixels of the left margin
 function Text.nearest_pos_less_than(line, x)
 --?   print('', '-- nearest_pos_less_than', line, x)
-  if x == 0 then
-    return 1
-  end
   local len = utf8.len(line)
   local max_x = Text.x(line, len)
   if x > max_x then
     return len+1
   end
-  local left, right = 1, len+1
+  local left, right = 0, len+1
   while true do
     local curr = math.floor((left+right)/2)
     local currxmin = Text.x(line, curr+1)