Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions pkgs/id/web/src/goto-line.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,25 @@ describe("dialog input interaction", () => {
expect(posAfter).toBeLessThanOrEqual(2);
});
});

// ── Editor recreation (#718) ───────────────────────────────────────

describe("goto-line dialog across editor recreation", () => {
it("Ctrl+G in a recreated editor shows a dialog in the new container without destroyGotoLineDialog()", () => {
const first = createViewWithGotoLine("first\nsecond");
triggerGotoLine(first.view);
expect(first.container.querySelector(".goto-line-dialog")).not.toBeNull();

// Production teardown (main.ts disconnect) destroys only the view —
// it never calls destroyGotoLineDialog(). Mirror that exactly.
first.view.destroy();
first.container.remove();

const second = createViewWithGotoLine("first\nsecond");
views.push(second.view);
containers.push(second.container);
triggerGotoLine(second.view);
expect(second.container.querySelector(".goto-line-dialog")).not.toBeNull();
expect(second.container.querySelector(".goto-line-input")).not.toBeNull();
});
});
9 changes: 9 additions & 0 deletions pkgs/id/web/src/goto-line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ function openGotoLine(view: EditorView): void {
const container = view.dom.parentElement;
if (!container) return;

// The dialog is a module singleton attached to one container. When the
// editor is recreated (disconnect / open another file) the old dialog is
// detached with the old container — and no production code calls
// destroyGotoLineDialog() on teardown. Rebind instead of "opening" a
// detached node (#718).
if (dialogEl && dialogEl.parentElement !== container) {
destroyGotoLineDialog();
}

if (!dialogEl) {
dialogEl = createDialog(container);
dialogInput = dialogEl.querySelector("#goto-line-input");
Expand Down
22 changes: 22 additions & 0 deletions pkgs/id/web/src/search-panel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,25 @@ describe("search panel integration", () => {
expect(panels.length).toBe(1);
});
});

// ── Editor recreation (#718) ───────────────────────────────────────

describe("search panel across editor recreation", () => {
it("Ctrl+F in a recreated editor shows a panel in the new container without destroySearchPanel()", () => {
const first = createViewWithSearch();
triggerSearchKey(first.view, "f");
expect(first.container.querySelector(".search-panel")).not.toBeNull();

// Production teardown (main.ts disconnect) destroys only the view —
// it never calls destroySearchPanel(). Mirror that exactly.
first.view.destroy();
first.container.remove();

const second = createViewWithSearch();
activeView = second.view;
activeContainer = second.container;
triggerSearchKey(second.view, "f");
expect(second.container.querySelector(".search-panel")).not.toBeNull();
expect(second.container.querySelector("#search-input")).not.toBeNull();
});
});
9 changes: 9 additions & 0 deletions pkgs/id/web/src/search-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,15 @@ function openPanel(view: EditorView, showReplace: boolean): void {
const container = view.dom.parentElement;
if (!container) return;

// The panel is a module singleton bound to one view and container. When
// the editor is recreated (disconnect / open another file) the old panel
// is detached with the old container and its handlers still point at the
// destroyed view — and no production code calls destroySearchPanel() on
// teardown. Rebind instead of "opening" a detached node (#718).
if (panelState.panelEl && (panelState.view !== view || panelState.panelEl.parentElement !== container)) {
destroySearchPanel();
}

if (!panelState.panelEl) {
panelState.panelEl = createPanel(container);
panelState.searchInput = panelState.panelEl.querySelector("#search-input");
Expand Down
Loading