diff --git a/README.md b/README.md index 4e60852..41fe917 100644 --- a/README.md +++ b/README.md @@ -49,22 +49,23 @@ use { ## Options ```lua -theme = 'hyper' -- theme is doom and hyper default is hyper -disable_move -- default is false disable move keymap for hyper -shortcut_type -- shorcut type 'letter' or 'number' -shuffle_letter -- default is true, shortcut 'letter' will be randomize, set to false to have ordered letter. +theme = 'hyper' -- theme is doom and hyper default is hyper +disable_move -- default is false disable move keymap for hyper +shortcut_type -- shorcut type 'letter' or 'number' +shuffle_letter -- default is false, shortcut 'letter' will be randomize, set to false to have ordered letter +letter_list -- default is a-z, excluding j and k change_to_vcs_root -- default is false,for open file in hyper mru. it will change to the root of vcs -config = {}, -- config used for theme +config = {}, -- config used for theme hide = { - statusline -- hide statusline default is true - tabline -- hide the tabline - winbar -- hide winbar + statusline -- hide statusline default is true + tabline -- hide the tabline + winbar -- hide winbar }, preview = { - command -- preview command - file_path -- preview file path - file_height -- preview file height - file_width -- preview file width + command -- preview command + file_path -- preview file path + file_height -- preview file height + file_width -- preview file width }, ``` diff --git a/doc/dashboard.txt b/doc/dashboard.txt index 513ed56..3a93094 100644 --- a/doc/dashboard.txt +++ b/doc/dashboard.txt @@ -13,7 +13,7 @@ Table of Contents *dashboard-table-of-contents* 6. LICENSE |dashboard-license| 7. Links |dashboard-links| Fancy and Blazing Fast start screen plugin of neovim ----------------------------------- ----------------------------------- - + ----------------------------------- ----------------------------------- @@ -65,22 +65,23 @@ Fancy and Blazing Fast start screen plugin of neovim -------------------------- OPTIONS *dashboard-configuration-options* >lua - theme = 'hyper' -- theme is doom and hyper default is hyper - disable_move -- default is false disable move keymap for hyper - shortcut_type -- shorcut type 'letter' or 'number' - shuffle_letter -- default is true, shortcut 'letter' will be randomize, set to false to have ordered letter. - change_to_vcs_root -- default is false,for open file in hyper mru. it will change to the root of vcs - config = {}, -- config used for theme + theme = 'hyper' -- theme is doom and hyper default is hyper + disable_move -- default is false disable move keymap for hyper + shortcut_type -- shortcut type 'letter' or 'number' + shuffle_letter -- default is false, shortcut 'letter' will be randomize, set to false to have ordered letter + letter_list -- default is a-z, excluding j and k + change_to_vcs_root -- default is false, for open file in hyper mru. it will change to the root of vcs + config = {}, -- config used for theme hide = { - statusline -- hide statusline default is true - tabline -- hide the tabline - winbar -- hide winbar + statusline -- hide statusline default is true + tabline -- hide the tabline + winbar -- hide winbar }, preview = { - command -- preview command - file_path -- preview file path - file_height -- preview file height - file_width -- preview file width + command -- preview command + file_path -- preview file path + file_height -- preview file height + file_width -- preview file width }, < @@ -282,7 +283,7 @@ MIT ============================================================================== 7. Links *dashboard-links* -1. *@RakerZh*: +1. *@RakerZh*: 2. **: https://img.shields.io/badge/PayPal-00457C?style=for-the-badge&logo=paypal&logoColor=white Generated by panvimdoc diff --git a/lua/dashboard/init.lua b/lua/dashboard/init.lua index 7286e6c..cf21b09 100644 --- a/lua/dashboard/init.lua +++ b/lua/dashboard/init.lua @@ -37,6 +37,7 @@ local function default_options() disable_move = false, shortcut_type = 'letter', shuffle_letter = false, + letter_list = "abcdefghilmnopqrstuvwxyz", buffer_name = 'Dashboard', change_to_vcs_root = false, config = { @@ -199,6 +200,7 @@ function db:load_theme(opts) confirm_key = opts.confirm_key or nil, shortcut_type = opts.shortcut_type, shuffle_letter = opts.shuffle_letter, + letter_list = opts.letter_list, change_to_vcs_root = opts.change_to_vcs_root, }) diff --git a/lua/dashboard/theme/hyper.lua b/lua/dashboard/theme/hyper.lua index ddfe7d5..00cc51e 100644 --- a/lua/dashboard/theme/hyper.lua +++ b/lua/dashboard/theme/hyper.lua @@ -214,54 +214,50 @@ local function shuffle_table(table) end local function letter_hotkey(config) - -- Reserve j, k keys to move up and down. - local list = { 106, 107 } + local used_keys = {} local shuffle = config.shuffle_letter + local letter_list = config.letter_list for _, item in pairs(config.shortcut or {}) do if item.key then - table.insert(list, item.key:byte()) + table.insert(used_keys, item.key:byte()) end end math.randomseed(os.time()) -- Create key table, fill it with unused characters. - local unused_keys = {} - -- a - z - for key = 97, 122 do - if not vim.tbl_contains(list, key) then - table.insert(unused_keys, key) + local function collect_unused_keys(uppercase) + local unused_keys = {} + for key in letter_list:gmatch(".") do + if uppercase then + key = key:upper() + end + key = key:byte() + if not vim.tbl_contains(used_keys, key) then + table.insert(unused_keys, key) + end end - end - - if shuffle then - shuffle_table(unused_keys) - end - - local unused_uppercase_keys = {} - -- A - Z - for key = 65, 90 do - if not vim.tbl_contains(list, key) then - table.insert(unused_uppercase_keys, key) + if shuffle then + shuffle_table(unused_keys) end + return unused_keys end - if shuffle then - shuffle_table(unused_uppercase_keys) - end + local unused_keys_lowercase = collect_unused_keys(false) + local unused_keys_uppercase = collect_unused_keys(true) -- Push shuffled uppercase keys after the lowercase ones - for _, key in pairs(unused_uppercase_keys) do - table.insert(unused_keys, key) + for _, key in pairs(unused_keys_uppercase) do + table.insert(unused_keys_lowercase, key) end local fallback_hotkey = 0 return function() - if #unused_keys ~= 0 then + if #unused_keys_lowercase ~= 0 then -- Pop an unused key to use it as a hotkey. - local key = table.remove(unused_keys, 1) + local key = table.remove(unused_keys_lowercase, 1) return string.char(key) else -- All keys are already used. Fallback to the number generation.