Skip to content

Commit

Permalink
fix: help menu crashing when a keybinding is disabled (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikavilpas authored Jul 28, 2024
1 parent ec9cd23 commit dca52dd
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
1 change: 1 addition & 0 deletions integration-tests/client/testEnvironmentTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type StartupScriptModification =
| "use_light_neovim_colorscheme.lua"
| "report_loaded_yazi_modules.lua"
| "modify_yazi_config_and_set_help_key.lua"
| "disable_a_keybinding.lua"

declare global {
interface Window {
Expand Down
5 changes: 4 additions & 1 deletion integration-tests/cypress/e2e/help-menu.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ describe("the help menu", () => {
it("can show help with a keymap", () => {
cy.visit("http://localhost:5173")
startNeovimWithYa({
startupScriptModifications: ["modify_yazi_config_and_set_help_key.lua"],
startupScriptModifications: [
"modify_yazi_config_and_set_help_key.lua",
"disable_a_keybinding.lua",
],
}).then((dir) => {
// wait until text on the start screen is visible
cy.contains("If you see this text, Neovim is ready!")
Expand Down
9 changes: 9 additions & 0 deletions integration-tests/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ io.on("connection", function connection(socket) {
args.push("-c", `lua dofile('${file}')`)
break
}
case "disable_a_keybinding.lua": {
const file = path.join(
testDirectory,
"config-modifications",
"disable_a_keybinding.lua",
)
args.push("-c", `lua dofile('${file}')`)
break
}
default:
modification satisfies never
throw new Error(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---@module "yazi"

require('yazi').setup(
---@type YaziConfig
{
keymaps = {
open_file_in_tab = false,
},
}
)
20 changes: 13 additions & 7 deletions lua/yazi/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -229,26 +229,32 @@ function M.set_keymappings(yazi_buffer, config, context)
border = config.yazi_floating_window_border,
})

local function show(key)
return key or '<Nop>'
end

-- write the help text. Hopefully the vim help syntax is always bundled
-- and available so that nice highlights can be shown.
vim.api.nvim_buf_set_lines(help_buffer, 0, -1, false, {
'yazi.nvim help (`q` to close):',
'',
'' .. config.keymaps.open_file_in_tab .. ' - open file in tab',
'' .. show(config.keymaps.open_file_in_tab) .. ' - open file in tab',
''
.. config.keymaps.open_file_in_horizontal_split
.. show(config.keymaps.open_file_in_horizontal_split)
.. ' - open file in horizontal split',
''
.. config.keymaps.open_file_in_vertical_split
.. show(config.keymaps.open_file_in_vertical_split)
.. ' - open file in vertical split',
''
.. config.keymaps.grep_in_directory
.. show(config.keymaps.grep_in_directory)
.. ' - search in directory / selected files',
''
.. config.keymaps.replace_in_directory
.. show(config.keymaps.replace_in_directory)
.. ' - replace in directory / selected files',
'' .. config.keymaps.cycle_open_buffers .. ' - cycle open buffers',
'' .. config.keymaps.show_help .. ' - show this help',
''
.. show(config.keymaps.cycle_open_buffers)
.. ' - cycle open buffers',
'' .. show(config.keymaps.show_help) .. ' - show this help',
'',
'version *' .. require('yazi').version .. '*',
})
Expand Down

0 comments on commit dca52dd

Please sign in to comment.