Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lua/fzf-lua/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,7 @@ M.vimcmd_entry = function(_vimcmd, selected, opts, pcall_vimcmd)
return
end
end
if will_replace_curbuf
and vim.fn.exists("&winfixbuf") == 1
and vim.wo.winfixbuf
if will_replace_curbuf and utils.wo.winfixbuf
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this was added in 0.10 and we still support 0.9 don’t we still need vim.fn.exists("&winfixbuf") == 1?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i change the semantic of utils.wo
see in tests/utils_spec

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i write something wrong right vim.wo in eq should be utils.wo

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i write something wrong right vim.wo in eq should be utils.wo

But it is utils.wo

then
utils.warn("'winfixbuf' is set for current window, will open in a split.")
vimcmd = "split | " .. vimcmd
Expand Down
16 changes: 6 additions & 10 deletions lua/fzf-lua/previewer/builtin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ function TSContext.update(winid, bufnr, opts)
if win and api.nvim_win_is_valid(win) and api.nvim_win_get_config(win).zindex ~= zindex then
api.nvim_win_set_config(win, { zindex = zindex })
-- noautocmd don't ignore WinResized/WinScrolled
if fn.exists("+eventignorewin") == 1 and vim.wo[win][0].eventignorewin == "" then
vim.wo[win][0].eventignorewin = "WinResized"
end
utils.wo[win].eventignorewin = "WinResized"
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as other comment, wasn’t eventignorewin only added with 0.10?

end
end
api.nvim_win_call(winid, function()
Expand Down Expand Up @@ -1053,11 +1051,11 @@ function Previewer.base:attach_snacks_image_inline()
if not ft then return end
_G._fzf_lua_snacks_langs = _G._fzf_lua_snacks_langs or simg.langs()
if not vim.tbl_contains(_G._fzf_lua_snacks_langs, vim.treesitter.language.get_lang(ft)) then
vim.wo[preview_winid].winblend = self.winblend
utils.wo[preview_winid].winblend = self.winblend
return
end

vim.wo[preview_winid].winblend = 0 -- https://github.com/folke/snacks.nvim/pull/1615
utils.wo[preview_winid].winblend = 0 -- https://github.com/folke/snacks.nvim/pull/1615
vim.b[bufnr].snacks_image_attached = simg.inline.new(bufnr)
vim.defer_fn(function()
self.win:update_preview_scrollbar()
Expand Down Expand Up @@ -1121,7 +1119,7 @@ function Previewer.buffer_or_file:do_syntax(entry)
-- nvim_buf_call has less side-effects than window switch
-- doautocmd filetypedetect BufRead (vim.filetype.match + ftdetect) + do_modeline
local ok, _ = pcall(api.nvim_buf_call, bufnr, function()
utils.eventignore(function() vim.cmd("filetype detect") end, preview_winid, "FileType")
utils.eventignore(function() vim.cmd("filetype detect") end, "FileType")
end)
if not ok then
utils.warn(("':filetype detect' failed for '%s'"):format(entry.path or "<null>"))
Expand Down Expand Up @@ -1172,9 +1170,7 @@ function Previewer.base:maybe_set_cursorline(win, pos)
vim.api.nvim_win_set_cursor(win, pos)
cursorline = self.winopts.cursorline
end
if cursorline ~= vim.wo[win].cursorline then
vim.wo[win].cursorline = cursorline
end
utils.wo[win].cursorline = cursorline
end

function Previewer.buffer_or_file:set_cursor_hl(entry)
Expand Down Expand Up @@ -1211,7 +1207,7 @@ function Previewer.buffer_or_file:set_cursor_hl(entry)
local lnum, col = tonumber(entry.line), tonumber(entry.col) or 0
if not lnum or lnum < 1 then
-- set win option is slow with bigfile
if vim.wo.cursorline then vim.wo.cursorline = false end
utils.wo.cursorline = false
self.orig_pos = { 1, 0 }
api.nvim_win_set_cursor(self.win.preview_winid, cached_pos or self.orig_pos)
return
Expand Down
1 change: 0 additions & 1 deletion lua/fzf-lua/providers/nvim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,6 @@ M.nvim_options = function(opts)
end

M.spell_suggest = function(opts)
-- if not vim.wo.spell then return false end
---@type fzf-lua.config.SpellSuggest
opts = config.normalize_opts(opts, "spell_suggest")
if not opts then return end
Expand Down
4 changes: 2 additions & 2 deletions lua/fzf-lua/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ _G.FzfLua = require("fzf-lua")
---@field scrolloff? integer

---@class fzf-lua.config.Keymap
---@field builtin table<string, string>
---@field fzf table<string, string>
---@field builtin? table<string, string>
---@field fzf? table<string, string>

---@class fzf-lua.config.Previewer
---@field cmd string|fun():string?
Expand Down
40 changes: 26 additions & 14 deletions lua/fzf-lua/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ M.__HAS_NVIM_0102 = vim.fn.has("nvim-0.10.2") == 1
M.__HAS_NVIM_011 = vim.fn.has("nvim-0.11") == 1
M.__IS_WINDOWS = vim.fn.has("win32") == 1 or vim.fn.has("win64") == 1
-- `:help shellslash` (for more info see #1055)
M.__WIN_HAS_SHELLSLASH = M.__IS_WINDOWS and vim.fn.exists("+shellslash")
M.__WIN_HAS_SHELLSLASH = M.__IS_WINDOWS and vim.fn.exists("+shellslash") == 1

function M.__FILE__() return debug.getinfo(2, "S").source end

Expand Down Expand Up @@ -133,10 +133,6 @@ function M.round(num, limit)
return math.floor(num)
end

function M.nvim_has_option(option)
return vim.fn.exists("&" .. option) == 1
end

M._notify_header = "LineNr"

--- Fancy notification wrapper, idea borrowed from blink.nvim
Expand Down Expand Up @@ -1153,16 +1149,8 @@ end

---@param func function
---@param scope string?
---@param win integer?
---@return ... any
function M.eventignore(func, win, scope)
if win and vim.fn.exists("+eventignorewin") == 1 then
local save_ei = vim.wo[win][0].eventignorewin
vim.wo[win][0].eventignorewin = scope or "all"
local ret = { func() }
vim.wo[win][0].eventignorewin = save_ei
return unpack(ret)
end
function M.eventignore(func, scope)
local save_ei = vim.o.eventignore
vim.o.eventignore = scope or "all"
local ret = { func() }
Expand Down Expand Up @@ -1560,4 +1548,28 @@ function M.pid_object(key, opts)
return Pid:new(key, opts)
end

-- modified version of vim.wo
-- 1. always setlocal (to avoid potential pollute on win split)
-- 2. nop on non-exist option
-- 3. nop if unchange (set win option can be slow #2018)
local function new_win_opt_accessor(winid)
return setmetatable({}, {
__index = function(_, k)
if type(k) == "number" then return new_win_opt_accessor(k) end
if vim.fn.exists("+" .. k) == 0 then return end
return vim.api.nvim_get_option_value(k, { scope = "local", win = winid or 0 })
end,
__newindex = function(_, k, v)
if vim.fn.exists("+" .. k) == 0
or vim.api.nvim_get_option_value(k, { scope = "local", win = winid or 0 }) == v then
return
end
vim.api.nvim_set_option_value(k, v, { scope = "local", win = winid or 0 })
end,
})
end
---@type {}|vim.wo
M.wo = new_win_opt_accessor()


return M
Loading
Loading