Share card relayout between resize and reparent #15
No files matched your search
@@ -20,6 +20,7 @@
|
||||
### Changed
|
||||
|
||||
- Simplify quickfix setup and remove unused test helpers and redundant tests.
|
||||
- Share card layout code between resizing and moving to another split.
|
||||
|
||||
## [0.1.0] - 2026-09-30
|
||||
|
||||
|
||||
@@ -189,6 +189,13 @@ function M.open(frame, parent)
|
||||
return true
|
||||
end
|
||||
|
||||
local function relayout()
|
||||
backdrop.resize(dim, parent)
|
||||
local context_config, comment_config = placement(layout())
|
||||
vim.api.nvim_win_set_config(context_win, context_config)
|
||||
vim.api.nvim_win_set_config(comment_win, comment_config)
|
||||
end
|
||||
|
||||
local function watch_parent()
|
||||
vim.api.nvim_create_autocmd("WinClosed", {
|
||||
group = group,
|
||||
@@ -235,10 +242,7 @@ function M.open(frame, parent)
|
||||
end
|
||||
if replacement then
|
||||
parent = replacement
|
||||
backdrop.resize(dim, parent)
|
||||
local context_next, comment_next = placement(layout())
|
||||
vim.api.nvim_win_set_config(context_win, context_next)
|
||||
vim.api.nvim_win_set_config(comment_win, comment_next)
|
||||
relayout()
|
||||
watch_parent()
|
||||
end
|
||||
end)
|
||||
@@ -260,10 +264,7 @@ function M.open(frame, parent)
|
||||
if not vim.api.nvim_win_is_valid(parent) then
|
||||
return
|
||||
end
|
||||
backdrop.resize(dim, parent)
|
||||
local context_resized, comment_resized = placement(layout())
|
||||
vim.api.nvim_win_set_config(context_win, context_resized)
|
||||
vim.api.nvim_win_set_config(comment_win, comment_resized)
|
||||
relayout()
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
@@ -139,7 +139,8 @@ describe("the comment window", function()
|
||||
expect.equality(config.width <= vim.api.nvim_win_get_width(record.source_win), true)
|
||||
end)
|
||||
|
||||
it("keeps unsaved edits when the source window closes", function()
|
||||
it("moves the whole card and keeps unsaved edits when the source window closes", function()
|
||||
local floats = helpers.every_float()
|
||||
local record = assert(require("scratch_comments.ui.window").current())
|
||||
---@cast record { comment_win: integer, source_win: integer }
|
||||
local comment_buf = vim.api.nvim_win_get_buf(record.comment_win)
|
||||
@@ -153,6 +154,9 @@ describe("the comment window", function()
|
||||
local parent = assert(vim.api.nvim_win_get_config(record.comment_win).win)
|
||||
expect.equality(vim.api.nvim_win_is_valid(parent), true)
|
||||
expect.no_equality(vim.bo[vim.api.nvim_win_get_buf(parent)].buftype, "quickfix")
|
||||
for _, win in ipairs(floats) do
|
||||
expect.equality(vim.api.nvim_win_get_config(win).win, parent)
|
||||
end
|
||||
end)
|
||||
|
||||
it("closes a clean card if its source window was the last file pane", function()
|
||||
|
||||
Reference in new issue
Block a user