From 183587de8899a8a61edd974ade9c4df73e6b6a49 Mon Sep 17 00:00:00 2001 From: bekaboo <18127878294@qq.com> Date: Tue, 14 Nov 2023 12:10:03 +0800 Subject: [PATCH] feat(configs): add default keymap `q` to close current menu --- README.md | 117 ++++++++++++++++++++++------------------ doc/dropbar.txt | 15 +++++- lua/dropbar/configs.lua | 6 +++ 3 files changed, 85 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index b4cca790..25aa2fd3 100644 --- a/README.md +++ b/README.md @@ -211,7 +211,6 @@ https://github.com/Bekaboo/dropbar.nvim/assets/76579810/e8c1ac26-0321-4762-9975- - Fuzzy finder - Use `dropbar_menu_t:fuzzy_find_open()` to interactively filter, select and preview entries using fzf - - `i`: enter fzf mode from the menu - ``: exit fzf mode - `/`: move the cursor in fzf mode - ``: call the on_click callback of the symbol under the cursor @@ -220,6 +219,8 @@ https://github.com/Bekaboo/dropbar.nvim/assets/76579810/e8c1ac26-0321-4762-9975- click - ``: find the first clickable symbol in the current drop-down menu entry and call its `on_click` callback + - `i`: enter fzf mode from the menu + - `q`: close current menu - To disable, remap or add new keymaps in the drop-down menu, see [menu options](#menu) @@ -443,56 +444,62 @@ https://github.com/Bekaboo/dropbar.nvim/assets/76579810/e8c1ac26-0321-4762-9975- }, }, ---@type table> - keymaps = { - [''] = function() - local menu = utils.menu.get_current() - if not menu then - return - end - local mouse = vim.fn.getmousepos() - local clicked_menu = utils.menu.get({ win = mouse.winid }) - -- If clicked on a menu, invoke the corresponding click action, - -- else close all menus and set the cursor to the clicked window - if clicked_menu then - clicked_menu:click_at({ mouse.line, mouse.column - 1 }, nil, 1, 'l') - return - end - utils.menu.exec('close') - utils.bar.exec('update_current_context_hl') - if vim.api.nvim_win_is_valid(mouse.winid) then - vim.api.nvim_set_current_win(mouse.winid) - end - end, - [''] = function() - local menu = utils.menu.get_current() - if not menu then - return - end - local cursor = vim.api.nvim_win_get_cursor(menu.win) - local component = menu.entries[cursor[1]]:first_clickable(cursor[2]) - if component then - menu:click_on(component, nil, 1, 'l') - end - end, - [''] = function() - local menu = utils.menu.get_current() - if not menu then - return - end - local mouse = vim.fn.getmousepos() - utils.menu.update_hover_hl(mouse) - if M.opts.menu.preview then - utils.menu.update_preview(mouse) - end - end, - ['i'] = function() - local menu = utils.menu.get_current() - if not menu then - return - end - menu:fuzzy_find_open() - end, - }, + keymaps = { + [''] = function() + local menu = utils.menu.get_current() + if not menu then + return + end + local mouse = vim.fn.getmousepos() + local clicked_menu = utils.menu.get({ win = mouse.winid }) + -- If clicked on a menu, invoke the corresponding click action, + -- else close all menus and set the cursor to the clicked window + if clicked_menu then + clicked_menu:click_at({ mouse.line, mouse.column - 1 }, nil, 1, 'l') + return + end + utils.menu.exec('close') + utils.bar.exec('update_current_context_hl') + if vim.api.nvim_win_is_valid(mouse.winid) then + vim.api.nvim_set_current_win(mouse.winid) + end + end, + [''] = function() + local menu = utils.menu.get_current() + if not menu then + return + end + local cursor = vim.api.nvim_win_get_cursor(menu.win) + local component = menu.entries[cursor[1]]:first_clickable(cursor[2]) + if component then + menu:click_on(component, nil, 1, 'l') + end + end, + [''] = function() + local menu = utils.menu.get_current() + if not menu then + return + end + local mouse = vim.fn.getmousepos() + utils.menu.update_hover_hl(mouse) + if M.opts.menu.preview then + utils.menu.update_preview(mouse) + end + end, + ['i'] = function() + local menu = utils.menu.get_current() + if not menu then + return + end + menu:fuzzy_find_open() + end, + ['q'] = function() + local menu = utils.menu.get_current() + if menu then + menu:close() + end + end + }, ---@alias dropbar_menu_win_config_opts_t any|fun(menu: dropbar_menu_t):any ---@type table ---@see vim.api.nvim_open_win @@ -1100,7 +1107,13 @@ menu: end menu:fuzzy_find_open() end, - } + ['q'] = function() + local menu = utils.menu.get_current() + if menu then + menu:close() + end + end + }, ``` - `opts.menu.win_configs`: `table` - Window configurations for the menu, see `:h nvim_open_win()` diff --git a/doc/dropbar.txt b/doc/dropbar.txt index 78125868..5cca0b28 100644 --- a/doc/dropbar.txt +++ b/doc/dropbar.txt @@ -526,7 +526,20 @@ the menu: utils.menu.update_preview(mouse) end end, - } + ['i'] = function() + local menu = utils.menu.get_current() + if not menu then + return + end + menu:fuzzy_find_open() + end, + ['q'] = function() + local menu = utils.menu.get_current() + if menu then + menu:close() + end + end + }, < - `opts.menu.win_configs`: `table` - Window configurations for the menu, see `:h nvim_open_win()` diff --git a/lua/dropbar/configs.lua b/lua/dropbar/configs.lua index 86f1b3e8..fa7e2526 100644 --- a/lua/dropbar/configs.lua +++ b/lua/dropbar/configs.lua @@ -259,6 +259,12 @@ M.opts = { end menu:fuzzy_find_open() end, + ['q'] = function() + local menu = utils.menu.get_current() + if menu then + menu:close() + end + end, }, ---@alias dropbar_menu_win_config_opts_t any|fun(menu: dropbar_menu_t):any ---@type table