feat(picker): allow custom function actions.open_file.window_picker.picker (#1782)

* feat: allow passing a custom function as a window picker

WIP

* fix: move logic expression to if statement

If `M.window_picker.custom_function()` returns `nil` then `pick_win_id()`
will run (the or part). We don't want that. More verbose, but better.

* feat(open): add window_picker.picker

* feat(open): add window_picker.picker

* style nit

* feat(open): add window_picker.picker

* docs: add window_picker.picker documentation

* docs: add window_picker.picker documentation

Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
David Sierra DiazGranados
2022-12-15 23:14:33 -05:00
committed by GitHub
parent 18272f8df3
commit d85b6718ce
3 changed files with 18 additions and 1 deletions

View File

@@ -640,6 +640,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
resize_window = true,
window_picker = {
enable = true,
picker = "default",
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
exclude = {
filetype = { "notify", "packer", "qf", "diff", "fugitive", "fugitiveblame" },
@@ -699,6 +700,7 @@ local FIELD_OVERRIDE_TYPECHECK = {
on_attach = { ["function"] = true, string = true },
sort_by = { ["function"] = true, string = true },
root_folder_label = { ["function"] = true, string = true },
picker = { ["function"] = true, string = true },
}
local function validate_options(conf)

View File

@@ -175,7 +175,11 @@ local function get_target_winid(mode, win_ids)
end
else
-- pick a window
target_winid = pick_win_id()
if type(M.window_picker.picker) == "function" then
target_winid = M.window_picker.picker()
else
target_winid = pick_win_id()
end
if target_winid == nil then
-- pick failed/cancelled
return