Skip to content

feat(panel): improvements to multi-selection#46

Merged
dlyongemallo merged 3 commits intomainfrom
persist_file_marking
Mar 18, 2026
Merged

feat(panel): improvements to multi-selection#46
dlyongemallo merged 3 commits intomainfrom
persist_file_marking

Conversation

@dlyongemallo
Copy link
Copy Markdown
Owner

@dlyongemallo dlyongemallo commented Mar 17, 2026

Allow selection marks to be customised. Remaps default keys: space to toggle selection, C to clear all.

Optionally saves selections to a JSON file scoped by repo toplevel and rev args (defaults to stdpath("data")/diffview_selections.json).

Relates to sindrets#582.

Copilot AI review requested due to automatic review settings March 17, 2026 05:27
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds persistence for Diffview file-panel selections across Neovim restarts by saving/restoring selections from a JSON store, along with configuration and an emitted User autocmd.

Changes:

  • Introduces diffview.selection_store to load/save selections keyed by repo toplevel + revision args.
  • Wires the diff file panel to notify on selection changes and (when enabled) debounce persistence + emit DiffviewSelectionChanged.
  • Adds persist_selections defaults/config docs and functional tests for the selection store + selection-change notifications.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
lua/diffview/selection_store.lua New JSON-backed selection store with scope keys and save/load.
lua/diffview/scene/views/diff/file_panel.lua Adds selection-change callback hook and triggers it from selection-mutating methods.
lua/diffview/scene/views/diff/diff_view.lua Initializes persistence (load + debounced save) and emits selection_changed event.
lua/diffview/init.lua Converts selection_changed emitter event into User autocmd DiffviewSelectionChanged.
lua/diffview/config.lua Adds persist_selections = { enabled = true, path = nil } default config.
doc/diffview_defaults.txt Documents new default config entry.
doc/diffview.txt Adds config help for persist_selections and documents DiffviewSelectionChanged.
lua/diffview/tests/functional/selection_store_spec.lua Adds functional tests for store round-trips and selection-change notifications.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lua/diffview/selection_store.lua Outdated
Comment thread lua/diffview/selection_store.lua
Comment thread lua/diffview/scene/views/diff/diff_view.lua Outdated
Comment thread lua/diffview/scene/views/diff/file_panel.lua
@jakubbortlik
Copy link
Copy Markdown

Hi @dlyongemallo, I really appreciate your work on diffview.nvim! It's an amazing plugin and I'm very grateful that you've implemented so many new features and fixes.

With regard to the marking feature, I have a couple of comments that you might consider:

Placing the mark (or a space) just in front of the file name changes the alignment and makes it more difficult to see which directory a file belongs to. Compare this image from original Diffview:
image

And this image from your fork:
image

The marks for directories are inserted only when necessary, so marking a directory leads to shifting the directory name to the right. I find this a little distracting. Maybe both issues (file alignment and directory shifting) could be solved by placing the selection marks to the very left of the lines (i.e., to the left of the modification types, something like this:
image

Then the whole tree could be shifted if any file was marked.

Also, maybe the mark characters could be customizable, I'd actually like to make them a little more prominent and maybe use something like ⬜ and ✅.

Optionally saves selections to a JSON file scoped by repo toplevel and rev
args (defaults to `stdpath("data")/diffview_selections.json`).

Adds new config: `persist_selections = { enabled = false, path = nil }`.
Adds new User autocmd: `DiffviewSelectionChanged`.
@dlyongemallo dlyongemallo force-pushed the persist_file_marking branch from db6276c to 027e260 Compare March 18, 2026 13:17
@dlyongemallo dlyongemallo changed the title feat(panel): persist file selections across Neovim restarts feat(panel): improvements to multi-selection Mar 18, 2026
@dlyongemallo
Copy link
Copy Markdown
Owner Author

@jakubbortlik I've made the selection marks customisable but the problem with your suggested characters is that they don't render consistently across terminals. In particular, they render with different widths depending on the environment.

You can try the following and see how they appear for you:

  require("diffview").setup({
    signs = {
      selected_file = "",
      unselected_file = "",
      selected_dir = "",
      partially_selected_dir = "🔳",
      unselected_dir = "",
    },
    file_panel = {
      always_show_marks = true,
    },
  })

@dlyongemallo dlyongemallo merged commit f245042 into main Mar 18, 2026
2 checks passed
@dlyongemallo dlyongemallo deleted the persist_file_marking branch March 18, 2026 13:29
@jakubbortlik
Copy link
Copy Markdown

@dlyongemallo, thanks for implementing this! This is a very useful feature. I'm aware that the unicode characters I've mentioned are problematic and the customization in the settings is ideal for me.

I still think placing the marks to the very left would make the tree more clean, but I guess I will get used to the current state.

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.

3 participants