Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add keymaps for floating window #174

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,21 @@ require("grapple").setup({
-- Custom: adds padding around window title
title_padding = " ",
},

--Override default floating window mappings
win_mappings = {
Tronikelis marked this conversation as resolved.
Show resolved Hide resolved
Tronikelis marked this conversation as resolved.
Show resolved Hide resolved
toggle_hidden = "g.",
Copy link
Owner

Choose a reason for hiding this comment

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

Some action name change suggestions:

  • unload_scope -> unload and put in the loaded_mappings table
  • reset_scope -> reset and put in the loaded_mappings table
  • change_scope -> change and put in the scope_mappings table
  • select_horizontal -> select_split and put in the tag_mappings table
  • select_vertical -> select_vsplit and put in the tag_mappings table

Copy link
Author

Choose a reason for hiding this comment

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

thanks for the insights, I'll change it

Copy link
Author

@Tronikelis Tronikelis Sep 29, 2024

Choose a reason for hiding this comment

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

did you list all the renames here? Or is something left

unload_scope = "x",
reset_scope = "X",
change_scope = "<s-cr>",
select = "<cr>",
select_horizontal = "<c-s>",
select_vertical = "|",
quickfix = "<c-q>",
go_up_scope = "-",
rename = "R",
help = "?",
},
})
```

Expand Down
57 changes: 39 additions & 18 deletions lua/grapple/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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", "<cr>", 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", "<c-s>", 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)" })
Expand All @@ -212,24 +214,24 @@ local DEFAULT_SETTINGS = {
end

-- Quickfix list
window:map("n", "<c-q>", 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" })
Expand All @@ -249,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", "<cr>", 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 })
Expand All @@ -271,24 +275,24 @@ local DEFAULT_SETTINGS = {
end

-- Change
window:map("n", "<s-cr>", 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" })
Expand All @@ -308,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", "<cr>", function()
window:map("n", mappings.select, function()
local entry = window:current_entry()
local id = entry.data.id
window:perform_close(ContainerActions.select, { id = id })
Expand All @@ -330,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" })
Expand Down Expand Up @@ -430,6 +436,21 @@ local DEFAULT_SETTINGS = {
title_padding = " ",
},

--Override default floating window mappings
Tronikelis marked this conversation as resolved.
Show resolved Hide resolved
win_mappings = {
toggle_hidden = "g.",
unload_scope = "x",
reset_scope = "X",
change_scope = "<s-cr>",
select = "<cr>",
select_horizontal = "<c-s>",
select_vertical = "|",
quickfix = "<c-q>",
go_up_scope = "-",
rename = "R",
help = "?",
},

---Values for which a buffer should be excluded from being tagged
exclusions = {
buftype = {
Expand Down
4 changes: 3 additions & 1 deletion lua/grapple/window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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

Expand Down