gk skips a line if cursor is at column 0 position (Obsidian)
Closed this issue · 4 comments
Hi,
Originally saw this discussed on the Obsidian forums here and it was suggested to make an issue here.
If cursor is at the start of a line (i.e. column 1) position then a gk
command moves up two lines instead of one.
If cursor is at any other column position gk
works correctly.
gj
works correctly at all column positions.
Steps to reproduce
Open a file with wrapped long paragraph. Make sure vim is open and it is in view mode.
gg: curosr at first line
gj x 2: cursor to third line
gk: cursor to the first line rather than second
Expected result
In vim view mode, pressing gk leads to 1 viewing line up.
Actual result
Pressing gk leads to 2 viewing line up if cursor is at the head of one line.
Environment
Obsidian vim mode
Additional information
gj works fine. gk works also if cursor at the middle of a line.
For clarification, this only happens when the line is wrapped, correct?
Yes that's correct. Apologies I should've mentioned that.
I'm afraid this is a CodeMirror issue, rather than CodeMirror Vim.
The unexpected behaviour is generated here and does exactly what described in the issue.
Example:
- My lines are 100 characters long.
- My first line contains a 100 letters.
- My second line contains 200 letters and wraps.
- Let the cursor be on the first character of the third line (wrapped second line).
- The cursor position is 200.
- Calling CodeMirror's
moveVertically
will return 0 instead of 100.
I am unsure if this is the intended behaviour of the relevant function. A monkey-patch on our end would be to artificially move the cursor one character to the right and then back to the left, but I imagine that would introduce even more bugs.
I believe this is the relevant function upstream.
Update:
I am unable to reproduce this issue in raw CodeMirror, wherefore I haven't opened an issue there yet. Seemingly equal calls to that function on the same version of CodeMirror View result in different results when I press arrow up in CodeMirror vs gk
in CodeMirror Vim.
Will continue to investigate when I find some time, but I'm momentarily out of ideas.
@Opisek seems to be a bug in EditorSelection.range which creates a cursor that is displayed as a range with assoc=1
, but behaves as one with assoc=-1