bugfix: infinite loop inside a very narrow window
I'm not sure this can trigger everywhere (I've only been able to exercise it in Lua Carousel), but it seems like a safety net worth having against future modifications by anybody.
This commit is contained in:
parent
0751b38932
commit
c1f7f17f9c
|
@ -128,7 +128,9 @@ function Text.populate_screen_line_starting_pos(State, line_index)
|
||||||
-- long word; chop it at some letter
|
-- long word; chop it at some letter
|
||||||
-- We're not going to reimplement TeX here.
|
-- We're not going to reimplement TeX here.
|
||||||
local bpos = Text.nearest_pos_less_than(frag, State.width - x)
|
local bpos = Text.nearest_pos_less_than(frag, State.width - x)
|
||||||
-- everything works if bpos == 0, but is a little inefficient
|
if x == 0 and bpos == 0 then
|
||||||
|
assert(false, ("Infinite loop while line-wrapping. Editor is %dpx wide; window is %dpx wide"):format(State.width, App.screen.width))
|
||||||
|
end
|
||||||
pos = pos + bpos
|
pos = pos + bpos
|
||||||
local boffset = Text.offset(frag, bpos+1) -- byte _after_ bpos
|
local boffset = Text.offset(frag, bpos+1) -- byte _after_ bpos
|
||||||
frag = string.sub(frag, boffset)
|
frag = string.sub(frag, boffset)
|
||||||
|
|
4
text.lua
4
text.lua
|
@ -103,7 +103,9 @@ function Text.populate_screen_line_starting_pos(State, line_index)
|
||||||
-- long word; chop it at some letter
|
-- long word; chop it at some letter
|
||||||
-- We're not going to reimplement TeX here.
|
-- We're not going to reimplement TeX here.
|
||||||
local bpos = Text.nearest_pos_less_than(frag, State.width - x)
|
local bpos = Text.nearest_pos_less_than(frag, State.width - x)
|
||||||
-- everything works if bpos == 0, but is a little inefficient
|
if x == 0 and bpos == 0 then
|
||||||
|
assert(false, ("Infinite loop while line-wrapping. Editor is %dpx wide; window is %dpx wide"):format(State.width, App.screen.width))
|
||||||
|
end
|
||||||
pos = pos + bpos
|
pos = pos + bpos
|
||||||
local boffset = Text.offset(frag, bpos+1) -- byte _after_ bpos
|
local boffset = Text.offset(frag, bpos+1) -- byte _after_ bpos
|
||||||
frag = string.sub(frag, boffset)
|
frag = string.sub(frag, boffset)
|
||||||
|
|
Loading…
Reference in New Issue