fugitive: preserve existing buffer-local integration maps #123

Closed
opened 2026-09-21 18:12:22 +00:00 by barrettruth · 0 comments
Owner

Original issue: barrettruth/diffs.nvim#274
Original author: barrettruth
Original date: 2026-05-09T19:21:40Z

Parent tracker: #270

Problem

diffs.nvim Fugitive integration maps are configured maps installed in a third-party buffer, so they must not clobber pre-existing buffer-local mappings.

This is the same ownership principle already applied to conflict/merge configured maps:

  • generated diffs:// buffers are plugin-owned and may have default maps;
  • real source buffers and third-party plugin buffers are user/integration-owned;
  • configured buffer maps in those buffers must be buffer-local, opt-in/configured, and ownership-aware.

Issue #257 fixed this class for conflict/merge maps through lua/diffs/keymaps.lua, but Fugitive integration still uses direct vim.keymap.set().

Relevant existing code

  • lua/diffs/fugitive.lua
    • setup_keymaps(bufnr, config) directly installs config.horizontal and config.vertical with vim.keymap.set().
    • Defaults come from vim.g.diffs.integrations.fugitive = true as du and dU.
  • lua/diffs/config.lua
    • normalize_integrations() maps fugitive = true to { horizontal = "du", vertical = "dU" }.
  • plugin/diffs.lua
    • on FileType fugitive, calls runtime.attach(args.buf) and then require("diffs.fugitive").setup_keymaps(args.buf, fugitive_config).
  • lua/diffs/keymaps.lua
    • already tracks buffer-local keymap ownership for configured conflict/merge maps.
    • It skips pre-existing non-diffs mappings and removes only mappings it still owns.

Desired behavior

  • If a Fugitive status buffer already has a buffer-local du or dU, diffs.nvim must not replace it.
  • If diffs.nvim installed du/dU, cleanup must not delete a mapping if another plugin/user replaces it later.
  • horizontal = false or vertical = false must still disable that map.
  • Empty strings should behave as disabled, matching current behavior.
  • Existing defaults remain unchanged when no conflict exists: du horizontal, dU vertical.

Implementation guidance

Reuse lua/diffs/keymaps.lua if possible.

If it needs extension:

  • keep the helper generic enough for configured buffer maps;
  • do not regress conflict/merge behavior;
  • preserve callback-map support and <Plug>(...) rhs support.

Consider adding a small Fugitive-specific registry so repeated FileType/attach calls do not duplicate ownership state.

Acceptance criteria

  • Fugitive integration maps are ownership-aware.
  • No configured integration map clobbers user or Fugitive buffer-local mappings.
  • Conflict/merge keymap ownership behavior remains unchanged.
> Original issue: barrettruth/diffs.nvim#274 > Original author: `barrettruth` > Original date: 2026-05-09T19:21:40Z Parent tracker: #270 ## Problem `diffs.nvim` Fugitive integration maps are configured maps installed in a third-party buffer, so they must not clobber pre-existing buffer-local mappings. This is the same ownership principle already applied to conflict/merge configured maps: - generated `diffs://` buffers are plugin-owned and may have default maps; - real source buffers and third-party plugin buffers are user/integration-owned; - configured buffer maps in those buffers must be buffer-local, opt-in/configured, and ownership-aware. Issue #257 fixed this class for conflict/merge maps through `lua/diffs/keymaps.lua`, but Fugitive integration still uses direct `vim.keymap.set()`. ## Relevant existing code - `lua/diffs/fugitive.lua` - `setup_keymaps(bufnr, config)` directly installs `config.horizontal` and `config.vertical` with `vim.keymap.set()`. - Defaults come from `vim.g.diffs.integrations.fugitive = true` as `du` and `dU`. - `lua/diffs/config.lua` - `normalize_integrations()` maps `fugitive = true` to `{ horizontal = "du", vertical = "dU" }`. - `plugin/diffs.lua` - on `FileType fugitive`, calls `runtime.attach(args.buf)` and then `require("diffs.fugitive").setup_keymaps(args.buf, fugitive_config)`. - `lua/diffs/keymaps.lua` - already tracks buffer-local keymap ownership for configured conflict/merge maps. - It skips pre-existing non-diffs mappings and removes only mappings it still owns. ## Desired behavior - If a Fugitive status buffer already has a buffer-local `du` or `dU`, diffs.nvim must not replace it. - If diffs.nvim installed `du`/`dU`, cleanup must not delete a mapping if another plugin/user replaces it later. - `horizontal = false` or `vertical = false` must still disable that map. - Empty strings should behave as disabled, matching current behavior. - Existing defaults remain unchanged when no conflict exists: `du` horizontal, `dU` vertical. ## Implementation guidance Reuse `lua/diffs/keymaps.lua` if possible. If it needs extension: - keep the helper generic enough for configured buffer maps; - do not regress conflict/merge behavior; - preserve callback-map support and `<Plug>(...)` rhs support. Consider adding a small Fugitive-specific registry so repeated `FileType`/attach calls do not duplicate ownership state. ## Acceptance criteria - Fugitive integration maps are ownership-aware. - No configured integration map clobbers user or Fugitive buffer-local mappings. - Conflict/merge keymap ownership behavior remains unchanged.
barrettruth 2026-09-21 18:12:22 +00:00
  • closed this issue
  • added the
    bug
    label
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
barrettruth/diffs.nvim#123
No description provided.