From 8d06f3693ef2cf7cedc248e79d1310bda4d8958c Mon Sep 17 00:00:00 2001 From: Nizamuddin Sulieman Date: Mon, 1 Jul 2024 19:18:22 +0800 Subject: [PATCH] Option for fixed/alphabetical `shortcut` ordering for `hyper` theme (#464) * feat(hyper): add option to use ordered `shortcut` * docs(readme): update new option in README.md * style(stylua): fix linter error --- README.md | 1 + lua/dashboard/init.lua | 2 ++ lua/dashboard/theme/hyper.lua | 9 +++++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3bb2009..4e60852 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ use { 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 hide = { diff --git a/lua/dashboard/init.lua b/lua/dashboard/init.lua index 7cb2823..799ffe1 100644 --- a/lua/dashboard/init.lua +++ b/lua/dashboard/init.lua @@ -36,6 +36,7 @@ local function default_options() theme = 'hyper', disable_move = false, shortcut_type = 'letter', + shuffle_letter = false, buffer_name = 'Dashboard', change_to_vcs_root = false, config = { @@ -190,6 +191,7 @@ function db:load_theme(opts) winid = self.winid, confirm_key = opts.confirm_key or nil, shortcut_type = opts.shortcut_type, + shuffle_letter = opts.shuffle_letter, change_to_vcs_root = opts.change_to_vcs_root, }) diff --git a/lua/dashboard/theme/hyper.lua b/lua/dashboard/theme/hyper.lua index 00155b2..2da09be 100644 --- a/lua/dashboard/theme/hyper.lua +++ b/lua/dashboard/theme/hyper.lua @@ -216,6 +216,7 @@ end local function letter_hotkey(config) -- Reserve j, k keys to move up and down. local list = { 106, 107 } + local shuffle = config.shuffle_letter for _, item in pairs(config.shortcut or {}) do if item.key then @@ -234,7 +235,9 @@ local function letter_hotkey(config) end end - shuffle_table(unused_keys) + if shuffle then + shuffle_table(unused_keys) + end local unused_uppercase_keys = {} -- A - Z @@ -244,7 +247,9 @@ local function letter_hotkey(config) end end - shuffle_table(unused_uppercase_keys) + if shuffle then + shuffle_table(unused_uppercase_keys) + end -- Push shuffled uppercase keys after the lowercase ones for _, key in pairs(unused_uppercase_keys) do