mikavilpas / yazi.nvim

A Neovim Plugin for the yazi terminal file manager
MIT License
534 stars 18 forks source link

Escape key breaks plugin accessibility #423

Closed yuvals1 closed 3 days ago

yuvals1 commented 2 months ago

Pressing Escape while in the plugin:

Makes the plugin inaccessible Requires quitting via Neovim command line

mikavilpas commented 2 months ago

Hmm that's strange - for me the escape key causes no issues.

Could you follow https://github.com/mikavilpas/yazi.nvim/blob/main/documentation/reproducing-issues.md and see if you can reproduce the issue?

yuvals1 commented 1 month ago

turns out this line was the problem: vim.keymap.set('t', '<Esc><Esc>', '<C-\\><C-n>', { desc = 'Exit terminal mode' }) (it's default in kickstart)

also - toggleterm with this configuration made the plugin super laggy:

return {
  {
    'akinsho/toggleterm.nvim',
    version = '*',
    opts = {
      size = 20,
      open_mapping = [[<C-t>]],
      hide_numbers = true,
      shade_filetypes = {},
      shade_terminals = true,
      shading_factor = 2,
      start_in_insert = true,
      insert_mappings = true,
      persist_size = true,
      direction = 'float',
      close_on_exit = true,
      shell = vim.o.shell,
      float_opts = {
        border = 'curved',
        winblend = 0,
        highlights = {
          border = 'Normal',
          background = 'Normal',
        },
      },
    },
    config = function(_, opts)
      require('toggleterm').setup(opts)

      function _G.set_terminal_keymaps()
        local opts = { buffer = 0 }
        vim.keymap.set('t', '<esc>', [[<C-\><C-n>]], opts)
        vim.keymap.set('t', 'jk', [[<C-\><C-n>]], opts)
        vim.keymap.set('t', '<C-h>', [[<Cmd>wincmd h<CR>]], opts)
        vim.keymap.set('t', '<C-j>', [[<Cmd>wincmd j<CR>]], opts)
        vim.keymap.set('t', '<C-k>', [[<Cmd>wincmd k<CR>]], opts)
        vim.keymap.set('t', '<C-l>', [[<Cmd>wincmd l<CR>]], opts)
      end

      -- Auto command to set terminal keymaps when terminal is opened
      vim.cmd 'autocmd! TermOpen term://* lua set_terminal_keymaps()'
    end,
  },
}

haven't checked why.

by the way, it also affected other nvim tui plugins (like lazygit.nvim)

mikavilpas commented 1 month ago

That's strange. Glad you were able to narrow it down.

It reminds me of this https://github.com/mikavilpas/yazi.nvim/issues/295

yuvals1 commented 1 month ago

any idea why would toggleterm affect yazi.nvim (and other nvim tui plugins) so bad?

(by the way i didnt remove toggleterm altoghter, i just changed it to this configuration:

return {
  {
    'akinsho/toggleterm.nvim',
    version = '*',
    opts = {
      size = 20,
      open_mapping = [[<C-t>]],
      hide_numbers = true,
      shade_filetypes = {},
      shade_terminals = false,
      start_in_insert = true,
      insert_mappings = true,
      persist_size = false,
      direction = 'horizontal',
      close_on_exit = true,
      shell = vim.o.shell,
      float_opts = {
        border = 'single',
        winblend = 0,
        highlights = {
          border = 'Normal',
          background = 'Normal',
        },
      },
    },
    config = function(_, opts)
      require('toggleterm').setup(opts)
      -- Only set keymaps for ToggleTerm buffers
      vim.api.nvim_create_autocmd("TermOpen", {
        pattern = "term://*toggleterm#*",
        callback = function()
          local opts = { buffer = 0 }
          -- vim.keymap.set('t', '<esc>', [[<C-\><C-n>]], opts)
          -- vim.keymap.set('t', 'jk', [[<C-\><C-n>]], opts)
          vim.keymap.set('t', '<C-h>', [[<Cmd>wincmd h<CR>]], opts)
          vim.keymap.set('t', '<C-j>', [[<Cmd>wincmd j<CR>]], opts)
          vim.keymap.set('t', '<C-k>', [[<Cmd>wincmd k<CR>]], opts)
          vim.keymap.set('t', '<C-l>', [[<Cmd>wincmd l<CR>]], opts)
        end
      })
    end,
  },
}

and it was enough to stop the lagginess

mikavilpas commented 1 month ago

Hmm I'm not sure what the lagginess was like for you. But in the issue that I linked, using <esc><esc> as the mapping made pressing only one <esc> key wait for some time to see if the user wants to press a second <esc> or just one. This introduced some lag.

It seems that mapping is some kickstart default - I don't think it's a good idea because it might interfere with tui applications that use the escape key. If you want to disable it for yazi.nvim only, you can maybe use something like this:

    ---@type YaziConfig
    opts = {
      ---@diagnostic disable-next-line: missing-fields
      hooks = {
        ---@diagnostic disable-next-line: unused-local
        yazi_opened = function(_preselected_path, buffer, _config)
          vim.keymap.del("t", "<esc><esc>", { buffer = buffer })
        end,
      },
    }

I have not tested this, but I think it might work.

github-actions[bot] commented 2 weeks ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 3 days ago

This issue was closed because it has been inactive for 14 days since being marked as stale.