Skip to content

Commit a4c0b68

Browse files
committed
WIP
1 parent 60428a8 commit a4c0b68

File tree

16 files changed

+358
-535
lines changed

16 files changed

+358
-535
lines changed

OPTIONS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ Scrollbar style in the builtin previewer, set to `false` to disable, possible va
382382

383383
#### globals.winopts.preview.scrolloff
384384

385-
Type: `number`, Default: `-2`
385+
Type: `number`, Default: `-1`
386386

387387
Float style scrollbar offset from the right edge of the preview window.
388388

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# fzf :heart: lua
44

5-
![Neovim version](https://img.shields.io/badge/Neovim-0.5-57A143?style=flat-square&logo=neovim)
5+
![Neovim version](https://img.shields.io/badge/Neovim-0.7-57A143?style=flat-square&logo=neovim)
66

77
[Quickstart](#quickstart)[Installation](#installation)[Usage](#usage)[Commands](#commands)[Customization](#customization)[Wiki](https://github.com/ibhagwan/fzf-lua/wiki)
88

@@ -55,7 +55,7 @@ Using [lazy.nvim](https://github.com/folke/lazy.nvim)
5555

5656
### Dependencies
5757

58-
- [`neovim`](https://github.com/neovim/neovim/releases) version > `0.5.0`
58+
- [`neovim`](https://github.com/neovim/neovim/releases) version > `0.7.0`
5959
- [`fzf`](https://github.com/junegunn/fzf) version > `0.25`
6060
or [`skim`](https://github.com/skim-rs/skim) binary installed
6161
- [nvim-web-devicons](https://github.com/nvim-tree/nvim-web-devicons)
@@ -406,9 +406,8 @@ winopts = {
406406
width = 0.80, -- window width
407407
row = 0.35, -- window row position (0=top, 1=bottom)
408408
col = 0.50, -- window col position (0=left, 1=right)
409-
-- border argument passthrough to nvim_open_win(), also used
410-
-- 'none', 'single', 'double', 'thicc' (+cc) or 'rounded' (default)
411-
border = { '', '', '', '', '', '', '', '' },
409+
-- border argument passthrough to nvim_open_win()
410+
border = "rounded",
412411
-- Backdrop opacity, 0 is fully opaque, 100 is fully transparent (i.e. disabled)
413412
backdrop = 60,
414413
-- title = "Title",
@@ -425,34 +424,35 @@ winopts = {
425424
preview = {
426425
-- default = 'bat', -- override the default previewer?
427426
-- default uses the 'builtin' previewer
428-
border = 'border', -- border|noborder, applies only to
427+
border = "border", -- preview border: accepts both `nvim_open_win`
428+
-- and fzf values (e.g. "border-top", "none")
429429
-- native fzf previewers (bat/cat/git/etc)
430-
wrap = 'nowrap', -- wrap|nowrap
431-
hidden = 'nohidden', -- hidden|nohidden
432-
vertical = 'down:45%', -- up|down:size
433-
horizontal = 'right:60%', -- right|left:size
434-
layout = 'flex', -- horizontal|vertical|flex
430+
wrap = "nowrap", -- wrap|nowrap
431+
hidden = "nohidden", -- hidden|nohidden
432+
vertical = "down:45%", -- up|down:size
433+
horizontal = "right:60%", -- right|left:size
434+
layout = "flex", -- horizontal|vertical|flex
435435
flip_columns = 100, -- #cols to switch to horizontal on flex
436436
-- Only used with the builtin previewer:
437437
title = true, -- preview border title (file/buf)?
438438
title_pos = "center", -- left|center|right, title alignment
439-
scrollbar = 'float', -- `false` or string:'float|border'
439+
scrollbar = "float", -- `false` or string:'float|border'
440440
-- float: in-window floating border
441441
-- border: in-border "block" marker
442-
scrolloff = '-2', -- float scrollbar offset from right
442+
scrolloff = -1, -- float scrollbar offset from right
443443
-- applies only when scrollbar = 'float'
444444
delay = 20, -- delay(ms) displaying the preview
445445
-- prevents lag on fast scrolling
446446
winopts = { -- builtin previewer window options
447447
number = true,
448448
relativenumber = false,
449449
cursorline = true,
450-
cursorlineopt = 'both',
450+
cursorlineopt = "both",
451451
cursorcolumn = false,
452-
signcolumn = 'no',
452+
signcolumn = "no",
453453
list = false,
454454
foldenable = false,
455-
foldmethod = 'manual',
455+
foldmethod = "manual",
456456
},
457457
},
458458
on_create = function()

doc/fzf-lua-opts.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*fzf-lua-opts.txt* For Neovim >= 0.8.0 Last change: 2024 December 18
1+
*fzf-lua-opts.txt* For Neovim >= 0.8.0 Last change: 2024 December 27
22

33
==============================================================================
44
Table of Contents *fzf-lua-opts-table-of-contents*
@@ -504,7 +504,7 @@ values are `float|border`.
504504

505505
globals.winopts.preview.scrolloff*fzf-lua-opts-globals.winopts.preview.scrolloff*
506506

507-
Type: `number`, Default: `-2`
507+
Type: `number`, Default: `-1`
508508

509509
Float style scrollbar offset from the right edge of the preview window.
510510

lua/fzf-lua/core.lua

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,12 +464,35 @@ M.fzf = function(contents, opts)
464464
return selected
465465
end
466466

467+
-- Best approximation of neovim border types to fzf border types
468+
local function translate_border(border)
469+
local neovim2fzf = {
470+
none = "noborder",
471+
single = "border-sharp",
472+
double = "border-double",
473+
rounded = "border-rounded",
474+
solid = "noborder",
475+
empty = "border-block",
476+
shadow = "border-thinblock",
477+
bold = "border-bold",
478+
block = "border-block",
479+
solidblock = "border-block",
480+
thicc = "border-bold",
481+
thiccc = "border-block",
482+
thicccc = "border-block",
483+
}
484+
border = type(border) == "string" and (neovim2fzf[border] or border) or "rounded"
485+
return border
486+
end
487+
467488
---@param o table
468489
---@return string
469490
M.preview_window = function(o, fzf_win)
470491
local layout
471492
local prefix = string.format("%s:%s:%s",
472-
o.winopts.preview.hidden, o.winopts.preview.border, o.winopts.preview.wrap)
493+
o.winopts.preview.hidden,
494+
translate_border(o.winopts.preview.border),
495+
o.winopts.preview.wrap)
473496
if utils.has(o, "fzf", { 0, 31 })
474497
and o.winopts.preview.layout == "flex"
475498
and tonumber(o.winopts.preview.flip_columns) > 0

lua/fzf-lua/defaults.lua

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ M.defaults = {
6262
title = true,
6363
title_pos = "center",
6464
scrollbar = "border",
65-
scrolloff = "-2",
65+
scrolloff = -1,
6666
-- default preview delay, fzf native previewers has a 100ms delay:
6767
-- https://github.com/junegunn/fzf/issues/2417#issuecomment-809886535
6868
delay = 20,
@@ -1252,27 +1252,4 @@ M.defaults.__HLS = {
12521252
}
12531253
}
12541254

1255-
M.defaults.__WINOPTS = {
1256-
borderchars = {
1257-
["none"] = { "", "", "", "", "", "", "", "" },
1258-
["empty"] = { " ", " ", " ", " ", " ", " ", " ", " " },
1259-
["single"] = { "", "", "", "", "", "", "", "" },
1260-
["double"] = { "", "", "", "", "", "", "", "" },
1261-
["rounded"] = { "", "", "", "", "", "", "", "" },
1262-
["thicc"] = { "", "", "", "", "", "", "", "" },
1263-
["thiccc"] = { "", "", "", "", "", "", "", "" },
1264-
["thicccc"] = { "", "", "", "", "", "", "", "" },
1265-
},
1266-
-- border chars reverse lookup for ambiwidth="double"
1267-
border2string = {
1268-
[" "] = "empty",
1269-
[""] = "single",
1270-
[""] = "double",
1271-
[""] = "rounded",
1272-
[""] = "double",
1273-
[""] = "double",
1274-
[""] = "double",
1275-
},
1276-
}
1277-
12781255
return M

lua/fzf-lua/devicons.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ end
4747
function NvimWebDevicons:load(do_not_lazy_load)
4848
-- limit devicons support to nvim >=0.8, although official support is >=0.7
4949
-- running setup on 0.7 errs with "W18: Invalid character in group name"
50-
if not self._package_loaded and utils.__HAS_NVIM_07
50+
if not self._package_loaded
5151
-- do not trigger lazy loading
5252
and (not do_not_lazy_load or package.loaded[self._package_name])
5353
then

lua/fzf-lua/fzf.lua

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -221,26 +221,24 @@ function M.raw_fzf(contents, fzf_cli_args, opts)
221221
-- sending `feedkeys|startinsert` after the term job is started, this approach
222222
-- seems more consistent as it triggers when entering terminal normal mode "nt"
223223
-- NOTE: "ModeChanged" was added with neovim 0.7
224-
if utils.__HAS_NVIM_07 then
225-
vim.api.nvim_create_autocmd("ModeChanged", {
226-
once = true,
227-
buffer = 0,
228-
callback = function(e)
229-
if e.match:match(":nt") then
230-
vim.defer_fn(function()
231-
-- Prevents inserting "i" when spamming `ctrl-g` in `grep_lgrep`
232-
-- Also verify we're not already in TERMINAL mode, could happen
233-
-- if the user has an autocmd for TermOpen with `startinsert`
234-
if vim.api.nvim_buf_is_valid(e.buf)
235-
and vim.api.nvim_get_mode().mode ~= "t"
236-
then
237-
vim.cmd("startinsert")
238-
end
239-
end, 0)
240-
end
224+
vim.api.nvim_create_autocmd("ModeChanged", {
225+
once = true,
226+
buffer = 0,
227+
callback = function(e)
228+
if e.match:match(":nt") then
229+
vim.defer_fn(function()
230+
-- Prevents inserting "i" when spamming `ctrl-g` in `grep_lgrep`
231+
-- Also verify we're not already in TERMINAL mode, could happen
232+
-- if the user has an autocmd for TermOpen with `startinsert`
233+
if vim.api.nvim_buf_is_valid(e.buf)
234+
and vim.api.nvim_get_mode().mode ~= "t"
235+
then
236+
vim.cmd("startinsert")
237+
end
238+
end, 0)
241239
end
242-
})
243-
end
240+
end
241+
})
244242
end
245243

246244
if opts.debug then
@@ -318,22 +316,6 @@ function M.raw_fzf(contents, fzf_cli_args, opts)
318316
-- fzf-tmux spawns outside neovim, don't set filetype/insert mode
319317
if not opts.is_fzf_tmux then
320318
vim.bo.filetype = "fzf"
321-
322-
-- https://github.com/neovim/neovim/pull/15878
323-
-- Since patch-8.2.3461 which was released with 0.6 neovim distinguishes between
324-
-- Normal mode and Terminal-Normal mode. However, this seems to have also introduced
325-
-- a bug with `startinsert`: When fzf-lua reuses interfaces (e.g. called from "builtin"
326-
-- or grep<->live_grep toggle) the current mode will be "t" which is Terminal (INSERT)
327-
-- mode but our interface is still opened in NORMAL mode, either `startinsert` is not
328-
-- working (as it's technically already in INSERT) or creating a new terminal buffer
329-
-- within the same window starts in NORMAL mode while returning the wrong `nvim_get_mode`
330-
if not utils.__HAS_NVIM_07 then
331-
if utils.__HAS_NVIM_06 and vim.api.nvim_get_mode().mode == "t" then
332-
utils.feed_keys_termcodes("i")
333-
else
334-
vim.cmd [[startinsert]]
335-
end
336-
end
337319
end
338320

339321
if not utils.__IS_WINDOWS

lua/fzf-lua/init.lua

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -127,26 +127,12 @@ function M.setup_highlights(override)
127127
hl_def.default = false
128128
end
129129
end
130-
if utils.__HAS_NVIM_07 then
131-
vim.api.nvim_set_hl(0, hl_name, hl_def)
132-
else
133-
if hl_def.link then
134-
vim.cmd(string.format("hi! %s link %s %s",
135-
hl_def.default and "default" or "",
136-
hl_name, hl_def.link))
137-
else
138-
vim.cmd(string.format("hi! %s %s %s%s%s",
139-
hl_def.default and "default" or "", hl_name,
140-
hl_def.fg and string.format(" guifg=%s", hl_def.fg) or "",
141-
hl_def.bg and string.format(" guibg=%s", hl_def.bg) or "",
142-
hl_def.bold and " gui=bold" or ""))
143-
end
144-
end
130+
vim.api.nvim_set_hl(0, hl_name, hl_def)
145131
end
146132

147133
-- linking to a cleared hl is bugged in neovim 0.8.x
148134
-- resulting in a pink background for hls linked to `Normal`
149-
if vim.fn.has("nvim-0.9") == 0 and vim.fn.has("nvim-0.8") == 1 then
135+
if not utils.__HAS_NVIM_09 and utils.__HAS_NVIM_08 then
150136
for _, a in ipairs(highlights) do
151137
local hl_name, opt_name = a[1], a[2]
152138
if utils.is_hl_cleared(hl_name) then

0 commit comments

Comments
 (0)