Skip to content
Open
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
13 changes: 10 additions & 3 deletions src/canvas/selectionPresentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type SelectionChrome = {

export const SELECTION_TITLE_SPACE = 32;
const TITLE_SPACE = SELECTION_TITLE_SPACE;
const NODE_TOP_CONTROLS_SPACE = 40;
const TOOLBAR_GAP = 8;
const COMPOSER_GAP = 16;
const clamp = (value: number, min: number, max: number) =>
Expand Down Expand Up @@ -209,12 +210,18 @@ export function selectionPlacement(
const bottom = top + projected.height;
const left = (width: number) =>
clamp(center - width / 2, safe.x, safe.x + safe.width - width);
const toolbarTop = Math.max(safe.y, top - TITLE_SPACE - TOOLBAR_GAP - toolbar.height);
const headingTop = top - TITLE_SPACE * view.zoom;
const controlsBottom = top + NODE_TOP_CONTROLS_SPACE * view.zoom;
const coversNodeControls = toolbar.height > 0 && toolbarTop === safe.y &&
toolbarTop < controlsBottom && toolbarTop + toolbar.height > headingTop;
const belowNode = bottom + TOOLBAR_GAP;
const fitsBelowNode = composer.height === 0 && belowNode + toolbar.height <= safe.y + safe.height;
const fallbackTop = fitsBelowNode ? belowNode : controlsBottom + TOOLBAR_GAP;
return {
toolbar: {
left: left(toolbar.width),
// Never above the safe area: the top bar's global controls sit there and
// the toolbar would intercept their clicks when the node is near the top.
top: Math.max(safe.y, top - TITLE_SPACE - TOOLBAR_GAP - toolbar.height),
top: coversNodeControls ? fallbackTop : toolbarTop,
},
composer: {
left: scaleComposer
Expand Down
36 changes: 36 additions & 0 deletions tests/browser/canvas_toolbar_topbar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,42 @@ async function verify(browser, locale, zoom) {
assert.deepEqual(await steadyViewport(), [afterPan], "The pan is not undone by automatic fitting");
await expectClear("after manual pan");

if (zoom === 1) {
const title = node(fixture.second).locator(".cw-node-title");
const titleBox = await title.boundingBox();
const workspace = await page.locator(".cw-workspace").boundingBox();
const offset = workspace.y + 90 - (titleBox.y + titleBox.height / 2);
await page.mouse.move(750, 700);
await page.mouse.down({ button: "middle" });
await page.mouse.move(750, 700 + offset, { steps: 6 });
await page.mouse.up({ button: "middle" });
assert.equal((await steadyViewport()).length, 1, "The rename position stays stable");
await expectClear("near the upper canvas edge");
const hit = await title.evaluate((element) => {
const bounds = element.getBoundingClientRect();
const target = document.elementFromPoint(
bounds.x + bounds.width / 2, bounds.y + bounds.height / 2,
);
return {
title: element.contains(target),
target: target?.className,
titleBounds: bounds.toJSON(),
toolbarBounds: document.querySelector(".cw-node-toolbar-anchor").getBoundingClientRect().toJSON(),
};
});
if (locale === "en-US" && process.env.CANVAS_TOOLBAR_RENAME_SCREENSHOT)
await page.screenshot({ path: process.env.CANVAS_TOOLBAR_RENAME_SCREENSHOT });
assert.ok(hit.title, `The node title receives the pointer: ${JSON.stringify(hit)}`);
await title.dblclick({ timeout: 5000 });
const input = node(fixture.second).locator(".cw-node-title-input");
await input.waitFor();
await input.press("Escape");
await input.waitFor({ state: "detached" });
await presets.click({ timeout: 5000 });
assert.equal(await presets.getAttribute("aria-expanded"), "true");
await page.keyboard.press("Escape");
}

// 4. Switching away and back restores the canvas.
await picker.click({ timeout: 5000 });
await page.getByRole("menuitemradio", { name: fixture.b.name, exact: true }).click();
Expand Down
17 changes: 16 additions & 1 deletion tests/canvasSelectionPresentation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ test("toolbar never rises above the safe area into the top bar (#513)", () => {
{ x: 0, y: 0, zoom: 1.5 },
]) {
const placed = selectionPlacement(node, viewport, chrome);
assert.equal(placed.toolbar.top, chrome.safe.y, JSON.stringify(viewport));
assert.ok(placed.toolbar.top >= chrome.safe.y, JSON.stringify(viewport));
assert.equal(placed.visible, true);
}
// A fitted selection keeps the ordinary anchored position above the node.
Expand All @@ -126,6 +126,21 @@ test("toolbar never rises above the safe area into the top bar (#513)", () => {
);
});

test("a clamped toolbar leaves the selected node title and history control reachable (#693)", () => {
const node = { x: 240, y: 118, width: 300, height: 300 };
const chrome: SelectionChrome = {
safe: { x: 80, y: 72, width: 1100, height: 850 },
toolbar: { width: 500, height: 36 },
composer: { width: 0, height: 0 },
};
const view = { x: 0, y: 0, zoom: 1 };
assert.ok(selectionPlacement(node, view, chrome).toolbar.top > node.y + node.height);
const withComposer = { ...chrome, composer: { width: 500, height: 300 } };
const placement = selectionPlacement(node, { ...view, y: -50 }, withComposer);
assert.ok(placement.toolbar.top >= node.y - 50 + 40);
assert.ok(placement.toolbar.top + withComposer.toolbar.height < placement.composer.top);
});

test("fitting a distant node preserves its screen center while reducing zoom", () => {
const node = { x: 10000, y: 8000, width: 600, height: 600 };
const view = { x: 640 - 10300, y: 200 - 8000, zoom: 1 };
Expand Down
Loading