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

Issue with folke/zen-mode.nvim #116

Open
doongjohn opened this issue Mar 2, 2023 · 9 comments
Open

Issue with folke/zen-mode.nvim #116

doongjohn opened this issue Mar 2, 2023 · 9 comments
Labels
bug Something isn't working ecosystem

Comments

@doongjohn
Copy link

Recording 2023-03-03 at 00 59 11

  1. Run cmd: ZenMode
  2. Start leap
    local function leapSearch()
      leap.leap { target_windows = vim.tbl_filter(
        function(win) return vim.api.nvim_win_get_config(win).focusable end,
        vim.api.nvim_tabpage_list_wins(0)
      ) }
    end
    
    keymap_s('n', 'm', leapSearch)
    keymap_s('v', 'm', leapSearch)
    keymap_s('o', 'm', leapSearch)
  3. Enter two characters.
  4. Enter the final character.
  5. ZenMode exits and the cursor does not move.

leap config:

local leap = require 'leap'
leap.setup {}
leap.opts.highlight_unlabeled_phase_one_targets = true
vim.api.nvim_set_hl(0, 'LeapBackdrop', { link = 'Comment' })
vim.api.nvim_set_hl(0, 'LeapMatch', {
  fg = 'white',
  bold = true,
  nocombine = true,
})

zen-mode config:

require 'zen-mode'.setup {
  {
    window = {
      -- height and width can be:
      -- * an absolute number of cells when > 1
      -- * a percentage of the width / height of the editor when <= 1
      -- * a function that returns the width or the height
      width = 220, -- width of the Zen window
      height = 1, -- height of the Zen window
    },
  },
  on_open = function()
    vim.cmd('doautocmd FileType')
  end
}
@ggandor
Copy link
Owner

ggandor commented Mar 2, 2023

I can reproduce. Single-window search works, the problem appears when other windows are included, like in your custom command (gs fails too, but fortunately no one would intentionally use that in a Zen window).

In your specific case, a quick fix would be:

local function leapSearch()
  zen_mode_active = ...  -- left as an exercise to the reader
  -- Restricting Leap to the current window if ZenMode is active.
  leap.leap { target_windows = zen_mode_active and vim.fn.win_getid() or vim.tbl_filter(
    function(win) return vim.api.nvim_win_get_config(win).focusable end,
    vim.api.nvim_tabpage_list_wins(0)
  ) }
end

@ggandor ggandor added the bug Something isn't working label Mar 2, 2023
@ggandor
Copy link
Owner

ggandor commented Mar 2, 2023

@folke

@folke
Copy link

folke commented Mar 2, 2023

Zen-mode automatically closes whenever the window loses focus by design, so that's indeed what's causing this here

@ggandor
Copy link
Owner

ggandor commented Mar 2, 2023

And we are finding targets... where if not in the current (floating) window?

@folke
Copy link

folke commented Mar 2, 2023

I'm assuming in the windows below the zen window? The zen window is a float.
So probably the same buffer, but original window?

@ggandor
Copy link
Owner

ggandor commented Mar 2, 2023

Yeah, I guess the window below remains focusable. If that is the case, you could fix this on your side (instead of adding checks to the Leap call) by explicitly setting the all other windows on the tab page non-focusable when the Zen window is opened.

@folke
Copy link

folke commented Mar 2, 2023

As I mentioned, that's how it's supposed to work. If the original window would no longer be focusable, then the user also can't <c-w>w to it for example.

Op should just fix the function he uses like you suggested

@ggandor
Copy link
Owner

ggandor commented Mar 2, 2023

Right, got it. TBH, I thought you can only exit a zen window with its dedicated toggle, but I guess a floating island from which you can "jump off" is a valid mental model too.

@folke
Copy link

folke commented Mar 2, 2023

That's how I use it 😄

I mapped just the arrow keys to navigate between windows, so I simply do left or right to exit zen-mode.

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

No branches or pull requests

3 participants