lite icon indicating copy to clipboard operation
lite copied to clipboard

StatusView shows incorrect number of columns

Open richiefreedom opened this issue 2 years ago • 0 comments

The number of columns shown by StatusView is correct only for English texts. Any language that needs more than 1 byte to represent characters in UTF-8 results to an incorrect column number.

This works the described way because the column is obtained simply by calling the method Doc:get_selection, which works with plain bytes instead of runes.

A simple fix to the problem is counting of runes with something like:

function common.utf8_len(text)
  local len = 0
  for char in common.utf8_chars(text) do len = len + 1 end
  return len
end

So, the column in StatusView:get_items() can be recomputed the following way:

col = common.utf8_len(dv.doc:get_text(line, 1, line, col)) + 1

richiefreedom avatar May 03 '22 17:05 richiefreedom