rxi / lite

A lightweight text editor written in Lua
MIT License
7.42k stars 352 forks source link

StatusView shows incorrect number of columns #300

Open richiefreedom opened 2 years ago

richiefreedom commented 2 years ago

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