From c6ccb370651b05c38eabe63c49120b23f300ba4f Mon Sep 17 00:00:00 2001 From: Tronikel Date: Sat, 31 Aug 2024 10:15:27 +0300 Subject: [PATCH 1/5] feat: add keymaps for floating window --- lua/grapple/settings.lua | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lua/grapple/settings.lua b/lua/grapple/settings.lua index eb44971..3920013 100644 --- a/lua/grapple/settings.lua +++ b/lua/grapple/settings.lua @@ -186,20 +186,22 @@ local DEFAULT_SETTINGS = { local TagActions = require("grapple.tag_actions") local app = Grapple.app() + local mappings = app.settings.win_mappings + -- Select - window:map("n", "", function() + window:map("n", mappings.select, function() local cursor = window:cursor() window:perform_close(TagActions.select, { index = cursor[1] }) end, { desc = "Select" }) -- Select (horizontal split) - window:map("n", "", function() + window:map("n", mappings.select_horizontal, function() local cursor = window:cursor() window:perform_close(TagActions.select, { index = cursor[1], command = vim.cmd.split }) end, { desc = "Select (split)" }) -- Select (vertical split) - window:map("n", "|", function() + window:map("n", mappings.select_vertical, function() local cursor = window:cursor() window:perform_close(TagActions.select, { index = cursor[1], command = vim.cmd.vsplit }) end, { desc = "Select (vsplit)" }) @@ -212,24 +214,24 @@ local DEFAULT_SETTINGS = { end -- Quickfix list - window:map("n", "", function() + window:map("n", mappings.quickfix, function() window:perform_close(TagActions.quickfix) end, { desc = "Quickfix" }) -- Go "up" to scopes - window:map("n", "-", function() + window:map("n", mappings.go_up_scope, function() window:perform_close(TagActions.open_scopes) end, { desc = "Go to scopes" }) -- Rename - window:map("n", "R", function() + window:map("n", mappings.rename, function() local entry = window:current_entry() local path = entry.data.path window:perform_retain(TagActions.rename, { path = path }) end, { desc = "Rename" }) -- Help - window:map("n", "?", function() + window:map("n", mappings.help, function() local WindowActions = require("grapple.window_actions") window:perform_retain(WindowActions.help) end, { desc = "Help" }) @@ -430,6 +432,16 @@ local DEFAULT_SETTINGS = { title_padding = " ", }, + win_mappings = { + select = "", + select_horizontal = "", + select_vertical = "|", + quickfix = "", + go_up_scope = "-", + rename = "R", + help = "?", + }, + ---Values for which a buffer should be excluded from being tagged exclusions = { buftype = { From 8db07adaf364e5b9fb4b766a19d871cfbdbf761d Mon Sep 17 00:00:00 2001 From: Tronikel Date: Sat, 31 Aug 2024 10:39:36 +0300 Subject: [PATCH 2/5] chore: readme update --- README.md | 11 +++++++++++ lua/grapple/settings.lua | 1 + 2 files changed, 12 insertions(+) diff --git a/README.md b/README.md index 14272d9..d8f35b1 100644 --- a/README.md +++ b/README.md @@ -290,6 +290,17 @@ require("grapple").setup({ -- Custom: adds padding around window title title_padding = " ", }, + + --Override default floating window mappings + win_mappings = { + select = "", + select_horizontal = "", + select_vertical = "|", + quickfix = "", + go_up_scope = "-", + rename = "R", + help = "?", + }, }) ``` diff --git a/lua/grapple/settings.lua b/lua/grapple/settings.lua index 3920013..d5b1b34 100644 --- a/lua/grapple/settings.lua +++ b/lua/grapple/settings.lua @@ -432,6 +432,7 @@ local DEFAULT_SETTINGS = { title_padding = " ", }, + --Override default floating window mappings win_mappings = { select = "", select_horizontal = "", From 7780666958248373f2bbe8f0d2fdcafc79c588b1 Mon Sep 17 00:00:00 2001 From: Tronikel Date: Sun, 1 Sep 2024 17:02:50 +0300 Subject: [PATCH 3/5] add more mappings --- README.md | 4 ++++ lua/grapple/settings.lua | 30 +++++++++++++++++++----------- lua/grapple/window.lua | 4 +++- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index d8f35b1..250ad16 100644 --- a/README.md +++ b/README.md @@ -293,6 +293,10 @@ require("grapple").setup({ --Override default floating window mappings win_mappings = { + toggle_hidden = "g.", + unload_scope = "x", + reset_scope = "X", + change_scope = "", select = "", select_horizontal = "", select_vertical = "|", diff --git a/lua/grapple/settings.lua b/lua/grapple/settings.lua index d5b1b34..e6d2c2f 100644 --- a/lua/grapple/settings.lua +++ b/lua/grapple/settings.lua @@ -251,8 +251,10 @@ local DEFAULT_SETTINGS = { local ScopeActions = require("grapple.scope_actions") local app = Grapple.app() + local mappings = app.settings.win_mappings + -- Select - window:map("n", "", function() + window:map("n", mappings.select, function() local entry = window:current_entry() local name = entry.data.name window:perform_close(ScopeActions.open_tags, { name = name }) @@ -273,24 +275,24 @@ local DEFAULT_SETTINGS = { end -- Change - window:map("n", "", function() + window:map("n", mappings.change_scope, function() local entry = window:current_entry() local name = entry.data.name window:perform_close(ScopeActions.change, { name = name }) end, { desc = "Change scope" }) -- Navigate "up" to loaded scopes - window:map("n", "-", function() + window:map("n", mappings.go_up_scope, function() window:perform_close(ScopeActions.open_loaded) end, { desc = "Go to loaded scopes" }) -- Toggle - window:map("n", "g.", function() + window:map("n", mappings.toggle_hidden, function() window:perform_retain(ScopeActions.toggle_all) end, { desc = "Toggle show hidden" }) -- Help - window:map("n", "?", function() + window:map("n", mappings.help, function() local WindowActions = require("grapple.window_actions") window:perform_retain(WindowActions.help) end, { desc = "Help" }) @@ -310,8 +312,10 @@ local DEFAULT_SETTINGS = { local ContainerActions = require("grapple.container_actions") local app = Grapple.app() + local mappings = app.settings.win_mappings + -- Select - window:map("n", "", function() + window:map("n", mappings.select, function() local entry = window:current_entry() local id = entry.data.id window:perform_close(ContainerActions.select, { id = id }) @@ -332,31 +336,31 @@ local DEFAULT_SETTINGS = { end -- Unload - window:map("n", "x", function() + window:map("n", mappings.unload_scope, function() local entry = window:current_entry() local id = entry.data.id window:perform_retain(ContainerActions.unload, { id = id }) end, { desc = "Unload scope" }) -- Reset - window:map("n", "X", function() + window:map("n", mappings.reset_scope, function() local entry = window:current_entry() local id = entry.data.id window:perform_retain(ContainerActions.reset, { id = id }) end, { desc = "Reset scope" }) -- Navigate "up" to scopes - window:map("n", "-", function() + window:map("n", mappings.go_up_scope, function() window:perform_close(ContainerActions.open_scopes) end, { desc = "Go to scopes" }) -- Toggle - window:map("n", "g.", function() + window:map("n", mappings.toggle_hidden, function() window:perform_retain(ContainerActions.toggle_all) end, { desc = "Toggle show unloaded" }) -- Help - window:map("n", "?", function() + window:map("n", mappings.help, function() local WindowActions = require("grapple.window_actions") window:perform_retain(WindowActions.help) end, { desc = "Help" }) @@ -434,6 +438,10 @@ local DEFAULT_SETTINGS = { --Override default floating window mappings win_mappings = { + toggle_hidden = "g.", + unload_scope = "x", + reset_scope = "X", + change_scope = "", select = "", select_horizontal = "", select_vertical = "|", diff --git a/lua/grapple/window.lua b/lua/grapple/window.lua index 51b525f..7ab231e 100644 --- a/lua/grapple/window.lua +++ b/lua/grapple/window.lua @@ -44,6 +44,8 @@ function Window:window_options() ---@diagnostic disable-next-line: assign-type-mismatch local opts = vim.tbl_deep_extend("keep", self.win_opts, {}) + local app = require("grapple").app() + -- Window title if self:has_content() and self.content:title() then opts.title = self.content:title() @@ -64,7 +66,7 @@ function Window:window_options() -- Add "help" footer for nvim-0.10 if vim.fn.has("nvim-0.10") == 1 then - opts.footer = "Press '?' to toggle Help" + opts.footer = string.format("Press '%s' to toggle Help", app.settings.win_mappings.help) opts.footer_pos = "center" end From 34149922c30cbecc30e2d1fad2048f95c092bec3 Mon Sep 17 00:00:00 2001 From: Tronikel Date: Sun, 29 Sep 2024 17:09:15 +0300 Subject: [PATCH 4/5] address comments --- README.md | 30 ++++++++++++++++------- lua/grapple/settings.lua | 52 ++++++++++++++++++++++++---------------- lua/grapple/window.lua | 2 +- 3 files changed, 54 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 190c9d7..0b40075 100644 --- a/README.md +++ b/README.md @@ -291,17 +291,29 @@ require("grapple").setup({ footer_pos = "center", }, - --Override default floating window mappings - win_mappings = { + --Override tag mappings + tag_mappings = { + select_hsplit = "", + select_vsplit = "|", + quickfix = "", + go_to_scopes = "-", + }, + --Override scope mappings + scope_mappings = { + change = "", + go_to_loaded = "-", + }, + --Override loaded (containers) mappings + loaded_mappings = { + unload = "x", + reset = "X", + go_to_scopes = "-", + }, + + --Override default general mappings + mappings = { toggle_hidden = "g.", - unload_scope = "x", - reset_scope = "X", - change_scope = "", select = "", - select_horizontal = "", - select_vertical = "|", - quickfix = "", - go_up_scope = "-", rename = "R", help = "?", }, diff --git a/lua/grapple/settings.lua b/lua/grapple/settings.lua index f259860..29fa83e 100644 --- a/lua/grapple/settings.lua +++ b/lua/grapple/settings.lua @@ -186,7 +186,7 @@ local DEFAULT_SETTINGS = { local TagActions = require("grapple.tag_actions") local app = Grapple.app() - local mappings = app.settings.win_mappings + local mappings = vim.tbl_deep_extend("force", app.settings.mappings, app.settings.tag_mappings) -- Select window:map("n", mappings.select, function() @@ -195,13 +195,13 @@ local DEFAULT_SETTINGS = { end, { desc = "Select" }) -- Select (horizontal split) - window:map("n", mappings.select_horizontal, function() + window:map("n", mappings.select_hsplit, function() local cursor = window:cursor() window:perform_close(TagActions.select, { index = cursor[1], command = vim.cmd.split }) end, { desc = "Select (split)" }) -- Select (vertical split) - window:map("n", mappings.select_vertical, function() + window:map("n", mappings.select_vsplit, function() local cursor = window:cursor() window:perform_close(TagActions.select, { index = cursor[1], command = vim.cmd.vsplit }) end, { desc = "Select (vsplit)" }) @@ -219,7 +219,7 @@ local DEFAULT_SETTINGS = { end, { desc = "Quickfix" }) -- Go "up" to scopes - window:map("n", mappings.go_up_scope, function() + window:map("n", mappings.go_to_scopes, function() window:perform_close(TagActions.open_scopes) end, { desc = "Go to scopes" }) @@ -251,7 +251,7 @@ local DEFAULT_SETTINGS = { local ScopeActions = require("grapple.scope_actions") local app = Grapple.app() - local mappings = app.settings.win_mappings + local mappings = vim.tbl_deep_extend("force", app.settings.mappings, app.settings.scope_mappings) -- Select window:map("n", mappings.select, function() @@ -275,14 +275,14 @@ local DEFAULT_SETTINGS = { end -- Change - window:map("n", mappings.change_scope, function() + window:map("n", mappings.change, function() local entry = window:current_entry() local name = entry.data.name window:perform_close(ScopeActions.change, { name = name }) end, { desc = "Change scope" }) -- Navigate "up" to loaded scopes - window:map("n", mappings.go_up_scope, function() + window:map("n", mappings.go_to_loaded, function() window:perform_close(ScopeActions.open_loaded) end, { desc = "Go to loaded scopes" }) @@ -312,7 +312,7 @@ local DEFAULT_SETTINGS = { local ContainerActions = require("grapple.container_actions") local app = Grapple.app() - local mappings = app.settings.win_mappings + local mappings = vim.tbl_deep_extend("force", app.settings.mappings, app.settings.loaded_mappings) -- Select window:map("n", mappings.select, function() @@ -336,21 +336,21 @@ local DEFAULT_SETTINGS = { end -- Unload - window:map("n", mappings.unload_scope, function() + window:map("n", mappings.unload, function() local entry = window:current_entry() local id = entry.data.id window:perform_retain(ContainerActions.unload, { id = id }) end, { desc = "Unload scope" }) -- Reset - window:map("n", mappings.reset_scope, function() + window:map("n", mappings.reset, function() local entry = window:current_entry() local id = entry.data.id window:perform_retain(ContainerActions.reset, { id = id }) end, { desc = "Reset scope" }) -- Navigate "up" to scopes - window:map("n", mappings.go_up_scope, function() + window:map("n", mappings.go_to_scopes, function() window:perform_close(ContainerActions.open_scopes) end, { desc = "Go to scopes" }) @@ -438,17 +438,29 @@ local DEFAULT_SETTINGS = { footer_pos = "center", }, - --Override default floating window mappings - win_mappings = { + --Override tag mappings + tag_mappings = { + select_hsplit = "", + select_vsplit = "|", + quickfix = "", + go_to_scopes = "-", + }, + --Override scope mappings + scope_mappings = { + change = "", + go_to_loaded = "-", + }, + --Override loaded (containers) mappings + loaded_mappings = { + unload = "x", + reset = "X", + go_to_scopes = "-", + }, + + --Override default general mappings + mappings = { toggle_hidden = "g.", - unload_scope = "x", - reset_scope = "X", - change_scope = "", select = "", - select_horizontal = "", - select_vertical = "|", - quickfix = "", - go_up_scope = "-", rename = "R", help = "?", }, diff --git a/lua/grapple/window.lua b/lua/grapple/window.lua index 63c2a0f..04de9d4 100644 --- a/lua/grapple/window.lua +++ b/lua/grapple/window.lua @@ -60,7 +60,7 @@ function Window:window_options() end if not opts.footer then - opts.footer = string.format("Press '%s' to toggle Help", app.settings.win_mappings.help) + opts.footer = string.format("Press '%s' to toggle Help", app.settings.mappings.help) end -- Remove custom fields From e1b08075f0480546b377ad5b81f3a846b3fa717f Mon Sep 17 00:00:00 2001 From: Tronikel Date: Sun, 29 Sep 2024 21:52:24 +0300 Subject: [PATCH 5/5] hsplit -> split --- README.md | 2 +- lua/grapple/settings.lua | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0b40075..e81d29f 100644 --- a/README.md +++ b/README.md @@ -293,7 +293,7 @@ require("grapple").setup({ --Override tag mappings tag_mappings = { - select_hsplit = "", + select_split = "", select_vsplit = "|", quickfix = "", go_to_scopes = "-", diff --git a/lua/grapple/settings.lua b/lua/grapple/settings.lua index 29fa83e..57f93be 100644 --- a/lua/grapple/settings.lua +++ b/lua/grapple/settings.lua @@ -195,7 +195,7 @@ local DEFAULT_SETTINGS = { end, { desc = "Select" }) -- Select (horizontal split) - window:map("n", mappings.select_hsplit, function() + window:map("n", mappings.select_split, function() local cursor = window:cursor() window:perform_close(TagActions.select, { index = cursor[1], command = vim.cmd.split }) end, { desc = "Select (split)" }) @@ -440,7 +440,7 @@ local DEFAULT_SETTINGS = { --Override tag mappings tag_mappings = { - select_hsplit = "", + select_split = "", select_vsplit = "|", quickfix = "", go_to_scopes = "-",