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.
This commit is contained in:
parent
cf7bff30f7
commit
aad21bd9a1
7
move.lua
7
move.lua
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue