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

bug: incorrect cursor position when jumping with split #896

Closed
4 tasks done
nxmxsxs opened this issue Feb 3, 2025 · 0 comments · Fixed by #888
Closed
4 tasks done

bug: incorrect cursor position when jumping with split #896

nxmxsxs opened this issue Feb 3, 2025 · 0 comments · Fixed by #888
Labels
bug Something isn't working

Comments

@nxmxsxs
Copy link

nxmxsxs commented Feb 3, 2025

Did you check docs and existing issues?

  • I have read all the snacks.nvim docs
  • I have updated the plugin to the latest version before submitting this issue
  • I have searched the existing issues of snacks.nvim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

NVIM v0.11.0-nightly+b8e947e

Operating system/version

linux

Describe the bug

One of the issues is the win isn't updated to the correct one before setting the cursor
This patch should fix it:

diff --git a/lua/snacks/picker/actions.lua b/lua/snacks/picker/actions.lua
index eae00e6..3efe809 100644
--- a/lua/snacks/picker/actions.lua
+++ b/lua/snacks/picker/actions.lua
@@ -103,6 +103,7 @@ function M.jump(picker, _, action)
   end
 
   -- set the cursor
+  win = vim.api.nvim_get_current_win();
   local item = items[1]
   local pos = item.pos
   if picker.opts.jump.match then

I'm not sure if this is related but I think I've found a couple of issues in this code block:

-- use an existing window if possible
if #items == 1 and picker.opts.jump.reuse_win and buf ~= current_buf then
win = vim.fn.win_findbuf(buf)[1] or win
vim.api.nvim_set_current_win(win)
end

Would you mind explaining what's the intended behaviour with reuse_win=true when jumping with split?

Steps To Reproduce

You would have to trigger and edit + split/vspit on an item containing a position (eg: lsp_definition, lsp_references, ...)

Expected Behavior

The cursor should be at the correct position after jumping.

Repro

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
  spec = {
    { "folke/snacks.nvim", opts = {} },
    -- add any other plugins here
  },
})
@nxmxsxs nxmxsxs added the bug Something isn't working label Feb 3, 2025
@folke folke closed this as completed in 95d3e7f Feb 3, 2025
folke pushed a commit that referenced this issue Feb 7, 2025
🤖 I have created a release *beep* *boop*
---


##
[2.19.0](v2.18.0...v2.19.0)
(2025-02-07)


### Features

* **bigfile:** configurable average line length (default = 1000). Useful
for minified files. Closes
[#576](#576). Closes
[#372](#372)
([7fa92a2](7fa92a2))
* **explorer:** add hl groups for ignored / hidden files. Closes
[#887](#887)
([85e1b34](85e1b34))
* **explorer:** added ctrl+f to grep in the item's directory
([0454b21](0454b21))
* **explorer:** added ctrl+t to open a terminal in the item's directory
([81f9006](81f9006))
* **explorer:** added diagnostics file/directory status
([7f1b60d](7f1b60d))
* **explorer:** added quick nav with `[`, `]` with `d/w/e` for
diagnostics
([d1d5585](d1d5585))
* **explorer:** added support for live search
([82c4a50](82c4a50))
* **explorer:** allow disabling untracked git status. Closes
[#983](#983)
([a3b083b](a3b083b))
* **explorer:** different hl group for broken links
([1989921](1989921))
* **explorer:** disable fuzzy searches by default for explorer since
it's too noisy and we can't sort on score due to tree view
([b07788f](b07788f))
* **explorer:** file watcher when explorer is open
([6936c14](6936c14))
* **explorer:** file watching that works on all platforms
([8399465](8399465))
* **explorer:** focus on first file when searching in the explorer
([1d4bea4](1d4bea4))
* **explorer:** git index watcher
([4c12475](4c12475))
* **explorer:** rewrite that no longer depends on `fd` for exploring
([6149a7b](6149a7b))
* **explorer:** show symlink target
([dfa79e0](dfa79e0))
* **matcher:** call on_match after setting score
([23ce529](23ce529))
* **picker.git:** add confirmation before deleting a git branch
([#951](#951))
([337a3ae](337a3ae))
* **picker.git:** add create and delete branch to git_branches
([#909](#909))
([8676c40](8676c40))
* **picker.lazy:** don't use `grep`. Parse spec files manually. Closes
[#972](#972)
([0928007](0928007))
* **picker.lsp:** use existing buffers for preview when opened
([d4e6353](d4e6353))
* **picker.matcher:** internal `on_match`
([47b3b69](47b3b69))
* **picker.preview:** allow confguring `preview = {main = true, enabled
= false}`
([1839c65](1839c65))
* **picker.undo:** added ctrl+y to yank added lines from undo
([811a24c](811a24c))
* **picker:** `picker:dir()` to get the dir of the item (when a
directory) or it's parent (when a file)
([969608a](969608a))
* **picker:** added `git_grep` picker. Closes
[#986](#986)
([2dc9016](2dc9016))
* **picker:** allow configuring file icon width. Closes
[#981](#981)
([52c1086](52c1086))
* **picker:** better checkhealth
([b773368](b773368))
* **picker:** get filetype from modeline when needed. Closes
[#987](#987)
([5af04ab](5af04ab))
* **picker:** opts.on_close
([6235f44](6235f44))
* **picker:** pin picker as a split to left/bottom/top/right with
`ctrl+z+(hjkl)`
([27cba53](27cba53))
* **rename:** add `old` to `on_rename` callback
([455228e](455228e))
* **scope:** allow injected languages to be parsed by treesitter
([#823](#823))
([aba21dd](aba21dd))
* **statuscolumn:** added mouse click handler to open/close folds.
Closes [#968](#968)
([98a7b64](98a7b64))
* **terminal:** added `start_insert`
([64129e4](64129e4))
* **terminal:** auto_close and auto_insert. Closes
[#965](#965)
([bb76cae](bb76cae))


### Bug Fixes

* **bigfile:** check that passed path is the one from the buffer
([8deea64](8deea64))
* **explorer.git:** better git status watching
([09349ec](09349ec))
* **explorer.git:** dont reset cursor when git status is done updating
([bc87992](bc87992))
* **explorer.git:** vim.schedule git updates
([3aad761](3aad761))
* **explorer.tree:** fix linux
([6f5399b](6f5399b))
* **explorer.tree:** symlink directories
([e5f1e91](e5f1e91))
* **explorer.watch:** pcall watcher, since it can give errors on windows
([af96818](af96818))
* **explorer:** always refresh state when opening the picker since
changes might have happened that were not monitored
([c61114f](c61114f))
* **explorer:** call original `on_close`. Closes
[#971](#971)
([a0bee9f](a0bee9f))
* **explorer:** check that picker is still open
([50fa1be](50fa1be))
* **explorer:** clear cache after action. Fixes
[#890](#890)
([34097ff](34097ff))
* **explorer:** clear selection after delete. Closes
[#898](#898)
([44733ea](44733ea))
* **explorer:** disable follow for explorer search by default. No longer
needed. Link directories may show as files then though, but that's not
an issue. See [#960](#960)
([b9a17d8](b9a17d8))
* **explorer:** don't use --absolute-path option, since that resolves
paths to realpath. See
[#901](#901). See
[#905](#905). See
[#904](#904)
([97570d2](97570d2))
* **explorer:** dont focus first file when not searching
([3fd437c](3fd437c))
* **explorer:** dont process git when picker closed
([c255d9c](c255d9c))
* **explorer:** last status for indent guides taking hidden / ignored
files into account
([94bd2ef](94bd2ef))
* **explorer:** strip cwd from search text for explorer items
([38f392a](38f392a))
* **explorer:** windows
([b560054](b560054))
* **exporer.tree:** and now hopefully on windows
([ef9b12d](ef9b12d))
* **git:** use nul char as separator for git status
([8e0dfd2](8e0dfd2))
* **health:** better health checks for picker. Closes
[#917](#917)
([427f036](427f036))
* **picker.actions:** close preview before buffer delete
([762821e](762821e))
* **picker.actions:** don't reuse_win in floating windows (like the
picker preview)
([4b9ea98](4b9ea98))
* **picker.actions:** fix qflist position
([#911](#911))
([6d3c135](6d3c135))
* **picker.actions:** get win after splitting or tabnew. Fixes
[#896](#896)
([95d3e7f](95d3e7f))
* **picker.colorscheme:** use wildignore. Closes
[#969](#969)
([ba8badf](ba8badf))
* **picker.db:** better script to download sqlite3 on windows. See
[#918](#918)
([84d1a92](84d1a92))
* **picker.finder:** correct check if filter changed
([52bc24c](52bc24c))
* **picker.input:** fixed startinsert weirdness with prompt buffers
(again)
([c030827](c030827))
* **picker.input:** set as not modified when setting input through API
([54a041f](54a041f))
* **picker.list:** better wrap settings for when wrapping is enabled
([a542ea4](a542ea4))
* **picker.list:** let user override wrap
([22da4bd](22da4bd))
* **picker.list:** nil check
([c22e46a](c22e46a))
* **picker.lsp:** fix indent guides for sorted document symbols
([17360e4](17360e4))
* **picker.lsp:** sort document symbols by position
([cc22177](cc22177))
* **picker.matcher:** don't optimize pattern subsets when pattern has a
negation
([a6b3d78](a6b3d78))
* **picker.preview:** don't clear preview state on close so that
colorscheme can be restored. Closes
[#932](#932)
([9688bd9](9688bd9))
* **picker.preview:** update main preview when changing the layout
([604c603](604c603))
* **picker.projects:** add custom project dirs
([c7293bd](c7293bd))
* **picker.projects:** use fd or fdfind
([270250c](270250c))
* **picker.select:** default height shows just the items. See
[#902](#902)
([c667622](c667622))
* **picker:** better handling when entering the root layout window.
Closes [#894](#894)
([e294fd8](e294fd8))
* **picker:** consider zen windows as main. Closes
[#973](https://github.com/folke/snacks.nvim/issues/973)
([b1db65a](b1db65a))
* **picker:** disabled preview main
([9fe43bd](9fe43bd))
* **picker:** exit insert mode before closing with `<c-c>` to
prevent cursor shifting left. Close
[#956](#956)
([71eae96](71eae96))
* **picker:** initial preview state when main
([cd6e336](cd6e336))
* **picker:** only show extmark errors when debug is enabled. Closes
[#988](#988)
([f6d9af7](f6d9af7))
* **win:** apply win-local window options for new buffers displayed in a
window. Fixes [#925](#925)
([cb99c46](cb99c46))
* **win:** better handling of alien buffers opening in managed windows.
See [#886](https://github.com/folke/snacks.nvim/issues/886)
([c8430fd](c8430fd))


### Performance Improvements

* **explorer:** disable watchdirs fallback watcher
([5d34380](5d34380))
* **explorer:** early exit for tree calculation
([1a30610](1a30610))
* **explorer:** no need to get git status with `-uall`. Closes
[#983](#983)
([bc087d3](bc087d3))
* **picker.list:** only re-render when visible items changed
([c72e62e](c72e62e))
* **picker:** cache treesitter line highlights
([af31c31](af31c31))
* **picker:** cache wether ts lang exists and disable smooth scrolling
on big files
([719b36f](719b36f))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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

Successfully merging a pull request may close this issue.

1 participant