Skip to content

bug: plugin changes j/k behavior #186

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

Closed
2 tasks done
hneutr opened this issue Sep 27, 2024 · 2 comments
Closed
2 tasks done

bug: plugin changes j/k behavior #186

hneutr opened this issue Sep 27, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@hneutr
Copy link

hneutr commented Sep 27, 2024

Neovim version (nvim -v)

0.10.1

Neovim distribution

N/A

Operating system

MacOS

Terminal emulator / GUI

kitty

Describe the bug

The plugin changes the behavior of the j and k normal mode movements.

  1. put the cursor at the end of a long line (without using $; the behavior is as expected if $ is used, weirdly)
  2. move the cursor down (or up) to a shorter line
  3. move the cursor back up (or down) to the longer line

If the long line is length X and the short line is length Y, the cursor will be at column Y of the long line, rather than at column X as expected. In other words, j and k are not inverses.

A more visual explanation:

If the buffer contains the following text, and the cursor is on the character surrounded by brackets:

short line
longer lin[e]

press k

short lin[e]
longer line

press j

short line
longer li[n]e

In other words, the plugin "column memory" of j/k is getting messed with

Expected behavior

start:

short line
longer lin[e]

press k

short lin[e]
longer line

press j

short line
longer lin[e]

Healthcheck output

render-markdown: require("render-markdown.health").check()

render-markdown.nvim [version] ~

  • OK plugin 7.1.15
  • OK neovim >= 0.10

render-markdown.nvim [configuration] ~

  • ERROR render-markdown.code.position: expected one of { "left", "right" }, got

render-markdown.nvim [nvim-treesitter] ~

  • OK installed
  • OK markdown: parser installed
  • OK markdown: highlight enabled
  • OK markdown_inline: parser installed
  • OK markdown_inline: highlight enabled
  • OK latex: parser installed

render-markdown.nvim [executables] ~

  • WARNING latex2text: not installed
    • ADVICE:
      • Disable LaTeX support to avoid this warning by setting { latex = { enabled = false } }

render-markdown.nvim [conflicts] ~

  • OK headlines: not installed
  • OK obsidian: not installed

Plugin configuration

Reproducible with no configuration

Plugin error log

N/A

Confirmations

  • I have updated this plugin to the latest version using my plugin manager
  • I have provided text for all screenshots & understand that my issue will be closed if I have not

Additional information

No response

@hneutr hneutr added the bug Something isn't working label Sep 27, 2024
MeanderingProgrammer added a commit that referenced this issue Sep 27, 2024
## Details

Issue: #186

In order to fix #177
the window option setting logic was updated to always modify window
options rather than on a state transition. The reason was to handle out
of band state transitions for a buffer that would cause the state of the
window options to be changed without the inner states knowledge. As a
result the window options were not being properly updated since
effectively no state transition occured.

While this does seem to have almost no performance penalty it does seem
to reset some kind of state in neovim that causes some kinds of motions
to be have differently, such as moving between ends of lines as reported
in the issue.

To fix this rather than always updating the option value, get the
current value and only set the new value if it is different.

In this way we properly handle out of band transitions since we're
relying on the actual current option value and not some internal state.
And since we don't unnecessarily change the value we don't mess with any
internal neovim state and allow motions to behave as they normally would.
@MeanderingProgrammer
Copy link
Owner

Thanks for reporting this!

At first I thought there was no way it was due to this plugin since we don't track any kind of column state or touch motions at all. But after disabling the plugin and trying a few things it was definitely something I was doing.

Turned out to be related to the constant setting of window local options. While setting the values doesn't seem to have a noticeable performance penalty and I figured internally neovim would do nothing if we were reseting the same value, that did not appear to be the case. There could be a very good reason to still do some work when setting an option even if it's the same value and something about that messed with this column state.

Fix was pretty simple on my end and the plugin now checks if the value being set is different than the current value: 91ce0b5

LMK if it works on your end!

@hneutr
Copy link
Author

hneutr commented Sep 27, 2024

Yeah hah, I really did not expect it to be coming from this plugin when I was doing the ol "disable plugins one by one and see where it's coming from" search. Went digging in the plugin code to see where it might be coming from and didn't find any likely culprits, either. But dang, window local options side effects, now that wouldn't have been my first, second, or third guess — that is some impressive sleuthing on your end.

Fix works like a charm 💫. Thank you!

@hneutr hneutr closed this as completed Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants