Skip to content

Commit

Permalink
feat: configure default command (#127)
Browse files Browse the repository at this point in the history
* feat: make default tag select command configurable

* docs: update settings section in readme to reflect new command option
  • Loading branch information
cbochs authored Mar 18, 2024
1 parent dabc3b1 commit 7a0a727
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,14 @@ require("grapple").setup({
style = "relative",

---A string of characters used for quick selecting in Grapple windows
---An empty string or nil will disable quick select
---An empty string or false will disable quick select
---@type string | nil
quick_select = "123456789",

---Default command to use when selecting a tag
---@type fun(path: string)
command = vim.cmd.edit,

---User-defined tags title function for Grapple windows
---By default, uses the resolved scope's ID
---@type fun(scope: grapple.resolved_scope): string?
Expand Down
2 changes: 1 addition & 1 deletion lua/grapple.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ end
---@field index? integer
---@field cursor? integer[]
---@field scope? string
---@field command? fun(path: string) undocumented
---@field command? fun(path: string)

---Extract a valid path from the provided path or buffer options.
---@param opts grapple.options
Expand Down
6 changes: 5 additions & 1 deletion lua/grapple/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ local DEFAULT_SETTINGS = {
style = "relative",

---A string of characters used for quick selecting in Grapple windows
---An empty string will disable quick select
---An empty string or false will disable quick select
---@type string
quick_select = "123456789",

---Default command to use when selecting a tag
---@type fun(path: string)
command = vim.cmd.edit,

---@class grapple.scope_definition
---@field name string
---@field force? boolean
Expand Down
5 changes: 4 additions & 1 deletion lua/grapple/tag.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ end

---@param command? fun(path: string)
function Tag:select(command)
local App = require("grapple.app")
local app = App.get()

local short_path = Path.fs_short(self.path)

command = command or vim.cmd.edit
command = command or app.settings.command
command(short_path)

if self.cursor then
Expand Down
18 changes: 13 additions & 5 deletions tests/grapple/settings_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,30 @@ describe("Settings", function()
end)

it("has the correct scope default", function()
local settings = Settings:new()
assert.same("git", settings.scope)
assert.same("git", Settings:new().scope)
end)

it("has the correct command default", function()
assert.same(vim.cmd.edit, Settings:new().command)
end)
end)

describe(".quick_select", function()
it("has the correct quick_select default", function()
local settings = Settings:new()
assert.same({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, settings:quick_select())
assert.same({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, Settings:new():quick_select())
end)

it("can be set to nothing", function()
it("can be set to an empty string to disable quick select", function()
local settings = Settings:new()
settings:update({ quick_select = "" })
assert.same({}, settings:quick_select())
end)

it("can be set to false to disable quick select", function()
local settings = Settings:new()
settings:update({ quick_select = false })
assert.same({}, settings:quick_select())
end)
end)

describe(".scopes", function()
Expand Down

0 comments on commit 7a0a727

Please sign in to comment.