diff options
Diffstat (limited to 'text.lua')
-rw-r--r-- | text.lua | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/text.lua b/text.lua index fdf2418..1f31d60 100644 --- a/text.lua +++ b/text.lua @@ -815,15 +815,15 @@ function Text.nearest_pos_less_than(line, x) return 1 end local len = utf8.len(line) - local max_x = Text.x_after(line, len) + local max_x = Text.x(line, len) if x > max_x then return len+1 end local left, right = 1, len+1 while true do local curr = math.floor((left+right)/2) - local currxmin = Text.x_after(line, curr+1) - local currxmax = Text.x_after(line, curr+2) + local currxmin = Text.x(line, curr+1) + local currxmax = Text.x(line, curr+2) --? print(x, left, right, curr, currxmin, currxmax) if currxmin <= x and x < currxmax then return curr @@ -840,7 +840,7 @@ function Text.nearest_pos_less_than(line, x) assert(false) end -function Text.x_after(s, pos) +function Text.x(s, pos) local offset = Text.offset(s, math.min(pos+1, #s+1)) local s_before = s:sub(1, offset-1) --? print('^'..s_before..'$') @@ -848,13 +848,6 @@ function Text.x_after(s, pos) return App.width(text_before) end -function Text.x(s, pos) - local offset = Text.offset(s, pos) - local s_before = s:sub(1, offset-1) - local text_before = App.newText(love.graphics.getFont(), s_before) - return App.width(text_before) -end - function Text.to2(State, pos1) if State.lines[pos1.line].mode == 'drawing' then return {line=pos1.line, screen_line=1, screen_pos=1} |