From bac2ad694d81d78b4ca54174e12e532b6aa6eaca Mon Sep 17 00:00:00 2001 From: ADoyle Date: Mon, 9 Sep 2024 19:04:57 +0800 Subject: [PATCH] fix: nvim-window-picker upgrade from v1 to v2 User should upgrade nvim-window-picker by manual. --- doc/one.txt | 2 +- doc/usage/keymaps.md | 2 +- lua/one/plugins/move/window-picker.lua | 138 ++++++++++++++++++------- 3 files changed, 105 insertions(+), 37 deletions(-) diff --git a/doc/one.txt b/doc/one.txt index 08d8166..8f6d1d7 100644 --- a/doc/one.txt +++ b/doc/one.txt @@ -416,7 +416,7 @@ If bufferline plugin enabled, some keymaps will be overridden. See [Buffer Line] -------------------------------------------------------------------------------- ## Window *one-keymaps-window* -- `-` = Choose window in current tab +- `-` = Jump to window in current tab - `` = Choose window or tab via telescope picker - `<]w>` = Focus to next window - `<[w>` = Focus to previous window diff --git a/doc/usage/keymaps.md b/doc/usage/keymaps.md index 1274c49..a36e67a 100644 --- a/doc/usage/keymaps.md +++ b/doc/usage/keymaps.md @@ -292,7 +292,7 @@ If bufferline plugin enabled, some keymaps will be overridden. See [Buffer Line] ## Window -- `-` = Choose window in current tab +- `-` = Jump to window in current tab - `` = Choose window or tab via telescope picker - `<]w>` = Focus to next window - `<[w>` = Focus to previous window diff --git a/lua/one/plugins/move/window-picker.lua b/lua/one/plugins/move/window-picker.lua index 68a290a..eee2a22 100644 --- a/lua/one/plugins/move/window-picker.lua +++ b/lua/one/plugins/move/window-picker.lua @@ -3,39 +3,59 @@ local colors = config.colors return { 's1n7ax/nvim-window-picker', - tag = 'v1.*', + tag = '2.*', config = function() - require'window-picker'.setup(config['window-picker']) + require 'window-picker'.setup(config['window-picker']) end, defaultConfig = { 'window-picker', { - -- when there is only one window available to pick from, use that window - -- without prompting the user to select - autoselect_one = true, - - -- whether you want to include the window you are currently on to window - -- selection or not - include_current_win = true, + -- type of hints you want to get + -- following types are supported + -- 'statusline-winbar' | 'floating-big-letter' + -- 'statusline-winbar' draw on 'statusline' if possible, if not 'winbar' will be + -- 'floating-big-letter' draw big letter on a floating window used + hint = 'statusline-winbar', -- when you go to window selection mode, status bar will show one of -- following letters on them so you can use that letter to select the window selection_chars = 'FJDKSLA;CMRUEIWOQP', - -- You can change the display string in status bar. - -- It supports '%' printf style. Such as `return char .. ': %f'` to display - -- buffer filepath. See :h 'stl' for details. - selection_display = function(char) - return string.format('[%s] %s', char, '%f') - end, - -- whether you want to use winbar instead of the statusline - -- "always" means to always use winbar, - -- "never" means to never use winbar - -- "smart" means to use winbar if cmdheight=0 and statusline if cmdheight > 0 - use_winbar = 'smart', -- "always" | "never" | "smart" + -- This section contains picker specific configurations + picker_config = { + statusline_winbar_picker = { + -- You can change the display string in status bar. + -- It supports '%' printf style. Such as `return char .. ': %f'` to display + -- buffer file path. See :h 'stl' for details. + selection_display = function(char, windowid) + return string.format(' [%s] %s', char, '%f') + end, + + -- whether you want to use winbar instead of the statusline + -- "always" means to always use winbar, + -- "never" means to never use winbar + -- "smart" means to use winbar if cmdheight=0 and statusline if cmdheight > 0 + use_winbar = 'smart', -- "always" | "never" | "smart" + }, + + floating_big_letter = { + -- window picker plugin provides bunch of big letter fonts + -- fonts will be lazy loaded as they are being requested + -- additionally, user can pass in a table of fonts in to font + -- property to use instead + + font = 'ansi-shadow', -- ansi-shadow | + }, + }, + + -- whether to show 'Pick window:' prompt + show_prompt = true, + + -- prompt message to show to get the user input + prompt_message = 'Pick a window', -- if you want to manually filter out the windows, pass in a function that -- takes two parameters. you should return window ids that should be @@ -52,6 +72,15 @@ return { -- defined by this plugin. if you pass in a function to "filter_func" -- property, you are on your own filter_rules = { + + -- when there is only one window available to pick from, use that window + -- without prompting the user to select + autoselect_one = true, + + -- whether you want to include the window you are currently on to window + -- selection or not + include_current_win = false, + -- filter using buffer options bo = { -- if the file type is one of following, the window will be ignored @@ -65,7 +94,11 @@ return { 'nerdtree', 'NvimTree', 'neo-tree', + 'neo-tree-popup', + 'neo-tree-preview', + 'NvimSeparator', -- defined in colorful-winsep.nvim 'notify', + 'noice', 'aerial', 'Mundo', 'mason', @@ -81,25 +114,43 @@ return { -- filter using window options wo = {}, - -- if the file path contains one of following names, the window - -- will be ignored + -- if the file path contains one of following names, the window will be ignored file_path_contains = {}, - -- if the file name contains one of following names, the window will be - -- ignored + -- if the file name contains one of following names, the window will be ignored file_name_contains = {}, }, - -- the foreground (text) color of the picker - fg_color = colors.black, + -- You can pass in the highlight name or a table of content to set as + -- highlight + highlights = { + statusline = { + focused = { + fg = colors.black, + bg = colors.blue, + bold = true, + }, + unfocused = { + fg = colors.black, + bg = colors.green, + bold = true, + }, + }, - -- if you have include_current_win == true, then current_win_hl_color will - -- be highlighted using this background color - current_win_hl_color = colors.blue, + winbar = { + focused = { + fg = colors.black, + bg = colors.blue, - -- all the windows except the curren window will be highlighted using this - -- color - other_win_hl_color = colors.green, + bold = true, + }, + unfocused = { + fg = colors.black, + bg = colors.green, + bold = true, + }, + }, + }, }, }, @@ -109,10 +160,27 @@ return { '-', function() local picker = require('window-picker') - local picked_window_id = picker.pick_window() or vim.api.nvim_get_current_win() - vim.api.nvim_set_current_win(picked_window_id) + + local ok, winsep = pcall(require, 'colorful-winsep') + if ok then + winsep.hide() + end + + local picked_window_id = picker.pick_window({ + filter_rules = { + bo = { + -- if the file type is one of following, the window will be ignored + filetype = {}, + }, + }, + prompt_message = 'Jump to window in current tab', + }) + + if picked_window_id then + vim.api.nvim_set_current_win(picked_window_id) + end end, - { desc = 'Pick a window' }, + { desc = 'Jump to window in current tab' }, }, }, }