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
4 changes: 2 additions & 2 deletions src/renderer/src/features/workspace/canvasStacking.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { CameraState, SessionBounds } from "../../../../shared/contracts";

export function reconcileCanvasLayerOrder(
current: readonly string[],
current: string[],
active: readonly string[]
): string[] {
const activeSet = new Set(active);
const next = current.filter((id, index) => activeSet.has(id) && current.indexOf(id) === index);
for (const id of active) {
if (!next.includes(id)) next.push(id);
}
return next;
return next.length === current.length && next.every((id, index) => id === current[index]) ? current : next;
}

export function bringCanvasLayerToFront(current: readonly string[], id: string): string[] {
Expand Down
6 changes: 6 additions & 0 deletions tests/canvas-stacking.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ test("layer reconciliation keeps user order and appends only new live windows",
);
});

test("an unchanged layer order reconciles to the same array", () => {
const order = ["browser", "terminal:a", "note:n"];
assert.equal(reconcileCanvasLayerOrder(order, ["note:n", "terminal:a", "browser"]), order);
assert.notEqual(reconcileCanvasLayerOrder(order, ["terminal:a", "browser"]), order);
});

test("the native Browser surface is hidden only under a higher overlapping layer", () => {
const map = new Map([
["browser", bounds(0, 0)],
Expand Down