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

Diffviewer changes focus to first file after save #1448

Open
radmen opened this issue Aug 15, 2024 · 2 comments
Open

Diffviewer changes focus to first file after save #1448

radmen opened this issue Aug 15, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@radmen
Copy link

radmen commented Aug 15, 2024

Description

In diffview, after staging chunk of changes, the focus goes back to the first file in the navigator. This becomes a problem when diffing multiple files and auto-save plugin is enabled.

What happens is that I constantly need to find the last staged file, and move to the next one. It is quite an issue when trying to stage many different files.

Kooha-2024-08-15-09-38-57.mp4

Neovim version

NVIM v0.10.1
Build type: Release
LuaJIT 2.1.1720049189
Run "nvim -V1 -v" for more info

Operating system and version

Fedora Bluefin

Steps to reproduce

  1. Prepare repo:
    mkdir /tmp/repro
    cd /tmp/repro
    echo "README\n" > README.md
    echo "UPDATING\n" > UPDATING.md
    echo "TEST\n" > TEST.md
    git add .
    git commit -m "Add files"
  2. Make some changes:
    echo "Hello There" >> README.md
    echo "Hello There" >> UPDATING.md
    echo "Hello There" >> TEST.md
  3. nvim -u minimal.lua
  4. :Neogit<CR>
  5. d u (open diff for unstaged files)
  6. Stage changes for the first file
  7. Stage changes for the second file

Expected behavior

Focus should remain on the just-staged file.

Actual behavior

Focus moves to the first file in tree.

Minimal config

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

require("lazy.minit").repro({
  spec = {
    -- add any other plugins here
    {
      "NeogitOrg/neogit",
      dependencies = {
        "nvim-lua/plenary.nvim",         -- required
        "sindrets/diffview.nvim",        -- optional - Diff integration

        -- Only one of these is needed, not both.
        "nvim-telescope/telescope.nvim", -- optional
        "ibhagwan/fzf-lua",              -- optional
      },
      config = true
    },
  },
})
@radmen radmen added the bug Something isn't working label Aug 15, 2024
@CKolkey
Copy link
Member

CKolkey commented Aug 16, 2024

I'd recommend just staging from Neogit, not diffview. Upon returning to the neogit buffer, it refreshes, and tries to save/restore the cursor position, but it'll fail to restore in this case and default to the first item.

You can stage individual hunks, or lines, from neogit itself, so diffview isn't really needed for that at all.

@radmen
Copy link
Author

radmen commented Aug 16, 2024

The default staging method is good only if you stage smaller blocks. For larger ones, the side-by-side diff offered by diffview is more convenient.

Since diffview is part of Neogit (although optional, I get it), I assume it should just work. Now, the overall UX is clunky.

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