Skip to content

Commit 4428ba2

Browse files
committed
feat(ui): add structured title chunks and highlights
1 parent 8e5eb7b commit 4428ba2

12 files changed

Lines changed: 321 additions & 69 deletions

File tree

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ Configure via `require("peekstack").setup({ ... })`.
148148
},
149149
title = {
150150
enabled = true,
151-
format = "{provider} · {path}:{line}{context}",
152-
breadcrumbs = true,
151+
format = "{kind}{provider} {path}:{line}{context}",
153152
context = {
154153
enabled = false,
155154
max_depth = 5,

doc/peekstack.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ With options:
3232
},
3333
title = {
3434
enabled = true,
35-
format = "{provider} · {path}:{line}{context}",
36-
breadcrumbs = true,
35+
format = "{kind}{provider} {path}:{line}{context}",
3736
context = {
3837
enabled = false,
3938
max_depth = 5,

lua/peekstack/config.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ M.defaults = {
8181
},
8282
title = {
8383
enabled = true,
84-
format = "{kind}{provider} · {path}:{line}{context}",
85-
breadcrumbs = true,
84+
format = "{kind}{provider} {path}:{line}{context}",
8685
context = {
8786
enabled = false,
8887
max_depth = 5,

lua/peekstack/core/popup.lua

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ local function capture_origin_from_win(winid)
100100
end
101101

102102
---@param location PeekstackLocation
103-
---@param opts? { buffer_mode?: "copy"|"source", title?: string, editable?: boolean, ephemeral?: boolean, origin_winid?: integer }
103+
---@param opts? { buffer_mode?: "copy"|"source", title?: string|PeekstackTitleChunk[], editable?: boolean, ephemeral?: boolean, origin_winid?: integer }
104104
---@return PeekstackPopupModel?
105105
function M.create(location, opts)
106106
opts = opts or {}
@@ -167,12 +167,27 @@ function M.create(location, opts)
167167
return nil
168168
end
169169

170-
local title = win_opts.title
170+
local title = nil
171+
local title_chunks = nil
172+
if win_opts.title ~= nil then
173+
if type(win_opts.title) == "table" then
174+
title_chunks = win_opts.title
175+
end
176+
title = render.title_text(win_opts.title)
177+
if title == "" then
178+
title = nil
179+
title_chunks = nil
180+
end
181+
end
171182
if opts.title and opts.title ~= "" then
172-
title = opts.title
173183
win_opts.title = opts.title
174184
win_opts.title_pos = "center"
175185
pcall(vim.api.nvim_win_set_config, winid, win_opts)
186+
title = render.title_text(opts.title)
187+
title_chunks = nil
188+
if title == "" then
189+
title = nil
190+
end
176191
end
177192
set_cursor(winid, location, line_offset)
178193

@@ -194,6 +209,7 @@ function M.create(location, opts)
194209
origin_bufnr = origin.bufnr,
195210
origin_is_popup = origin_is_popup,
196211
title = title,
212+
title_chunks = title_chunks,
197213
pinned = false,
198214
buffer_mode = buffer_mode,
199215
line_offset = line_offset,

lua/peekstack/core/stack.lua

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ local function close_stack_item(stack, idx, item)
184184
local history_entry = {
185185
location = item.location,
186186
title = item.title,
187+
title_chunks = item.title_chunks,
187188
pinned = item.pinned,
188189
buffer_mode = item.buffer_mode or "copy",
189190
source_bufnr = item.source_bufnr,
@@ -265,10 +266,15 @@ end
265266
local function restore_entry(stack, entry)
266267
deps()
267268
local create_opts = {
268-
title = entry.title,
269269
buffer_mode = entry.buffer_mode or "copy",
270270
origin_winid = stack.root_winid,
271271
}
272+
-- Only pass title override for user-renamed popups (no title_chunks).
273+
-- Auto-generated titles are regenerated by build_title() to preserve
274+
-- structured chunks for popup window and stack view highlighting.
275+
if not entry.title_chunks then
276+
create_opts.title = entry.title
277+
end
272278

273279
-- For source mode, check if the source buffer is still valid
274280
if create_opts.buffer_mode == "source" and entry.source_bufnr then
@@ -448,11 +454,14 @@ function M.reopen_by_id(id, winid)
448454
local stack = ensure_stack(winid)
449455
for idx, item in ipairs(stack.popups) do
450456
if item.id == id then
451-
local model = popup.create(item.location, {
452-
title = item.title,
457+
local reopen_opts = {
453458
buffer_mode = item.buffer_mode or "copy",
454459
origin_winid = stack.root_winid,
455-
})
460+
}
461+
if not item.title_chunks then
462+
reopen_opts.title = item.title
463+
end
464+
local model = popup.create(item.location, reopen_opts)
456465
if not model then
457466
return nil
458467
end
@@ -522,6 +531,7 @@ function M.handle_win_closed(winid)
522531
local history_entry = {
523532
location = item.location,
524533
title = item.title,
534+
title_chunks = item.title_chunks,
525535
pinned = item.pinned,
526536
buffer_mode = item.buffer_mode or "copy",
527537
source_bufnr = item.source_bufnr,
@@ -566,6 +576,7 @@ function M.rename_by_id(id, title, winid)
566576
for _, item in ipairs(stack.popups) do
567577
if item.id == id then
568578
item.title = title
579+
item.title_chunks = nil
569580
return true
570581
end
571582
end
@@ -774,6 +785,7 @@ function M.close_all(winid)
774785
local history_entry = {
775786
location = item.location,
776787
title = item.title,
788+
title_chunks = item.title_chunks,
777789
pinned = item.pinned,
778790
buffer_mode = item.buffer_mode or "copy",
779791
source_bufnr = item.source_bufnr,

lua/peekstack/init.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ local function set_hl()
2020
vim.api.nvim_set_hl(0, "PeekstackStackViewEmpty", { default = true, link = "Comment" })
2121
vim.api.nvim_set_hl(0, "PeekstackStackViewCursorLine", { default = true, link = "CursorLine" })
2222
vim.api.nvim_set_hl(0, "PeekstackInlinePreview", { default = true, link = "Comment" })
23+
vim.api.nvim_set_hl(0, "PeekstackTitleProvider", { default = true, link = "Type" })
24+
vim.api.nvim_set_hl(0, "PeekstackTitlePath", { default = true, link = "Directory" })
25+
vim.api.nvim_set_hl(0, "PeekstackTitleKindError", { default = true, link = "DiagnosticError" })
26+
vim.api.nvim_set_hl(0, "PeekstackTitleKindWarn", { default = true, link = "DiagnosticWarn" })
27+
vim.api.nvim_set_hl(0, "PeekstackTitleKindInfo", { default = true, link = "DiagnosticInfo" })
28+
vim.api.nvim_set_hl(0, "PeekstackTitleKindHint", { default = true, link = "DiagnosticHint" })
2329
end
2430

2531
---@param name string

lua/peekstack/types.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@
8383
---@field separator string
8484
---@field node_types table<string, string[]>
8585

86+
---@class PeekstackTitleChunk
87+
---@field [1] string
88+
---@field [2]? string
89+
8690
---@class PeekstackStoreData
8791
---@field version integer
8892
---@field sessions table<string, PeekstackSession>
@@ -142,7 +146,6 @@
142146
---@class PeekstackConfigTitle
143147
---@field enabled boolean
144148
---@field format string
145-
---@field breadcrumbs boolean
146149
---@field context PeekstackConfigTitleContext
147150

148151
---@class PeekstackConfigPath

0 commit comments

Comments
 (0)