Skip to content

Commit

Permalink
fix(profiles): do not override title_pos (closes #1690)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibhagwan committed Jan 9, 2025
1 parent c5d53ee commit 446c5a5
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 14 deletions.
12 changes: 12 additions & 0 deletions OPTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,18 @@ Type: `boolean`, Default: `false`

Use fullscreen for the fzf-load floating window.

#### globals.winopts.title

Type: `string`, Default: `nil`

Controls title display in the fzf window, set by the calling picker.

#### globals.winopts.title_pos

Type: `string`, Default: `center`

Controls title display in the fzf window, possible values are `left|right|center`.

#### globals.winopts.treesitter

Type: `boolean`, Default: `false`
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ winopts = {
-- Backdrop opacity, 0 is fully opaque, 100 is fully transparent (i.e. disabled)
backdrop = 60,
-- title = "Title",
-- title_pos = "center", -- 'left', 'center' or 'right'
-- title_pos = "center", -- 'left', 'center' or 'right'
fullscreen = false, -- start fullscreen?
-- enable treesitter highlighting for the main fzf window will only have
-- effect where grep like results are present, i.e. "file:line:col:text"
Expand Down
19 changes: 18 additions & 1 deletion doc/fzf-lua-opts.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*fzf-lua-opts.txt* For Neovim >= 0.8.0 Last change: 2025 January 05
*fzf-lua-opts.txt* For Neovim >= 0.8.0 Last change: 2025 January 06

==============================================================================
Table of Contents *fzf-lua-opts-table-of-contents*
Expand Down Expand Up @@ -378,6 +378,23 @@ Use fullscreen for the fzf-load floating window.



globals.winopts.title *fzf-lua-opts-globals.winopts.title*

Type: `string`, Default: `nil`

Controls title display in the fzf window, set by the calling picker.



globals.winopts.title_pos *fzf-lua-opts-globals.winopts.title_pos*

Type: `string`, Default: `center`

Controls title display in the fzf window, possible values are
`left|right|center`.



globals.winopts.treesitter *fzf-lua-opts-globals.winopts.treesitter*

Type: `boolean`, Default: `false`
Expand Down
4 changes: 2 additions & 2 deletions doc/fzf-lua.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*fzf-lua.txt* For Neovim >= 0.5.0 Last change: 2025 January 06
*fzf-lua.txt* For Neovim >= 0.5.0 Last change: 2025 January 09

==============================================================================
Table of Contents *fzf-lua-table-of-contents*
Expand Down Expand Up @@ -425,7 +425,7 @@ CUSTOMIZATION *fzf-lua-customization*
-- Backdrop opacity, 0 is fully opaque, 100 is fully transparent (i.e. disabled)
backdrop = 60,
-- title = "Title",
-- title_pos = "center", -- 'left', 'center' or 'right'
-- title_pos = "center", -- 'left', 'center' or 'right'
fullscreen = false, -- start fullscreen?
-- enable treesitter highlighting for the main fzf window will only have
-- effect where grep like results are present, i.e. "file:line:col:text"
Expand Down
1 change: 1 addition & 0 deletions lua/fzf-lua/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ M.defaults = {
zindex = 50,
backdrop = 60,
fullscreen = false,
title_pos = "center",
treesitter = {
enabled = false,
fzf_colors = { ["hl"] = "-1:reverse", ["hl+"] = "-1:reverse" }
Expand Down
5 changes: 2 additions & 3 deletions lua/fzf-lua/profiles/default-title.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ local function title(str, opts)
winopts = {
-- title = { { " " .. str .. " ", "IncSearch" } },
title = " " .. str .. " ",
title_pos = "center",
}
})
end
return {
desc = "defaults using title instead of prompt",
defaults = { prompt = false },
winopts = { title_pos = "center" },
files = title("Files"),
buffers = title("Buffers"),
tabs = title("Tabs"),
Expand Down Expand Up @@ -43,8 +43,7 @@ return {
manpages = title("Man Pages"),
lsp = {
title_prefix = "LSP",
winopts = { title_pos = "center" },
symbols = { title_prefix = "LSP", winopts = { title_pos = "center" } },
symbols = { title_prefix = "LSP" },
finder = title("LSP Finder"),
code_actions = title("Code Actions"),
},
Expand Down
23 changes: 16 additions & 7 deletions lua/fzf-lua/win.lua
Original file line number Diff line number Diff line change
Expand Up @@ -775,12 +775,19 @@ function FzfWin:redraw_main()

self:generate_layout()

local winopts = vim.tbl_extend("keep", not utils.__HAS_NVIM_09 and {} or {
title = type(self.winopts.title) == "string" and type(self.hls.title) == "string"
and { { self.winopts.title, self.hls.title } }
or self.winopts.title,
title_pos = self.winopts.title_pos,
}, self.layout.fzf)
local winopts = vim.tbl_extend("keep", (function()
if not utils.__HAS_NVIM_09 or
(type(self.winopts.title) ~= "string" and type(self.winopts.title) ~= "table")
then
return {}
end
return {
title = type(self.winopts.title) == "string" and type(self.hls.title) == "string"
and { { self.winopts.title, self.hls.title } }
or self.winopts.title,
title_pos = self.winopts.title_pos,
}
end)(), self.layout.fzf)

if self:validate() then
if self._previewer
Expand Down Expand Up @@ -1298,7 +1305,9 @@ end

function FzfWin:update_preview_title(title)
-- neovim >= 0.9 added window title
if not utils.__HAS_NVIM_09 then return end
if not utils.__HAS_NVIM_09 or (type(title) ~= "string" and type(title) ~= "table") then
return
end
-- since `nvim_win_set_config` removes all styling, save backup
-- of the current options and restore after the call (#813)
local style = self:get_winopts(self.preview_winid, self._previewer:gen_winopts())
Expand Down

0 comments on commit 446c5a5

Please sign in to comment.