Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Can't exit resize mode second time if <Esc> is mapped #232

Open
1 task done
bingo084 opened this issue Aug 20, 2024 · 5 comments
Open
1 task done

[Bug]: Can't exit resize mode second time if <Esc> is mapped #232

bingo084 opened this issue Aug 20, 2024 · 5 comments
Assignees
Labels
bug Something isn't working PRs-welcome I'd love to see a PR for this

Comments

@bingo084
Copy link

bingo084 commented Aug 20, 2024

Similar Issues

  • Before filing, I have searched for similar issues.

Neovim Version

NVIM v0.10.1
Build type: Release
LuaJIT 2.1.1723675123
Run "nvim -V1 -v" for more info

Multiplexer Integration

Kitty

Multiplexer Version

kitty 0.36.0 created by Kovid Goyal

Steps to Reproduce

  1. Enter resize mode
  2. Press <Esc> to exit resize mode
  3. Enter resize mode again
  4. Press <Esc> to exit resize mode again, failed

Expected Behavior

Exit resize mode normally.

Actual Behavior

Stuck in resize mode, unable to exit.

Minimal Configuration to Reproduce

local root = vim.fn.fnamemodify('./.repro', ':p')

-- set stdpaths to use .repro
for _, name in ipairs({ 'config', 'data', 'state', 'cache' }) do
  vim.env[('XDG_%s_HOME'):format(name:upper())] = root .. '/' .. name
end

-- bootstrap lazy
local lazypath = root .. '/plugins/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    'git',
    'clone',
    '--filter=blob:none',
    '--single-branch',
    'https://github.com/folke/lazy.nvim.git',
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  -- do not remove the colorscheme! it makes testing nicer
  'folke/tokyonight.nvim',
  'mrjones2014/smart-splits.nvim',
  -- add any other pugins here
}

require('lazy').setup(plugins, {
  root = root .. '/plugins',
})

require('smart-splits').setup({
  -- add any options here
})

vim.keymap.set('n', '<Esc>', '<cmd>nohlsearch<cr>')
vim.keymap.set('n', '<A-r>', require('smart-splits').start_resize_mode)

-- add anything else here
vim.opt.termguicolors = true
-- do not remove the colorscheme! it makes testing nicer
vim.cmd([[colorscheme tokyonight]])

Additional Details and/or Screenshots

No response

@bingo084 bingo084 added the bug Something isn't working label Aug 20, 2024
@mrjones2014 mrjones2014 added the PRs-welcome I'd love to see a PR for this label Aug 30, 2024
@leg7
Copy link

leg7 commented Nov 13, 2024

I have the same problem

@drowning-cat
Copy link

drowning-cat commented Dec 22, 2024

As a temporary solution, you can use the pogyomo/submode.nvim plugin.

Warning

Not directly the solution to the issue

Click to expand the code
{
  'mrjones2014/smart-splits.nvim',
  event = 'VeryLazy',
  dependencies = {
    'pogyomo/submode.nvim',
  },
  config = function()
    -- Resize
    local submode = require 'submode'
    submode.create('WinResize', {
      mode = 'n',
      enter = '<C-w>r',
      leave = { '<Esc>', 'q', '<C-c>' },
      default = function(register)
        register('h', require('smart-splits').resize_left, { desc = 'Resize left' })
        register('j', require('smart-splits').resize_down, { desc = 'Resize down' })
        register('k', require('smart-splits').resize_up, { desc = 'Resize up' })
        register('l', require('smart-splits').resize_right, { desc = 'Resize right' })
        register('<Left>', require('smart-splits').resize_left, { desc = 'Resize left' })
        register('<Down>', require('smart-splits').resize_down, { desc = 'Resize down' })
        register('<Up>', require('smart-splits').resize_up, { desc = 'Resize up' })
        register('<Right>', require('smart-splits').resize_right, { desc = 'Resize right' })
      end,
    })
    -- Optional: notifications
    vim.api.nvim_create_autocmd('User', {
      group = vim.api.nvim_create_augroup('winresize-enter', {}),
      pattern = 'SubmodeEnterPost',
      callback = function(env)
        if env.data.name == 'WinResize' then
          vim.notify 'Use { h, j, k, l } or { <Left>, <Down>, <Up>, <Right> } to resize the window'
        end
      end,
    })
    vim.api.nvim_create_autocmd('User', {
      group = vim.api.nvim_create_augroup('winresize-leave', {}),
      pattern = 'SubmodeLeavePost',
      callback = function(env)
        if env.data.name == 'WinResize' then
          vim.cmd [[echon '']]
        end
      end,
    })
  end,
}
Click to expand the code (updated)
{
  'mrjones2014/smart-splits.nvim',
  event = 'VeryLazy',
  dependencies = {
    'pogyomo/submode.nvim',
  },
  config = function()
    -- Resize
    local submode = require 'submode'
    submode.create('WinResize', {
      mode = 'n',
      enter = '<C-w>r',
      leave = { '<Esc>', 'q', '<C-c>' },
      hook = {
        on_enter = function()
          vim.notify 'Use { h, j, k, l } or { <Left>, <Down>, <Up>, <Right> } to resize the window'
        end,
        on_leave = function()
          vim.notify ''
        end,
      },
      default = function(register)
        register('h', require('smart-splits').resize_left, { desc = 'Resize left' })
        register('j', require('smart-splits').resize_down, { desc = 'Resize down' })
        register('k', require('smart-splits').resize_up, { desc = 'Resize up' })
        register('l', require('smart-splits').resize_right, { desc = 'Resize right' })
        register('<Left>', require('smart-splits').resize_left, { desc = 'Resize left' })
        register('<Down>', require('smart-splits').resize_down, { desc = 'Resize down' })
        register('<Up>', require('smart-splits').resize_up, { desc = 'Resize up' })
        register('<Right>', require('smart-splits').resize_right, { desc = 'Resize right' })
      end,
    })
  end,
}

@mrjones2014
Copy link
Owner

Yeah, I've been considering making something like that the official solution; I don't use the resize mode feature and it's been a bit of a maintenance burden.

@drowning-cat
Copy link

drowning-cat commented Dec 24, 2024

I also think delegating this functionality to another plugin is a good idea. Mentioning submode.nvim or another plugin in the README.md as an alternative way to define keymaps could be helpful. This approach could attract new users to the plugin and help confirm whether its creator intends to actively maintain it. Over time, this feature could be gradually marked as deprecated if needed.

@mrjones2014
Copy link
Owner

Yep, agree with all of that. I'll need to put some more thought into it since it would be a breaking change, but I won't get to it till after the holidays since I'm away from home at family's.

I'll revisit this some time in the next couple weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working PRs-welcome I'd love to see a PR for this
Projects
None yet
Development

No branches or pull requests

4 participants