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

fix: update last cursor on first CursorMoved #16698

Merged
merged 1 commit into from
Dec 19, 2021
Merged

fix: update last cursor on first CursorMoved #16698

merged 1 commit into from
Dec 19, 2021

Conversation

mjlbach
Copy link
Contributor

@mjlbach mjlbach commented Dec 18, 2021

Closes #16625
Closes #12923

Supersedes #13867

The first defined CursorMoved autocommand will immediately
fire if the cursor has previously moved upon definition
of the autocommand.

Plugins add dummy autocommands such as:

autocmd CursorMoved * execute ''

to avoid this behavior.

Instead, when defining a new CursorHold autocommand, force
update the last cursor position.

See vim/vim#2053

@mjlbach mjlbach marked this pull request as ready for review December 18, 2021 06:17
@zeertzjq
Copy link
Member

zeertzjq commented Dec 18, 2021

I'm considering making a PR at Vim repository.

@zeertzjq
Copy link
Member

zeertzjq commented Dec 18, 2021

Oh, this is not entirely applicable to Vim, as Vim doesn't store last CursorMoved position per window and only triggers CursorMoved from main loop.

Copy link
Member

@zeertzjq zeertzjq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether this is the best solution. BTW, there are also CursorMovedI and CursorMovedP.

@mjlbach
Copy link
Contributor Author

mjlbach commented Dec 18, 2021

I'm not sure whether this is the best solution. BTW, there are also CursorMovedI and CursorMovedP.

For whatever reason, these don't seem to have the same issue of immediately triggering.

@mjlbach
Copy link
Contributor Author

mjlbach commented Dec 18, 2021

Added a test. @zeertzjq I personally think it is fine to address the issue CursorMoved independently of other autocommands (for which we don't have reported issues yet) as this fixes a weird quirk that affects gitgutter and other plugins. LMK what you think.

Closes #16625

The first defined CursorMoved autocommand will immediately
fire if the cursor has previously moved upon definition
of the autocommand.

Plugins add dummy autocommands such as:

```lua
autocmd CursorMoved * execute ''
```

to avoid this behavior.

Instead, when defining a new CursorHold autocommand, force
update the last cursor position.

See vim/vim#2053
@mjlbach mjlbach merged commit b42e0c4 into neovim:master Dec 19, 2021
@github-actions
Copy link
Contributor

Backport failed for release-0.6, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally.

git fetch origin release-0.6
git worktree add -d .worktree/backport-16698-to-release-0.6 origin/release-0.6
cd .worktree/backport-16698-to-release-0.6
git checkout -b backport-16698-to-release-0.6
ancref=$(git merge-base 95803f0e902278079e5876082465b1910c819947 1bf87ca88a2ee1e9cfc1f0b16128fca6b849f3e0)
git cherry-pick -x $ancref..1bf87ca88a2ee1e9cfc1f0b16128fca6b849f3e0

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