Skip to content

Conversation

@pynappo
Copy link
Collaborator

@pynappo pynappo commented Aug 31, 2025

Closes #1548 (hopefully)

Basically instead of saving before/after render we just forcibly save a new position every time the cursor moves, which makes the saved position much more up-to-date.

@pynappo pynappo changed the title fix(renderer): save cursor and window position more frequently fix(renderer): save cursor & window pos on CursorMoved Aug 31, 2025
@pynappo pynappo merged commit aa27c5c into nvim-neo-tree:main Aug 31, 2025
9 checks passed
@erikbloodshed
Copy link

erikbloodshed commented Aug 31, 2025

After this commit, whenever i open the neo-tree, the cursor position is now always at the top of the neo-tree's window and not on the name of the file that is currently opened where i initiate the open command.

return {
  "nvim-neo-tree/neo-tree.nvim",
   keys = {
    {
      "<leader>ef",
      function()
        require("neo-tree.command").execute({
          toggle = true,
          reveal = true,
          reveal_force_cwd = true,
        })
      end,
    },

    {
      "<leader>ev",
      function()
        require("neo-tree.command").execute({
          dir = "/home/xenyan/.config/nvim",
          toggle = true,
          reveal = true,
        })
      end,
    },
  },

  dependencies = {
    "nvim-lua/plenary.nvim",
    "nvim-tree/nvim-web-devicons",
    "MunifTanjim/nui.nvim",
  },

  config = function()
    local api = vim.api
    local opt = vim.opt

    local hl = api.nvim_get_hl(0, { name = "Cursor", link = false })
    opt.guicursor:append("a:Cursor/lCursor")
    local function hide_cursor()
      api.nvim_set_hl(0, "Cursor", { blend = 100, fg = hl.fg, bg = hl.bg })
    end

    local function show_cursor()
      api.nvim_set_hl(0, "Cursor", { blend = 0,fg = hl.fg, bg = hl.bg })
    end

    require("neo-tree").setup({
      source_selector = {
        winbar = false,
        statusline = false,
      },
      close_if_last_window = true,
      popup_border_style = "rounded",
      filesystem = {
        bind_to_cwd = false,
        follow_current_file = { enabled = true },
        filtered_items = {
          hide_by_pattern = { "*.out" },
        },
        use_libuv_file_watcher = false,
      },
      event_handlers = {
        {
          event = "neo_tree_buffer_enter",
          handler = hide_cursor
        },
        {
          event = "neo_tree_buffer_leave",
          handler = show_cursor,
        },
        {
          event = "file_opened",
          handler = function()
            require("neo-tree.command").execute({ action = "close" })
          end,
        },
        {
          event = "neo_tree_popup_input_ready",
          handler = function(args)
            show_cursor()
            vim.keymap.set("i", "<esc>", vim.cmd.stopinsert, {
              noremap = true, buffer = args.bufnr
            })
          end
        },
        {
          event = "neo_tree_popup_buffer_enter",
          handler = show_cursor,
        },
      },
    })
  end
}

@pynappo
Copy link
Collaborator Author

pynappo commented Sep 1, 2025

i cloned your config and i can't seem to reproduce

cd .config
gh repo clone erikbloodshed/nvim erik
cd erik
NVIM_APPNAME="erik" nvim

Then:

  • :e lua/plugins/neotree.lua
  • <leader>ef
image

edit: oops i'm dumb i forgot the commit tag is there, i can reproduce it. weirdly the reveal tests passed so prob i forgot some edge case.

@Pencilcaseman
Copy link

Pencilcaseman commented Oct 9, 2025

Hey there -- I think this is still not quite fixed.

Without reveal set, if you:

  1. open Neotree
  2. move the cursor somewhere
  3. close Neotree
  4. reopen Neotree

the cursor appears back at the top of the file explorer, not where you left it.

I tried with 3.35 and it worked just fine, but with 3.35.1 (the release where this PR was merged) I got this behaviour. It's the same on the latest release as well.

If this is the intended behaviour, feel free to ignore this :)

Cheers

Pencilcaseman added a commit to Pencilcaseman/nvim-config that referenced this pull request Oct 9, 2025
@pynappo
Copy link
Collaborator Author

pynappo commented Oct 10, 2025

Hey there -- I think this is still not quite fixed.

[...]

If this is the intended behaviour, feel free to ignore this :)

Cheers

It was not intended behavior. thanks for reporting, should be fixed by the above PR.

@Pencilcaseman
Copy link

Yup sorted! Thanks for getting that fixed so quickly

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

Successfully merging this pull request may close these issues.

BUG: Cursor jumping up and down when moving the cursor

3 participants