Skip to content

Commit 74e3b98

Browse files
authored
Pick your own letters and prioritize the order (#487)
* 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
1 parent 4bad0f5 commit 74e3b98

File tree

4 files changed

+53
-53
lines changed

4 files changed

+53
-53
lines changed

README.md

+13-12
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,23 @@ use {
4949
## Options
5050

5151
```lua
52-
theme = 'hyper' -- theme is doom and hyper default is hyper
53-
disable_move -- default is false disable move keymap for hyper
54-
shortcut_type -- shorcut type 'letter' or 'number'
55-
shuffle_letter -- default is true, shortcut 'letter' will be randomize, set to false to have ordered letter.
52+
theme = 'hyper' -- theme is doom and hyper default is hyper
53+
disable_move -- default is false disable move keymap for hyper
54+
shortcut_type -- shortcut type 'letter' or 'number'
55+
shuffle_letter -- default is false, shortcut 'letter' will be randomize, set to false to have ordered letter
56+
letter_list -- default is a-z, excluding j and k
5657
change_to_vcs_root -- default is false,for open file in hyper mru. it will change to the root of vcs
57-
config = {}, -- config used for theme
58+
config = {}, -- config used for theme
5859
hide = {
59-
statusline -- hide statusline default is true
60-
tabline -- hide the tabline
61-
winbar -- hide winbar
60+
statusline -- hide statusline default is true
61+
tabline -- hide the tabline
62+
winbar -- hide winbar
6263
},
6364
preview = {
64-
command -- preview command
65-
file_path -- preview file path
66-
file_height -- preview file height
67-
file_width -- preview file width
65+
command -- preview command
66+
file_path -- preview file path
67+
file_height -- preview file height
68+
file_width -- preview file width
6869
},
6970
```
7071

doc/dashboard.txt

+16-15
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Table of Contents *dashboard-table-of-contents*
1313
6. LICENSE |dashboard-license|
1414
7. Links |dashboard-links|
1515
Fancy and Blazing Fast start screen plugin of neovim ----------------------------------- -----------------------------------
16-
16+
1717

1818
----------------------------------- -----------------------------------
1919

@@ -65,22 +65,23 @@ Fancy and Blazing Fast start screen plugin of neovim --------------------------
6565
OPTIONS *dashboard-configuration-options*
6666

6767
>lua
68-
theme = 'hyper' -- theme is doom and hyper default is hyper
69-
disable_move -- default is false disable move keymap for hyper
70-
shortcut_type -- shorcut type 'letter' or 'number'
71-
shuffle_letter -- default is true, shortcut 'letter' will be randomize, set to false to have ordered letter.
72-
change_to_vcs_root -- default is false,for open file in hyper mru. it will change to the root of vcs
73-
config = {}, -- config used for theme
68+
theme = 'hyper' -- theme is doom and hyper default is hyper
69+
disable_move -- default is false disable move keymap for hyper
70+
shortcut_type -- shortcut type 'letter' or 'number'
71+
shuffle_letter -- default is false, shortcut 'letter' will be randomize, set to false to have ordered letter
72+
letter_list -- default is a-z, excluding j and k
73+
change_to_vcs_root -- default is false, for open file in hyper mru. it will change to the root of vcs
74+
config = {}, -- config used for theme
7475
hide = {
75-
statusline -- hide statusline default is true
76-
tabline -- hide the tabline
77-
winbar -- hide winbar
76+
statusline -- hide statusline default is true
77+
tabline -- hide the tabline
78+
winbar -- hide winbar
7879
},
7980
preview = {
80-
command -- preview command
81-
file_path -- preview file path
82-
file_height -- preview file height
83-
file_width -- preview file width
81+
command -- preview command
82+
file_path -- preview file path
83+
file_height -- preview file height
84+
file_width -- preview file width
8485
},
8586
<
8687

@@ -283,7 +284,7 @@ MIT
283284
==============================================================================
284285
7. Links *dashboard-links*
285286

286-
1. *@RakerZh*:
287+
1. *@RakerZh*:
287288
2. **: https://img.shields.io/badge/PayPal-00457C?style=for-the-badge&logo=paypal&logoColor=white
288289

289290
Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>

lua/dashboard/init.lua

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ local function default_options()
3737
disable_move = false,
3838
shortcut_type = 'letter',
3939
shuffle_letter = false,
40+
letter_list = 'abcdefghilmnopqrstuvwxyz',
4041
buffer_name = 'Dashboard',
4142
change_to_vcs_root = false,
4243
config = {
@@ -199,6 +200,7 @@ function db:load_theme(opts)
199200
confirm_key = opts.confirm_key or nil,
200201
shortcut_type = opts.shortcut_type,
201202
shuffle_letter = opts.shuffle_letter,
203+
letter_list = opts.letter_list,
202204
change_to_vcs_root = opts.change_to_vcs_root,
203205
})
204206

lua/dashboard/theme/hyper.lua

+22-26
Original file line numberDiff line numberDiff line change
@@ -219,54 +219,50 @@ local function shuffle_table(table)
219219
end
220220

221221
local function letter_hotkey(config)
222-
-- Reserve j, k keys to move up and down.
223-
local list = { 106, 107 }
222+
local used_keys = {}
224223
local shuffle = config.shuffle_letter
224+
local letter_list = config.letter_list
225225

226226
for _, item in pairs(config.shortcut or {}) do
227227
if item.key then
228-
table.insert(list, item.key:byte())
228+
table.insert(used_keys, item.key:byte())
229229
end
230230
end
231231

232232
math.randomseed(os.time())
233233

234234
-- Create key table, fill it with unused characters.
235-
local unused_keys = {}
236-
-- a - z
237-
for key = 97, 122 do
238-
if not vim.tbl_contains(list, key) then
239-
table.insert(unused_keys, key)
235+
local function collect_unused_keys(uppercase)
236+
local unused_keys = {}
237+
for key in letter_list:gmatch('.') do
238+
if uppercase then
239+
key = key:upper()
240+
end
241+
key = key:byte()
242+
if not vim.tbl_contains(used_keys, key) then
243+
table.insert(unused_keys, key)
244+
end
240245
end
241-
end
242-
243-
if shuffle then
244-
shuffle_table(unused_keys)
245-
end
246-
247-
local unused_uppercase_keys = {}
248-
-- A - Z
249-
for key = 65, 90 do
250-
if not vim.tbl_contains(list, key) then
251-
table.insert(unused_uppercase_keys, key)
246+
if shuffle then
247+
shuffle_table(unused_keys)
252248
end
249+
return unused_keys
253250
end
254251

255-
if shuffle then
256-
shuffle_table(unused_uppercase_keys)
257-
end
252+
local unused_keys_lowercase = collect_unused_keys(false)
253+
local unused_keys_uppercase = collect_unused_keys(true)
258254

259255
-- Push shuffled uppercase keys after the lowercase ones
260-
for _, key in pairs(unused_uppercase_keys) do
261-
table.insert(unused_keys, key)
256+
for _, key in pairs(unused_keys_uppercase) do
257+
table.insert(unused_keys_lowercase, key)
262258
end
263259

264260
local fallback_hotkey = 0
265261

266262
return function()
267-
if #unused_keys ~= 0 then
263+
if #unused_keys_lowercase ~= 0 then
268264
-- Pop an unused key to use it as a hotkey.
269-
local key = table.remove(unused_keys, 1)
265+
local key = table.remove(unused_keys_lowercase, 1)
270266
return string.char(key)
271267
else
272268
-- All keys are already used. Fallback to the number generation.

0 commit comments

Comments
 (0)