Skip to content

Commit f29df2c

Browse files
authored
feat(hyper): display shortcuts on the left side (#514)
* feat(hyper): add shortcuts_left_side option * feat(hyper): display shortcuts on the left side * fix: stylua
1 parent 0f99b3c commit f29df2c

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

lua/dashboard/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ function db:load_theme(opts)
198198
bufnr = self.bufnr,
199199
winid = self.winid,
200200
confirm_key = opts.confirm_key or nil,
201+
shortcuts_left_side = opts.shortcuts_left_side,
201202
shortcut_type = opts.shortcut_type,
202203
shuffle_letter = opts.shuffle_letter,
203204
letter_list = opts.letter_list,

lua/dashboard/theme/hyper.lua

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,10 @@ local function project_list(config, callback)
138138
if list then
139139
list = vim.list_slice(list, #list - config.project.limit)
140140
end
141+
local blank_size = config.shortcuts_left_side and 4 or 3
141142
for _, dir in ipairs(list or {}) do
142143
dir = dir:gsub(vim.env.HOME, '~')
143-
table.insert(res, (' '):rep(3) .. '' .. dir)
144+
table.insert(res, (' '):rep(blank_size) .. '' .. dir)
144145
end
145146

146147
if #res == 0 then
@@ -200,6 +201,7 @@ local function mru_list(config)
200201
end, mlist)
201202
end
202203

204+
local blank_size = config.shortcuts_left_side and 4 or 3
203205
for _, file in pairs(vim.list_slice(mlist, 1, config.mru.limit)) do
204206
local filename = vim.fn.fnamemodify(file, ':t')
205207
local icon, group = utils.get_icon(filename)
@@ -211,7 +213,7 @@ local function mru_list(config)
211213
end
212214
file = icon .. ' ' .. file
213215
table.insert(groups, { #icon, group })
214-
table.insert(list, (' '):rep(3) .. file)
216+
table.insert(list, (' '):rep(blank_size) .. file)
215217
end
216218

217219
if #list == 1 then
@@ -414,10 +416,17 @@ local function gen_center(plist, config)
414416
local text = api.nvim_buf_get_lines(config.bufnr, first_line + i - 1, first_line + i, false)[1]
415417
if text and text:find('%w') and not text:find('empty') then
416418
local key = tostring(hotkey())
417-
api.nvim_buf_set_extmark(config.bufnr, ns, first_line + i - 1, 0, {
418-
virt_text = { { key, 'DashboardShortCut' } },
419-
virt_text_pos = 'eol',
420-
})
419+
if config.shortcuts_left_side then
420+
api.nvim_buf_set_extmark(config.bufnr, ns, first_line + i - 1, start_col - 1, {
421+
virt_text = { { key, 'DashboardShortCut' } },
422+
virt_text_pos = 'inline',
423+
})
424+
else
425+
api.nvim_buf_set_extmark(config.bufnr, ns, first_line + i - 1, 0, {
426+
virt_text = { { key, 'DashboardShortCut' } },
427+
virt_text_pos = 'eol',
428+
})
429+
end
421430
map_key(config, key, text)
422431
end
423432
end
@@ -464,10 +473,17 @@ local function gen_center(plist, config)
464473
)[1]
465474
if text and text:find('%w') then
466475
local key = tostring(hotkey())
467-
api.nvim_buf_set_extmark(config.bufnr, ns, first_line + i + plist_len, 0, {
468-
virt_text = { { key, 'DashboardShortCut' } },
469-
virt_text_pos = 'eol',
470-
})
476+
if config.shortcuts_left_side then
477+
api.nvim_buf_set_extmark(config.bufnr, ns, first_line + i + plist_len, start_col - 1, {
478+
virt_text = { { key, 'DashboardShortCut' } },
479+
virt_text_pos = 'inline',
480+
})
481+
else
482+
api.nvim_buf_set_extmark(config.bufnr, ns, first_line + i + plist_len, 0, {
483+
virt_text = { { key, 'DashboardShortCut' } },
484+
virt_text_pos = 'eol',
485+
})
486+
end
471487
map_key(config, key, text)
472488
end
473489
end

plugin/dashboard.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ vim.api.nvim_create_autocmd('VimEnter', {
66
group = g,
77
callback = function()
88
for _, v in pairs(vim.v.argv) do
9-
if v == "-" then
9+
if v == '-' then
1010
vim.g.read_from_stdin = 1
1111
break
1212
end

0 commit comments

Comments
 (0)