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: vim.fn.win_execute(win, 'normal zx') does nothing #830

Open
4 tasks done
MagicDuck opened this issue Aug 24, 2024 · 3 comments
Open
4 tasks done

bug: vim.fn.win_execute(win, 'normal zx') does nothing #830

MagicDuck opened this issue Aug 24, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@MagicDuck
Copy link

MagicDuck commented Aug 24, 2024

Did you check docs and existing issues?

  • I have read all the which-key.nvim docs
  • I have updated the plugin to the latest version before submitting this issue
  • I have searched the existing issues of which-key.nvim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

0.10.0

Operating system/version

MacOS 14.6.1

Describe the bug

This appears to be a regression with V3 which-key version.
In previous versions, vim.fn.win_execute(win, 'normal zx') would work.
It also works if I completely comment out which-key plugin setup.

Steps To Reproduce

  1. create 2 splits
  2. in one of them, run =vim.fn.win_getid() to get the window id, ex result: 1067
  3. select some lines and create a fold with zf
  4. open the fold with zo
  5. move cursor a few lines down, outside of the folded lines
  6. enter insert mode
  7. move to the other split (without exiting insert mode in the previous one) and enter :lua vim.fn.win_execute(1067, 'normal zx')

Notice that nothing happens. If you instead do other things like :lua vim.fn.win_execute(1067, 'normal 5j') that works!

Expected Behavior

the fold should collapse. As it does if you execute zx in normal mode from the first window.

Health

==============================================================================
which-key: require("which-key.health").check()

- OK Most of these checks are for informational purposes only.
  WARNINGS should be treated as a warning, and don't necessarily indicate a problem with your config.
  Please |DON't| report these warnings as an issue.

Checking your config ~
- WARNING |mini.icons| is not installed
- OK |nvim-web-devicons| is installed

Checking for issues with your mappings ~
- OK No issues reported

checking for overlapping keymaps ~
- WARNING In mode `n`, <m> overlaps with <m]>, <m8>, <mq>, <mu>, <m2>, <mi>, <mz>, <mk>, <mj>, <m:>, <mh>, <mf>, <m{>, <m,>, <me>, <m0>, <mc>, <m}>, <md>, <ms>, <mt>, <mr>, <mb>, <ml>, <mo>, <mx>, <ma>, <m4>, <m1>, <mp>, <mm>, <m9>, <my>, <m[>, <m5>, <m7>, <m6>, <m3>, <mg>, <mv>, <mw>, <mn>, <m;>:
  - <mq>: marks: set mark Q
  - <mu>: marks: set mark U
  - <mi>: marks: set mark I
  - <mz>: marks: set mark Z
  - <mk>: marks: set mark K
  - <mj>: marks: set mark J
  - <mh>: marks: set mark H
  - <mf>: marks: set mark F
  - <me>: marks: set mark E
  - <mc>: marks: set mark C
  - <md>: marks: set mark D
  - <ms>: marks: set mark S
  - <mt>: marks: set mark T
  - <mr>: marks: set mark R
  - <mb>: marks: set mark B
  - <ml>: marks: set mark L
  - <mo>: marks: set mark O
  - <mx>: marks: set mark X
  - <ma>: marks: set mark A
  - <mp>: marks: set mark P
  - <mm>: marks: set mark M
  - <my>: marks: set mark Y
  - <mg>: marks: set mark G
  - <mv>: marks: set mark V
  - <mw>: marks: set mark W
  - <mn>: marks: set mark N
- WARNING In mode `n`, <gc> overlaps with <gcc>:
  - <gc>: Toggle comment
  - <gcc>: Toggle comment line
- WARNING In mode `n`, <]y> overlaps with <]yy>:
  
- WARNING In mode `n`, <]u> overlaps with <]uu>:
  
- WARNING In mode `n`, <]C> overlaps with <]CC>:
  
- WARNING In mode `n`, <]x> overlaps with <]xx>:
  
- WARNING In mode `n`, <[y> overlaps with <[yy>:
  
- WARNING In mode `n`, <[u> overlaps with <[uu>:
  
- WARNING In mode `n`, <[C> overlaps with <[CC>:
  
- WARNING In mode `n`, <[x> overlaps with <[xx>:
  
- WARNING In mode `n`, <dm> overlaps with <dm->, <dm6>, <dm3>, <dm<Space>>, <dm4>, <dm1>, <dm=>, <dm2>, <dm9>, <dm8>, <dm5>, <dm7>, <dm0>:
  
- WARNING In mode `n`, <<Space>x> overlaps with <<Space>xt>, <<Space>xf>:
  - <<Space>x>: buffer: close current buffer while preserving window
  - <<Space>xt>: mini.test: run tests
  - <<Space>xf>: mini.test: run file
- WARNING In mode `x`, <r> overlaps with <r=>:
  - <r>: restOfIndentation textobj
  - <r=>: Select right hand side of an assignment
- WARNING In mode `o`, <r> overlaps with <r=>:
  - <r>: restOfIndentation textobj
  - <r=>: Select right hand side of an assignment
- OK Overlapping keymaps are only reported for informational purposes.
  This doesn't necessarily mean there is a problem with your config.

Checking for duplicate mappings ~
- OK No duplicate mappings found

Log

on_key: <CR>
ModeChanged(c:n)
  Unsafe(command-mode)
  suspend: Mode(n:8)
  Trigger(del) Mode(n:8) ' " ` g' g` ] [ <C-W> z = > <Space> < g <Plug>
State(start): Mode(n:0) Node(z) { keys = "z" }
  update Mode(n:12)
  continue: z Mode(n:12)
  getchar
  got: x
  suspend: Mode(n:12)
  Trigger(del) Mode(n:12) <Plug> ' " ` g' g` ] [ <C-W> z = > <Space> < g
  feedkeys: Mode(n:12) zx
Trigger(add) Mode(n:12) ' " ` g' g` ] [ <C-W> z = > <Space> < g <Plug>
Trigger(add) Mode(n:8) ' " ` g' g` ] [ <C-W> z = > <Space> < g <Plug>
on_key: s
on_key: l
BufEnter(12)
on_key: <Esc>
on_key: ;
ModeChanged(n:c)
  Safe(true)
on_key: q
on_key: a
on_key: <CR>
ModeChanged(c:n)
  Unsafe(command-mode)
  suspend: Mode(n:12)
  Trigger(del) Mode(n:12) <Plug> ' " ` g' g` ] [ <C-W> z = > <Space> < g
Trigger(add) Mode(n:12) ' " ` g' g` ] [ <C-W> z = > <Space> < g <Plug>

Repro

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
  spec = {
    { "folke/which-key.nvim", opts = {} },
    -- add any other plugins here
  },
})

Note: this is my full config:

      local wk = require('which-key')
      vim.o.timeout = true
      vim.o.timeoutlen = 500

      wk.setup({
        plugins = {
          marks = true, -- shows a list of your marks on ' and `
          registers = true, -- shows your registers on " in NORMAL or <C-r> in INSERT mode
          spelling = {
            enabled = false, -- enabling this will show WhichKey when pressing z= to select spelling suggestions
            suggestions = 20, -- how many suggestions should be shown in the list?
          },
          -- the presets plugin, adds help for a bunch of default keybindings in Neovim
          -- No actual key bindings are created
          presets = {
            operators = true, -- adds help for operators like d, y, ... and registers them for motion / text object completion
            motions = false, -- adds help for motions
            text_objects = true, -- help for text objects triggered after entering an operator
            windows = false, -- default bindings on <c-w>
            nav = true, -- misc bindings to work with windows
            z = true, -- bindings for folds, spelling and others prefixed with z
            g = true, -- bindings for prefixed with g
          },
        },
        keys = {
          scroll_down = '<PageDown>', -- binding to scroll down inside the popup
          scroll_up = '<PageUp>', -- binding to scroll up inside the popup
        },
      })
@MagicDuck MagicDuck added the bug Something isn't working label Aug 24, 2024
@MagicDuck MagicDuck changed the title bug: vim.fn.win_execute(win, 'normal zx') does nothing unless win buffer is in normal mode bug: vim.fn.win_execute(win, 'normal zx') does nothing Aug 24, 2024
@MagicDuck
Copy link
Author

Note, in case it helps debug the issue, this works as a workaround but has the side effect of cursor flickering if calculating folds for lots of lines:

    local currentWin = vim.api.nvim_get_current_win()
    vim.api.nvim_set_current_win(win)

    vim.api.nvim_feedkeys(
      -- note: if in insert mode, <C-\><C-o> does a normal mode command without moving cursor
      -- see help ins-special-special
      vim.api.nvim_replace_termcodes('<c-\\><c-o><cmd>normal zx<cr>', true, false, true),
      'n',
      false
    )
    vim.api.nvim_set_current_win(currentWin)

@MagicDuck
Copy link
Author

I've also tried using vim._foldupdate(win, start, end) as a workaround but it seems to do nothing...

@MagicDuck
Copy link
Author

note that this affects grug-far.nvim plugin. This line:
https://github.com/MagicDuck/grug-far.nvim/blob/ebab68b2150079732ae8074eefb261a124824139/lua/grug-far/fold.lua#L18
Workaround is to pass the following to wk.setup():

        disable = {
          ft = { 'grug-far' },
        },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant