From adbc11fc1bf0daea5b2e3919ac667ddfa6b4338d Mon Sep 17 00:00:00 2001 From: Aietes Date: Sun, 1 Dec 2024 17:35:52 +0100 Subject: [PATCH 1/4] nvim-window-picker integration for mini.files extra When nvim-window-picker plugin is installed, allow picking a window when opening a file with mini.files --- .../plugins/extras/editor/mini-files.lua | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/lua/lazyvim/plugins/extras/editor/mini-files.lua b/lua/lazyvim/plugins/extras/editor/mini-files.lua index 70a42940..e5c729c6 100644 --- a/lua/lazyvim/plugins/extras/editor/mini-files.lua +++ b/lua/lazyvim/plugins/extras/editor/mini-files.lua @@ -107,5 +107,42 @@ return { Snacks.rename.on_rename_file(event.data.from, event.data.to) end, }) + + local plugin = require("lazy.core.config").plugins["nvim-window-picker"] + if plugin then + --- Opens the file in a picked window. + --- @param close boolean Whether to close the mini.files window after opening the file. + local open_in_window = function(close) + close = close or false + local mini_files = require("mini.files") + local picked_window_id = require("window-picker").pick_window({ + filter_rules = { + autoselect_one = true, + bo = { + filetype = { "notify", "minifiles" }, + buftype = { "terminal", "quickfix", "nofile" }, + }, + }, + }) + if picked_window_id then + mini_files.set_target_window(picked_window_id) + mini_files.go_in({ close_on_file = close }) + else + vim.notify("Window selection canceled", vim.log.levels.INFO, { title = "mini.files" }) + end + end + + vim.api.nvim_create_autocmd("User", { + pattern = "MiniFilesBufferCreate", + callback = function(args) + local buf_id = args.data.buf_id + + vim.keymap.set("n", "", open_in_window, { buffer = buf_id, desc = "Open file in window" }) + vim.keymap.set("n", "", function() + open_in_window(true) + end, { buffer = buf_id, desc = "Open file in window and close" }) + end, + }) + end end, } From 4ff106bf7f471197c44d58917a5ea0aabc08835a Mon Sep 17 00:00:00 2001 From: Aietes Date: Sun, 1 Dec 2024 17:41:22 +0100 Subject: [PATCH 2/4] Remove check for nvim-window-picker plugin --- .../plugins/extras/editor/mini-files.lua | 63 +++++++++---------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/lua/lazyvim/plugins/extras/editor/mini-files.lua b/lua/lazyvim/plugins/extras/editor/mini-files.lua index e5c729c6..3bcd9296 100644 --- a/lua/lazyvim/plugins/extras/editor/mini-files.lua +++ b/lua/lazyvim/plugins/extras/editor/mini-files.lua @@ -108,41 +108,38 @@ return { end, }) - local plugin = require("lazy.core.config").plugins["nvim-window-picker"] - if plugin then - --- Opens the file in a picked window. - --- @param close boolean Whether to close the mini.files window after opening the file. - local open_in_window = function(close) - close = close or false - local mini_files = require("mini.files") - local picked_window_id = require("window-picker").pick_window({ - filter_rules = { - autoselect_one = true, - bo = { - filetype = { "notify", "minifiles" }, - buftype = { "terminal", "quickfix", "nofile" }, - }, + --- Opens the file in a picked window. + --- @param close boolean Whether to close the mini.files window after opening the file. + local open_in_window = function(close) + close = close or false + local mini_files = require("mini.files") + local picked_window_id = require("window-picker").pick_window({ + filter_rules = { + autoselect_one = true, + bo = { + filetype = { "notify", "minifiles" }, + buftype = { "terminal", "quickfix", "nofile" }, }, - }) - if picked_window_id then - mini_files.set_target_window(picked_window_id) - mini_files.go_in({ close_on_file = close }) - else - vim.notify("Window selection canceled", vim.log.levels.INFO, { title = "mini.files" }) - end - end - - vim.api.nvim_create_autocmd("User", { - pattern = "MiniFilesBufferCreate", - callback = function(args) - local buf_id = args.data.buf_id - - vim.keymap.set("n", "", open_in_window, { buffer = buf_id, desc = "Open file in window" }) - vim.keymap.set("n", "", function() - open_in_window(true) - end, { buffer = buf_id, desc = "Open file in window and close" }) - end, + }, }) + if picked_window_id then + mini_files.set_target_window(picked_window_id) + mini_files.go_in({ close_on_file = close }) + else + vim.notify("Window selection canceled", vim.log.levels.INFO, { title = "mini.files" }) + end end + + vim.api.nvim_create_autocmd("User", { + pattern = "MiniFilesBufferCreate", + callback = function(args) + local buf_id = args.data.buf_id + + vim.keymap.set("n", "", open_in_window, { buffer = buf_id, desc = "Open file in window" }) + vim.keymap.set("n", "", function() + open_in_window(true) + end, { buffer = buf_id, desc = "Open file in window and close" }) + end, + }) end, } From 53a71c0e869b176d304728f2087c86fdc2206029 Mon Sep 17 00:00:00 2001 From: Aietes Date: Sun, 1 Dec 2024 22:52:09 +0100 Subject: [PATCH 3/4] Check if nvim-window-picker is installed before registering auto command --- .../plugins/extras/editor/mini-files.lua | 63 ++++++++++--------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/lua/lazyvim/plugins/extras/editor/mini-files.lua b/lua/lazyvim/plugins/extras/editor/mini-files.lua index 3bcd9296..08d91ef9 100644 --- a/lua/lazyvim/plugins/extras/editor/mini-files.lua +++ b/lua/lazyvim/plugins/extras/editor/mini-files.lua @@ -108,38 +108,41 @@ return { end, }) - --- Opens the file in a picked window. - --- @param close boolean Whether to close the mini.files window after opening the file. - local open_in_window = function(close) - close = close or false - local mini_files = require("mini.files") - local picked_window_id = require("window-picker").pick_window({ - filter_rules = { - autoselect_one = true, - bo = { - filetype = { "notify", "minifiles" }, - buftype = { "terminal", "quickfix", "nofile" }, + --- Allow to open the file in a picked window if nvim-window-picker is installed. + if pcall(require, "window-picker") then + --- Opens the file in a picked window. + --- @param close boolean Whether to close the mini.files window after opening the file. + local open_in_window = function(close) + close = close or false + local mini_files = require("mini.files") + local picked_window_id = require("window-picker").pick_window({ + filter_rules = { + autoselect_one = true, + bo = { + filetype = { "notify", "minifiles" }, + buftype = { "terminal", "quickfix", "nofile" }, + }, }, - }, - }) - if picked_window_id then - mini_files.set_target_window(picked_window_id) - mini_files.go_in({ close_on_file = close }) - else - vim.notify("Window selection canceled", vim.log.levels.INFO, { title = "mini.files" }) + }) + if picked_window_id then + mini_files.set_target_window(picked_window_id) + mini_files.go_in({ close_on_file = close }) + else + vim.notify("Window selection canceled", vim.log.levels.INFO, { title = "mini.files" }) + end end + + vim.api.nvim_create_autocmd("User", { + pattern = "MiniFilesBufferCreate", + callback = function(args) + local buf_id = args.data.buf_id + + vim.keymap.set("n", "", open_in_window, { buffer = buf_id, desc = "Open file in window" }) + vim.keymap.set("n", "", function() + open_in_window(true) + end, { buffer = buf_id, desc = "Open file in window and close" }) + end, + }) end - - vim.api.nvim_create_autocmd("User", { - pattern = "MiniFilesBufferCreate", - callback = function(args) - local buf_id = args.data.buf_id - - vim.keymap.set("n", "", open_in_window, { buffer = buf_id, desc = "Open file in window" }) - vim.keymap.set("n", "", function() - open_in_window(true) - end, { buffer = buf_id, desc = "Open file in window and close" }) - end, - }) end, } From f7eecb2bfe30ef2d70ecdfead88110e2f165da60 Mon Sep 17 00:00:00 2001 From: Aietes Date: Sun, 1 Dec 2024 23:00:41 +0100 Subject: [PATCH 4/4] Change key binding description --- lua/lazyvim/plugins/extras/editor/mini-files.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/lazyvim/plugins/extras/editor/mini-files.lua b/lua/lazyvim/plugins/extras/editor/mini-files.lua index 08d91ef9..9971cac9 100644 --- a/lua/lazyvim/plugins/extras/editor/mini-files.lua +++ b/lua/lazyvim/plugins/extras/editor/mini-files.lua @@ -137,10 +137,10 @@ return { callback = function(args) local buf_id = args.data.buf_id - vim.keymap.set("n", "", open_in_window, { buffer = buf_id, desc = "Open file in window" }) + vim.keymap.set("n", "", open_in_window, { buffer = buf_id, desc = "Open in picked window" }) vim.keymap.set("n", "", function() open_in_window(true) - end, { buffer = buf_id, desc = "Open file in window and close" }) + end, { buffer = buf_id, desc = "Open in picked window and close" }) end, }) end