Skip to content

Commit c73aac6

Browse files
authored
Merge pull request #21 from mhiro2/fix/source-keymaps-layout-safety-grep-marks-cleanup
fix: Harden source-mode popups, providers, and persistence safeguards
2 parents ca91301 + 43373fc commit c73aac6

19 files changed

Lines changed: 581 additions & 103 deletions

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ Configure via `require("peekstack").setup({ ... })`.
247247
file = { enable = true },
248248
marks = {
249249
enable = false,
250-
scope = "all", -- "buffer" | "global" | "all"
251250
include = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
252251
include_special = false,
253252
},

doc/peekstack.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ With options:
113113
file = { enable = true },
114114
marks = {
115115
enable = false,
116-
scope = "all", -- "buffer" | "global" | "all"
117116
include = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
118117
include_special = false,
119118
},

lua/peekstack/config.lua

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ local KNOWN_BUFFER_MODES = { "copy", "source" }
1616
---@type string[]
1717
local KNOWN_RESTORE_POSITIONS = { "top", "original" }
1818

19-
---@type string[]
20-
local KNOWN_MARK_SCOPES = { "buffer", "global", "all" }
21-
2219
---@type string[]
2320
local KNOWN_PATH_BASES = { "repo", "cwd", "absolute" }
2421

@@ -171,7 +168,6 @@ M.defaults = {
171168
file = { enable = true },
172169
marks = {
173170
enable = false,
174-
scope = "all",
175171
include = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
176172
include_special = false,
177173
},
@@ -443,7 +439,6 @@ local LAYOUT_OFFSET_RULES = {
443439

444440
---@type PeekstackConfigFieldRule[]
445441
local MARKS_RULES = {
446-
{ key = "scope", validate = field_enum(KNOWN_MARK_SCOPES), require_truthy = true },
447442
{ key = "include", validate = field_type("string") },
448443
{ key = "include_special", validate = field_type("boolean") },
449444
}

lua/peekstack/core/events.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ function M.setup()
7272
reset_reflow_timer()
7373
popup_cursor_buffers = {}
7474
local group = vim.api.nvim_create_augroup("PeekstackEvents", { clear = true })
75+
local keymaps = require("peekstack.ui.keymaps")
7576

7677
vim.api.nvim_create_autocmd("WinClosed", {
7778
group = group,
@@ -105,6 +106,7 @@ function M.setup()
105106
local bufnr = vim.api.nvim_win_get_buf(winid)
106107
ensure_popup_cursor_tracking(group, bufnr)
107108
end
109+
keymaps.activate_source_popup(winid)
108110
if is_floating_window(winid) then
109111
stack.touch(winid)
110112
local layout = require("peekstack.core.layout")
@@ -116,9 +118,17 @@ function M.setup()
116118
end,
117119
})
118120

121+
vim.api.nvim_create_autocmd("WinLeave", {
122+
group = group,
123+
callback = function()
124+
keymaps.deactivate_source_popup(vim.api.nvim_get_current_win())
125+
end,
126+
})
127+
119128
local current_winid = vim.api.nvim_get_current_win()
120129
if vim.w[current_winid].peekstack_popup_id ~= nil then
121130
ensure_popup_cursor_tracking(group, vim.api.nvim_win_get_buf(current_winid))
131+
keymaps.activate_source_popup(current_winid)
122132
end
123133

124134
local cfg = config.get()
@@ -139,8 +149,9 @@ function M.setup()
139149
end,
140150
})
141151

152+
local cleanup = require("peekstack.core.cleanup")
153+
cleanup.stop()
142154
if cfg.ui.popup.auto_close and cfg.ui.popup.auto_close.enabled then
143-
local cleanup = require("peekstack.core.cleanup")
144155
cleanup.start()
145156
end
146157
end

lua/peekstack/core/layout.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function M.reflow(stack)
145145
height = lo.height,
146146
zindex = z,
147147
})
148-
vim.api.nvim_win_set_config(popup.winid, win_opts)
148+
pcall(vim.api.nvim_win_set_config, popup.winid, win_opts)
149149
if is_zoomed then
150150
set_popup_zoom_winhighlight(popup.winid, true)
151151
else

lua/peekstack/core/popup.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ end
252252

253253
---@param popup PeekstackPopupModel
254254
function M.close(popup)
255+
-- Remove source-mode keymaps before closing the window so they do not
256+
-- leak into normal editing of the shared buffer.
257+
require("peekstack.ui.keymaps").remove_popup(popup)
255258
diagnostics_ui.clear(popup.diagnostics)
256259
if popup.winid and vim.api.nvim_win_is_valid(popup.winid) then
257260
vim.api.nvim_win_close(popup.winid, true)

lua/peekstack/persist/store.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ function M.read(scope, opts)
7272
vim.schedule(function()
7373
local ok, decoded = pcall(vim.json.decode, data)
7474
if not ok or type(decoded) ~= "table" then
75+
notify.warn("Failed to decode session data: " .. path)
7576
on_done(empty_data())
7677
return
7778
end
@@ -104,6 +105,7 @@ function M.read_sync(scope)
104105

105106
local ok, decoded = pcall(vim.json.decode, data)
106107
if not ok or type(decoded) ~= "table" then
108+
notify.warn("Failed to decode session data: " .. path)
107109
return empty_data()
108110
end
109111
return decoded

lua/peekstack/providers/file.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ function M.under_cursor(ctx, cb)
1616
local source_name = vim.api.nvim_buf_get_name(ctx.bufnr)
1717
local base = vim.fn.fnamemodify(source_name, ":p:h")
1818
target = vim.fn.fnamemodify(base .. "/" .. target, ":p")
19+
20+
local stat = vim.uv.fs_stat(target)
21+
if not stat or stat.type ~= "file" then
22+
cb({})
23+
return
24+
end
1925
end
2026
local uri = fs.fname_to_uri(target)
2127
local loc = location.normalize(

lua/peekstack/providers/grep.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function M.search(_, cb)
5353
return
5454
end
5555

56-
vim.system({ "rg", "--vimgrep", query }, { text = true }, function(result)
56+
vim.system({ "rg", "--vimgrep", "--max-count=1000", "--", query }, { text = true }, function(result)
5757
vim.schedule(function()
5858
if result.code ~= 0 and result.code ~= 1 then
5959
notify.warn("rg failed: " .. (result.stderr or "unknown error"))

lua/peekstack/types.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@
277277

278278
---@class PeekstackConfigProviderMarks
279279
---@field enable boolean
280-
---@field scope "buffer"|"global"|"all"
281280
---@field include string
282281
---@field include_special boolean
283282

0 commit comments

Comments
 (0)