~akkartik/lines2.love

aad21bd9a1ce0e654b0f0e37422e952bf4678ac5 — Kartik K. Agaram a month ago cf7bff3
bugfix: reduce error in edit.hor

Cursor no longer drifts left as you repeatedly press up/down arrow
within a region of filled screen lines.
1 files changed, 5 insertions(+), 2 deletions(-)

M move.lua
M move.lua => move.lua +5 -2
@@ 489,15 489,17 @@ function edit.hor(Editor, loc, x0)  -- scans line
  local line = Editor.lines[loc.line]
  -- look within the screen line
  local x = Editor.left
  local prevx = nil
  for pos,char in utf8chars(line.data, start_pos_of_screen_line) do
    local w = Editor.font:getWidth(char)
    if char:match('%s') then
      if Text.line_wrap_at_word_boundary(Editor, x, line.data, pos) then
        return {mode='text', line=loc.line, pos=pos+1}
      else
        if x+w > x0 then
        if (prevx == nil or x0 >= (prevx+x)/2) and x0 < x+w/2 then
          return {mode='text', line=loc.line, pos=pos}
        end
        prevx = x
        x = x + w
      end
    else


@@ 505,10 507,11 @@ function edit.hor(Editor, loc, x0)  -- scans line
        assert(x0 > x)  -- we clicked really far to the right
        return {mode='text', line=loc.line, pos=pos}
      else
        if x+w > x0 then
        if (prevx == nil or x0 >= (prevx+x)/2) and x0 < x+w/2 then
          return {mode='text', line=loc.line, pos=pos}
        end
      end
      prevx = x
      x = x + w
    end
  end