fix: use current char to determine col in DocView:get_x_offset_col (#1946)
Previously it would use the last char position, which resulted in incorrect values when the next char had a different size than the current one. (cherry picked from commit f066c88e186a02b9912d7f102b541f514ae1aa35)
This commit is contained in:
@@ -203,7 +203,7 @@ end
|
|||||||
function DocView:get_x_offset_col(line, x)
|
function DocView:get_x_offset_col(line, x)
|
||||||
local line_text = self.doc.lines[line]
|
local line_text = self.doc.lines[line]
|
||||||
|
|
||||||
local xoffset, last_i, i = 0, 1, 1
|
local xoffset, i = 0, 1
|
||||||
local default_font = self:get_font()
|
local default_font = self:get_font()
|
||||||
local _, indent_size = self.doc:get_indent_info()
|
local _, indent_size = self.doc:get_indent_info()
|
||||||
default_font:set_tab_size(indent_size)
|
default_font:set_tab_size(indent_size)
|
||||||
@@ -219,11 +219,10 @@ function DocView:get_x_offset_col(line, x)
|
|||||||
else
|
else
|
||||||
for char in common.utf8_chars(text) do
|
for char in common.utf8_chars(text) do
|
||||||
local w = font:get_width(char)
|
local w = font:get_width(char)
|
||||||
if xoffset >= x then
|
if xoffset + w >= x then
|
||||||
return (xoffset - x > w / 2) and last_i or i
|
return (x <= xoffset + (w / 2)) and i or i + #char
|
||||||
end
|
end
|
||||||
xoffset = xoffset + w
|
xoffset = xoffset + w
|
||||||
last_i = i
|
|
||||||
i = i + #char
|
i = i + #char
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user