Closed mrbeardad closed 7 months ago
There's another function, [getcurpos()
](https://neovim.io/doc/user/builtin.html#getcurpos()), that gives the byte index for the cursor. Would it solve the problem to use that instead (as well as cursor()
instead of setcursorcharpos()
)? I used getcursorcharpos()
because I thought it would handle extended characters, but maybe I have it backwards.
No. The problem about column for extmarks api has been solved with this pr, the remaining problem is,
curswant
is a virtual column, it is relative with character display width, and affect up/down motion.
All vc.curswant = vc.col
is wrong, it needs to be converted first.
local text = vim.fn.strcharpart(vim.fn.getline(lnum), 0, col)
local virtcol = vim.fn.strdisplaywidth(text)
local text = vim.fn.strcharpart(vim.fn.getline(lnum), 0, col) local virtcol = vim.fn.strdisplaywidth(text)
However, the behavior is slightly different from the builtin motion, becase when cursor at a character that has 2-char display width, the curswant can be either the first char or the second char, but the code above always set curswant to the second-char position
12
你
The curswant
of cursor that on 你
is 1
if it has moved down from 1
, or 2
from 2
. so always recover vc.curswant
from vc.col
is not a good idea
Does this branch fix the position issues? I've changed all the position functions to use the byte count versions. I think there's still a problem with the move right command, because this is implemented manually. But otherwise, is it just a problem with the extmarks?
The display width
needs to be considered when set end_col
, check this
Left/Right motion use character column, up/down motion use virtual column(display width).
Why don't use normal command to move cursor? Thus, user setting could be considered automatically, such as whichwrap
,
Left/Right motion use character column, up/down motion use virtual column(display width).
What do you mean by virtual column? The curswant value?
Why don't use normal command to move cursor?
Originally I tried using virtualedit = "onemore"
for insert mode but it didn't seem to work. I thought it was because setting the option wasn't "api-fast" (so it would occur in the event loop like feedkeys
). I think I realise now that the issue is that the $
command doesn't work in insert mode even with virtualedit="onemore
.
Thus, user setting could be considered automatically, such as
whichwrap
,
I'll try changing things to use "onemore" and whichwrap
What do you mean by virtual column? The curswant value?
Virtual column is the last screen position occupied by the character at that position, different unicode character maybe has different display width. For example, the display width of a
is 1, and 你
is 2, so a
occupies 1 screen column, 你
occupies 2 screen column. The virtual column of a
is 1
and 你
is 5.
1234567
abc你好
Assuming the cursor is at 好
, the curswant of the cursor is 6, the virtual column of 好
is 7. Then you moved the cursor up and it was placed on the 6
where the virtual colmun equal to the curswant.
[:h virtcol()
](https://neovim.io/doc/user/builtin.html#virtcol())
Neovim use 3 kinds of column:
curswant
is a virtual column but not a character columnFor example,
你
has3
bytes,1
chracter and2
display width. So3
(start byte index)4
5
(end virtual column)In this pr, I've convert all
vc.col
into byte column when call extmarks api. However, there are too manyvc.curswant = vc.col
, so I make the pr to discuss the solution for it.