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: opening file in the wrong split when using floating window with preview in multiple-split layout #566

Closed
3 tasks done
MomePP opened this issue Jan 23, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@MomePP
Copy link
Contributor

MomePP commented Jan 23, 2025

Did you check the docs and existing issues?

  • I have read the docs
  • I have searched the existing issues

Neovim version (nvim -v)

NVIM v0.10.3 Build type: Release LuaJIT 2.1.1736781742

Operating system/version

MacOS 15.2

Describe the bug

Using Oil in floating window with preview seems to open a file in the wrong split (not the previously focused split before entering Oil floating window).

for example, we have 2 splits : left-split and right-split.

|-------|-------|
|       |       |
|       |   x   |
|       |       |
|-------|-------|

Starting in the right split, then entering Oil floating window(:Oil --float) with a preview window. When opening a file, it should open in the right-split. But, in this case, it opens in the left-split.

What is the severity of this bug?

minor (annoyance)

Steps To Reproduce

  1. nvim -u repro.lua
  2. <C-w><C-v>, <C-w><C-w> vertical split window and focus on second split
  3. :Oil --float open oil in floating window
  4. <C-p> open oil preview window
  5. select repro.lua as file to open

Expected Behavior

repro.lua should be opened in previous focus split(right split).

|-------|-------|
|       |       |
|       |   x   |
|       |       |
|-------|-------|

Directory structure

repro.lua

Repro

-- save as repro.lua
-- run with nvim -u repro.lua
-- DO NOT change the paths
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "runtime", "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 = {
  "folke/tokyonight.nvim",
  {
        "stevearc/oil.nvim",
        config = function()
            require("oil").setup({
              -- add any needed settings here
            })
        end,
  },
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

Did you check the bug with a clean config?

  • I have confirmed that the bug reproduces with nvim -u repro.lua using the repro.lua file above.
@tmwatchanan
Copy link

I found the same behavior as @MomePP described. With the preview enabled, the file is opened in the left window instead of the right window.

@BozeBro
Copy link
Contributor

BozeBro commented Jan 23, 2025

I understand the behavior now, and #560 does seem like the appropriate fix for this issue. Looks good

@tmwatchanan
Copy link

Nice, let's merge the fix then. Thank you both.

@MomePP MomePP closed this as completed Jan 24, 2025
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

3 participants