Skip to content

Commit

Permalink
feat: support custom keybinding for diff view
Browse files Browse the repository at this point in the history
Also adds documentation to README.md
  • Loading branch information
TimUntersberger committed Apr 17, 2021
1 parent ebbf1d6 commit 342e5ae
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
32 changes: 27 additions & 5 deletions README.md
Expand Up @@ -62,7 +62,7 @@ The create function takes 1 optional argument that can be one of the following v
* floating (This currently doesn't work with popups)
* split

## Status Keybindings
## Default Status Keybindings

| Keybinding | Function |
|--------------|--------------------------------------------------|
Expand All @@ -85,6 +85,15 @@ The create function takes 1 optional argument that can be one of the following v
| \<enter> | Go to file |
| \<C-r> | Refresh Buffer |

## Default Diff View Keybindings

| Keybinding | Function |
|--------------|--------------------------------------------------|
| q | Close |
| <c-s> | Save |
| ]f | Next file |
| [f | Prev file |

## Configuration

You can configure neogit by running the `neogit.setup` function.
Expand Down Expand Up @@ -112,14 +121,14 @@ neogit.setup {
["B"] = "BranchPopup",
-- Removes the default mapping of "s"
["s"] = "",
}
},
diff_view = {}
}
}
```

Right now only the status buffer supports custom mappings. The other popups will follow shortly.

List of status commands:
<details>
<summary>Status Commands</summary>

* Close
* Depth1 (Set foldlevel to 1)
Expand All @@ -143,6 +152,19 @@ List of status commands:
* LogPopup
* StashPopup
* BranchPopup
</details>

<details>
<summary>Diff View Commands</summary>

* Close
* Save
* NextFile
* CloseFile
* Noop (Override mapping but don't do anything)

</details>


## Notification Highlighting

Expand Down
6 changes: 6 additions & 0 deletions lua/neogit/config.lua
Expand Up @@ -37,6 +37,12 @@ M.values = {
["L"] = "LogPopup",
["Z"] = "StashPopup",
["b"] = "BranchPopup",
},
diff_view = {
["q"] = "Close",
["<c-s>"] = "Save",
["]f"] = "NextFile",
["[f"] = "PrevFile",
}
}
}
Expand Down
24 changes: 15 additions & 9 deletions lua/neogit/diff.lua
@@ -1,4 +1,5 @@
local M = {}
local config = require 'neogit.config'
local a = require 'plenary.async_lib'
local await, void, async, scheduler = a.await, a.void, a.async, a.scheduler
local MappingsManager = require("neogit.lib.mappings_manager")
Expand Down Expand Up @@ -249,12 +250,16 @@ function M.open(opts)
end
end

local cmd_cb_map = {
["NextFile"] = M.next_file,
["PrevFile"] = M.prev_file,
["Save"] = M.save_lhs,
["Close"] = M.close,
["Noop"] = M.close,
}

M.mappings = {
lhs = {
["q"] = M.close,
["<c-s>"] = M.save_lhs,
["]f"] = M.next_file,
["[f"] = M.prev_file,
["<c-w>l"] = M.focus_rhs,
["<c-w><c-l>"] = M.focus_rhs,
["<c-w>k"] = M.noop,
Expand All @@ -265,7 +270,6 @@ M.mappings = {
["<c-w><c-h>"] = M.noop,
},
rhs = {
["q"] = M.close,
["<c-w>h"] = M.focus_lhs,
["<c-w><c-h>"] = M.focus_lhs,
["<c-w>l"] = M.noop,
Expand All @@ -277,10 +281,12 @@ M.mappings = {
},
}

for key, val in pairs(config.values.mappings.diff_view) do
local cb = cmd_cb_map[val]
M.mappings.lhs[key] = cb
M.mappings.rhs[key] = cb
end

D = M

return M




0 comments on commit 342e5ae

Please sign in to comment.