mrjones2014 / smart-splits.nvim

🧠 Smart, seamless, directional navigation and resizing of Neovim + terminal multiplexer splits. Supports tmux, Wezterm, and Kitty. Think about splits in terms of "up/down/left/right".
MIT License
987 stars 43 forks source link

[Bug]: Wezterm Unable to move jumps properly #151

Closed mochouaaaaa closed 9 months ago

mochouaaaaa commented 9 months ago

Similar Issues

Neovim Version

NVIM v0.10.0-dev-2086+g965dbd0e0 Build type: RelWithDebInfo LuaJIT 2.1.1703358377 Run "nvim -V1 -v" for more info

Multiplexer Integration

Wezterm

Multiplexer Version

➜ wezterm --version wezterm 20240203-110809-5046fc22

Steps to Reproduce

  1. nvim .config
  2. split
  3. Inside the wezterm terminal you can move to nvim, But you can't move to another pane in nvim

Expected Behavior

Normal move from nvim to other pane

Actual Behavior

unable to move

Minimal Configuration to Reproduce

local M = {}

-- if you are NOT lazy-loading smart-splits.nvim (recommended) local function is_vim(pane) -- this is set by the plugin, and unset on ExitPre in Neovim return pane:get_user_vars().IS_NVIM == "true" end

function M.is_inside_vim(pane) local tty = pane:get_tty_name() if tty == nil then return false end

local success, _, _ = w.run_child_process {
    "sh",
    "-c",
    "ps -o state= -o comm= -t"
        .. w.shell_quote_arg(tty)
        .. " | "
        .. "grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|l?n?vim?x?)(diff)?$'",
}

return success

end

local direction_keys = {

h = "Left",
j = "Down",
k = "Up",
l = "Right",

}

function M.wezterm_nvim(operation, key, mods) return { key = key, mods = mods, action = w.action_callback(function(win, pane) if M.is_inside_vim(pane) then print(win) print(pane) print(act.SendKey { key = key, mods = mods }) -- pass the keys through to vim/nvim win:perform_action( -- SendKey = { key = key, mods = mods }, act.SendKey { key = key, mods = mods }, pane ) else if operation == "resize" then win:perform_action({ AdjustPaneSize = { direction_keys[key], 3 } }, pane) elseif operation == "move" then win:perform_action({ ActivatePaneDirection = direction_keys[key] }, pane) end end end), } end


### Additional Details and/or Screenshots

- smart-split.log
```log
[二  2/13 20:00:22 2024][smart-splits.nvim] Auto-detected multiplexer back-end: wezterm
[二  2/13 20:00:51 2024][smart-splits.nvim] Auto-detected multiplexer back-end: wezterm
[二  2/13 20:13:11 2024][smart-splits.nvim] Auto-detected multiplexer back-end: wezterm
[二  2/13 20:50:24 2024][smart-splits.nvim] Auto-detected multiplexer back-end: wezterm
[二  2/13 20:55:06 2024][smart-splits.nvim] Auto-detected multiplexer back-end: wezterm
[Tue Feb 13 20:59:02 2024][smart-splits.nvim] Auto-detected multiplexer back-end: wezterm
mochouaaaaa commented 9 months ago

Everything works fine on kitty with this configuration, I'm not sure at the moment which step the problem is, everything seems so normal

mrjones2014 commented 9 months ago

Can you explain the is_inside_vim function in the Wezterm config? My immediate assumption is that this is the issue, the recommended setup in the README.md shows to use the user variable check by the is_vim function, which I don't see used anywhere in your config.

mochouaaaaa commented 9 months ago

@mrjones2014 Checking whether the current pane is nvim by querying the process has the same effect as is_vim.

print(tty)  -- /dev/ttys002

In the nvim process it works fine, only the move operation doesn't work, but in the wezterm environment the effect is completely opposite, only the move operation works fine, all other operations don't work.

mrjones2014 commented 9 months ago

What's the reason for is_inside_vim vs. just using the suggested is_vim? Does it work if you revert to using the is_vim function?

            vim.keymap.set("n", "<D-k>", function() smart_splits.move_cursor_up() end)
            vim.keymap.set("n", "<D-j>", function() smart_splits.move_cursor_down() end)
            vim.keymap.set("n", "<D-h>", function() smart_splits.move_cursor_left() end)
            vim.keymap.set("n", "<D-l>", function() smart_splits.move_cursor_right() end)

Also pretty sure <D> is not a valid key code in nvim, based on your log output it looks like you're trying to use macOS Command key, which should be <M>.

Where are the Wezterm keymaps?

mochouaaaaa commented 9 months ago

I also suspected a command key issue, but wezterm I'm using the kitty protocol and have tried both using SUPER and CMD mapping, but the results are the same!



Maybe via https://github.com/wez/wezterm/issues/3731#issuecomment-1592198263 solve I'll try that later
mochouaaaaa commented 9 months ago

It can be determined that the problem is not with the plugin, as using SmartCursorMove in an nvim environment.