Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gk skips a line if cursor is at column 0 position (Obsidian) #165

Closed
apotenza92 opened this issue Feb 13, 2024 · 4 comments
Closed

gk skips a line if cursor is at column 0 position (Obsidian) #165

apotenza92 opened this issue Feb 13, 2024 · 4 comments

Comments

@apotenza92
Copy link

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.

@Opisek
Copy link
Contributor

Opisek commented Feb 18, 2024

For clarification, this only happens when the line is wrapped, correct?

@apotenza92
Copy link
Author

Yes that's correct. Apologies I should've mentioned that.

@Opisek
Copy link
Contributor

Opisek commented Feb 21, 2024

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.

@nightwing
Copy link
Collaborator

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants