Don't calculate widths per-uft8-char when not needed (#1409)
This commit is contained in:
parent
ef70faa2fd
commit
d0ec3aa0fe
|
@ -175,14 +175,23 @@ function DocView:get_col_x_offset(line, col)
|
|||
for _, type, text in self.doc.highlighter:each_token(line) do
|
||||
local font = style.syntax_fonts[type] or default_font
|
||||
if font ~= default_font then font:set_tab_size(indent_size) end
|
||||
local length = #text
|
||||
if column + length <= col then
|
||||
xoffset = xoffset + font:get_width(text)
|
||||
column = column + length
|
||||
if column >= col then
|
||||
return xoffset
|
||||
end
|
||||
else
|
||||
for char in common.utf8_chars(text) do
|
||||
if column == col then
|
||||
if column >= col then
|
||||
return xoffset
|
||||
end
|
||||
xoffset = xoffset + font:get_width(char)
|
||||
column = column + #char
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return xoffset
|
||||
end
|
||||
|
@ -198,6 +207,13 @@ function DocView:get_x_offset_col(line, x)
|
|||
for _, type, text in self.doc.highlighter:each_token(line) do
|
||||
local font = style.syntax_fonts[type] or default_font
|
||||
if font ~= default_font then font:set_tab_size(indent_size) end
|
||||
local width = font:get_width(text)
|
||||
-- Don't take the shortcut if the width matches x,
|
||||
-- because we need last_i which should be calculated using utf-8.
|
||||
if xoffset + width < x then
|
||||
xoffset = xoffset + width
|
||||
i = i + #text
|
||||
else
|
||||
for char in common.utf8_chars(text) do
|
||||
local w = font:get_width(char)
|
||||
if xoffset >= x then
|
||||
|
@ -208,6 +224,7 @@ function DocView:get_x_offset_col(line, x)
|
|||
i = i + #char
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return #line_text
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue