mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-14 10:00:29 +00:00
feat: select with nil
This commit is contained in:
parent
245875a29f
commit
c131b4b61b
@ -12,21 +12,17 @@ M.DEFAULT_LIST = DEFAULT_LIST
|
|||||||
---@alias HarpoonListFileOptions {split: boolean, vsplit: boolean}
|
---@alias HarpoonListFileOptions {split: boolean, vsplit: boolean}
|
||||||
|
|
||||||
---@class HarpoonPartialConfigItem
|
---@class HarpoonPartialConfigItem
|
||||||
|
---@field select_with_nil? boolean defaults to false
|
||||||
---@field encode? (fun(list_item: HarpoonListItem): string)
|
---@field encode? (fun(list_item: HarpoonListItem): string)
|
||||||
---@field decode? (fun(obj: string): any)
|
---@field decode? (fun(obj: string): any)
|
||||||
---@field display? (fun(list_item: HarpoonListItem): string)
|
---@field display? (fun(list_item: HarpoonListItem): string)
|
||||||
---@field select? (fun(list_item: HarpoonListItem, options: any?): nil)
|
---@field select? (fun(list_item?: HarpoonListItem, options: any?): nil)
|
||||||
---@field equals? (fun(list_line_a: HarpoonListItem, list_line_b: HarpoonListItem): boolean)
|
---@field equals? (fun(list_line_a: HarpoonListItem, list_line_b: HarpoonListItem): boolean)
|
||||||
---@field add? fun(config: HarpoonPartialConfigItem, item: any?): HarpoonListItem
|
---@field add? fun(config: HarpoonPartialConfigItem, item: any?): HarpoonListItem
|
||||||
---@field BufLeave? fun(evt: any, list: HarpoonList): nil
|
---@field BufLeave? fun(evt: any, list: HarpoonList): nil
|
||||||
---@field VimLeavePre? fun(evt: any, list: HarpoonList): nil
|
---@field VimLeavePre? fun(evt: any, list: HarpoonList): nil
|
||||||
---@field get_root_dir? fun(): string
|
---@field get_root_dir? fun(): string
|
||||||
|
|
||||||
---@class HarpoonWindowSettings
|
|
||||||
---@field width number
|
|
||||||
---@field height number
|
|
||||||
|
|
||||||
---notehunthoeunthoeunthoeunthoeunthoeunth
|
|
||||||
---@class HarpoonSettings
|
---@class HarpoonSettings
|
||||||
---@field save_on_toggle boolean defaults to true
|
---@field save_on_toggle boolean defaults to true
|
||||||
---@field key (fun(): string)
|
---@field key (fun(): string)
|
||||||
@ -62,6 +58,9 @@ function M.get_default_config()
|
|||||||
},
|
},
|
||||||
|
|
||||||
default = {
|
default = {
|
||||||
|
--- select_with_nill allows for a list to call select even if the provided item is nil
|
||||||
|
select_with_nil = false,
|
||||||
|
|
||||||
---@param obj HarpoonListItem
|
---@param obj HarpoonListItem
|
||||||
---@return string
|
---@return string
|
||||||
encode = function(obj)
|
encode = function(obj)
|
||||||
@ -79,7 +78,8 @@ function M.get_default_config()
|
|||||||
return list_item.value
|
return list_item.value
|
||||||
end,
|
end,
|
||||||
|
|
||||||
---@param list_item HarpoonListFileItem
|
--- the select function is called when a user selects an item from the corresponding list and can be nil if select_with_nil is true
|
||||||
|
---@param list_item? HarpoonListFileItem
|
||||||
---@param options HarpoonListFileOptions
|
---@param options HarpoonListFileOptions
|
||||||
select = function(list_item, options)
|
select = function(list_item, options)
|
||||||
options = options or {}
|
options = options or {}
|
||||||
|
@ -155,7 +155,7 @@ end
|
|||||||
|
|
||||||
function HarpoonList:select(index, options)
|
function HarpoonList:select(index, options)
|
||||||
local item = self.items[index]
|
local item = self.items[index]
|
||||||
if item then
|
if item or self.config.select_with_nil then
|
||||||
Listeners.listeners:emit(
|
Listeners.listeners:emit(
|
||||||
Listeners.event_names.SELECT,
|
Listeners.event_names.SELECT,
|
||||||
{ list = self, item = item, idx = index }
|
{ list = self, item = item, idx = index }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user