From aa3ecd9555e5a18e0813c679115f106f3eb1eda6 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Fri, 3 Sep 2021 19:59:10 +0200 Subject: [PATCH] Avoid calculating column position offset per-char --- data/core/docview.lua | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/data/core/docview.lua b/data/core/docview.lua index cddd82d2..2c870b0a 100644 --- a/data/core/docview.lua +++ b/data/core/docview.lua @@ -161,15 +161,13 @@ function DocView:get_col_x_offset(line, col) local xoffset = 0 for _, type, text in self.doc.highlighter:each_token(line) do local font = style.syntax_fonts[type] or default_font - for char in common.utf8_chars(text) do - if column == col then - return xoffset / font:subpixel_scale() - end - xoffset = xoffset + font:get_width_subpixel(char) - column = column + #char + local remainder = math.min(col - column, #text) + xoffset = xoffset + font:get_width_subpixel(string.sub(text, 1, remainder)) + column = column + remainder + if column == col then + return xoffset / font:subpixel_scale() end end - return xoffset / default_font:subpixel_scale() end