From 342e5ae937e5c2e93127fa875b140ace342bd482 Mon Sep 17 00:00:00 2001 From: TimUntersberger Date: Sat, 17 Apr 2021 11:39:56 +0200 Subject: [PATCH] feat: support custom keybinding for diff view Also adds documentation to README.md --- README.md | 32 +++++++++++++++++++++++++++----- lua/neogit/config.lua | 6 ++++++ lua/neogit/diff.lua | 24 +++++++++++++++--------- 3 files changed, 48 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 1859c43f3..34a98d855 100644 --- a/README.md +++ b/README.md @@ -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 | |--------------|--------------------------------------------------| @@ -85,6 +85,15 @@ The create function takes 1 optional argument that can be one of the following v | \ | Go to file | | \ | Refresh Buffer | +## Default Diff View Keybindings + +| Keybinding | Function | +|--------------|--------------------------------------------------| +| q | Close | +| | Save | +| ]f | Next file | +| [f | Prev file | + ## Configuration You can configure neogit by running the `neogit.setup` function. @@ -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: +
+Status Commands * Close * Depth1 (Set foldlevel to 1) @@ -143,6 +152,19 @@ List of status commands: * LogPopup * StashPopup * BranchPopup +
+ +
+Diff View Commands + +* Close +* Save +* NextFile +* CloseFile +* Noop (Override mapping but don't do anything) + +
+ ## Notification Highlighting diff --git a/lua/neogit/config.lua b/lua/neogit/config.lua index 4b7189850..96c0cf3d6 100644 --- a/lua/neogit/config.lua +++ b/lua/neogit/config.lua @@ -37,6 +37,12 @@ M.values = { ["L"] = "LogPopup", ["Z"] = "StashPopup", ["b"] = "BranchPopup", + }, + diff_view = { + ["q"] = "Close", + [""] = "Save", + ["]f"] = "NextFile", + ["[f"] = "PrevFile", } } } diff --git a/lua/neogit/diff.lua b/lua/neogit/diff.lua index 1b1b93691..ca298e3fe 100644 --- a/lua/neogit/diff.lua +++ b/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") @@ -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, - [""] = M.save_lhs, - ["]f"] = M.next_file, - ["[f"] = M.prev_file, ["l"] = M.focus_rhs, [""] = M.focus_rhs, ["k"] = M.noop, @@ -265,7 +270,6 @@ M.mappings = { [""] = M.noop, }, rhs = { - ["q"] = M.close, ["h"] = M.focus_lhs, [""] = M.focus_lhs, ["l"] = M.noop, @@ -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 - - - -