Skip to content

Commit

Permalink
Pick your own letters and prioritize the order (#487)
Browse files Browse the repository at this point in the history
* Add: Pick your own letters and prioritise, this way we can get homerow keys first, in my case aoeuhtns for dvorak
Fix: Documentation had wrong default for shuffle_letters

* Add back removed func

* Clean up .idea

* Clean tags

* Stylua

* Typo fix
  • Loading branch information
mbwilding authored Jan 22, 2025
1 parent 4bad0f5 commit 74e3b98
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 53 deletions.
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 -- 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
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
},
```

Expand Down
31 changes: 16 additions & 15 deletions doc/dashboard.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----------------------------------- -----------------------------------


----------------------------------- -----------------------------------

Expand Down Expand Up @@ -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
},
<

Expand Down Expand Up @@ -283,7 +284,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 <https://github.com/kdheepak/panvimdoc>
Expand Down
2 changes: 2 additions & 0 deletions lua/dashboard/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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,
})

Expand Down
48 changes: 22 additions & 26 deletions lua/dashboard/theme/hyper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -219,54 +219,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.
Expand Down

0 comments on commit 74e3b98

Please sign in to comment.