Avoid calculating column position offset per-char
This commit is contained in:
parent
8866a5dddf
commit
aa3ecd9555
|
@ -161,15 +161,13 @@ function DocView:get_col_x_offset(line, col)
|
||||||
local xoffset = 0
|
local xoffset = 0
|
||||||
for _, type, text in self.doc.highlighter:each_token(line) do
|
for _, type, text in self.doc.highlighter:each_token(line) do
|
||||||
local font = style.syntax_fonts[type] or default_font
|
local font = style.syntax_fonts[type] or default_font
|
||||||
for char in common.utf8_chars(text) do
|
local remainder = math.min(col - column, #text)
|
||||||
if column == col then
|
xoffset = xoffset + font:get_width_subpixel(string.sub(text, 1, remainder))
|
||||||
return xoffset / font:subpixel_scale()
|
column = column + remainder
|
||||||
end
|
if column == col then
|
||||||
xoffset = xoffset + font:get_width_subpixel(char)
|
return xoffset / font:subpixel_scale()
|
||||||
column = column + #char
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return xoffset / default_font:subpixel_scale()
|
return xoffset / default_font:subpixel_scale()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue