mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-17 05:45:07 +00:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6c94ab046f | ||
|
|
aa1e4c8ad6 | ||
|
|
9fe97efb34 | ||
|
|
cfd32891f5 | ||
|
|
7792a1d697 | ||
|
|
eacbbfca80 | ||
|
|
976e47ae3f |
@@ -718,3 +718,108 @@ test.describe("Half-screen desktop layout", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// An iPad in the browser runs the desktop layout with the sidebar pinned, but it can't hover,
|
||||
// and iOS Safari fires no contextmenu event for a long press. The kebab is the only way in.
|
||||
test.describe("Workspace row menu on a wide touch screen", () => {
|
||||
test.use({ viewport: { width: 1194, height: 834 }, isMobile: true, hasTouch: true });
|
||||
|
||||
test("shows the row's menu button without hovering and opens it with a tap", async ({
|
||||
page,
|
||||
}, info) => {
|
||||
const workspace = await seedWorkspace({ repoPrefix: "sidebar-touch-menu-" });
|
||||
const workspaceKey = `${getServerId()}:${workspace.workspaceId}`;
|
||||
|
||||
try {
|
||||
await gotoAppShell(page);
|
||||
await waitForSidebarWorkspace(page, workspace.workspaceId);
|
||||
const kebab = page.getByTestId(`sidebar-workspace-kebab-${workspaceKey}`);
|
||||
await expect(kebab).toBeVisible({ timeout: 30_000 });
|
||||
await expect(kebab).toHaveCSS("opacity", "1");
|
||||
await page.screenshot({ path: info.outputPath("touch-sidebar-row-menu.png") });
|
||||
await kebab.tap();
|
||||
await expect(
|
||||
page.getByTestId(`sidebar-workspace-menu-copy-path-${workspaceKey}`),
|
||||
).toBeVisible({ timeout: 30_000 });
|
||||
} finally {
|
||||
await workspace.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test("resizes the sidebar with a finger drag on its grip", async ({ page, context }, info) => {
|
||||
await gotoAppShell(page);
|
||||
const grip = page.getByTestId("left-sidebar-resize-handle");
|
||||
await expect(grip).toBeVisible({ timeout: 30_000 });
|
||||
const before = await grip.boundingBox();
|
||||
if (!before) throw new Error("The sidebar resize grip has no box");
|
||||
const x = before.x + before.width / 2;
|
||||
const y = before.y + before.height / 2;
|
||||
// Nothing else may sit on top of the grip, or a finger can't reach it.
|
||||
const hit = await page.evaluate(
|
||||
({ px, py }) =>
|
||||
document.elementFromPoint(px, py)?.closest("[data-testid]")?.getAttribute("data-testid"),
|
||||
{ px: x, py: y },
|
||||
);
|
||||
expect(hit).toBe("left-sidebar-resize-handle");
|
||||
|
||||
const cdp = await context.newCDPSession(page);
|
||||
await cdp.send("Input.dispatchTouchEvent", {
|
||||
type: "touchStart",
|
||||
touchPoints: [{ x, y, id: 1 }],
|
||||
});
|
||||
for (let step = 1; step <= 10; step += 1) {
|
||||
await cdp.send("Input.dispatchTouchEvent", {
|
||||
type: "touchMove",
|
||||
touchPoints: [{ x: x + step * 8, y, id: 1 }],
|
||||
});
|
||||
}
|
||||
await cdp.send("Input.dispatchTouchEvent", { type: "touchEnd", touchPoints: [] });
|
||||
|
||||
await expect
|
||||
.poll(async () => (await grip.boundingBox())?.x ?? before.x, { timeout: 10_000 })
|
||||
.toBeGreaterThan(before.x + 40);
|
||||
await page.screenshot({ path: info.outputPath("touch-sidebar-resized.png") });
|
||||
});
|
||||
});
|
||||
|
||||
// A touch-screen laptop driven by a mouse reports a coarse pointer among its pointers, but its
|
||||
// primary pointer hovers, so rows keep revealing their menu on hover.
|
||||
test.describe("Workspace row menu on a touch-screen laptop with a mouse", () => {
|
||||
test.use({ viewport: { width: 1440, height: 900 } });
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.addInitScript(() => {
|
||||
const browserMatchMedia = window.matchMedia.bind(window);
|
||||
window.matchMedia = (query: string) => {
|
||||
const result = browserMatchMedia(query);
|
||||
if (query !== "(any-pointer: coarse)") return result;
|
||||
return new Proxy(result, {
|
||||
get: (target, key) => {
|
||||
if (key === "matches") return true;
|
||||
const value: unknown = Reflect.get(target, key, target);
|
||||
return typeof value === "function" ? value.bind(target) : value;
|
||||
},
|
||||
});
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
test("keeps the row's menu button behind hover", async ({ page }) => {
|
||||
const workspace = await seedWorkspace({ repoPrefix: "sidebar-hybrid-menu-" });
|
||||
const workspaceKey = `${getServerId()}:${workspace.workspaceId}`;
|
||||
|
||||
try {
|
||||
await gotoAppShell(page);
|
||||
const row = await waitForSidebarWorkspace(page, workspace.workspaceId);
|
||||
expect(await page.evaluate(() => window.matchMedia("(any-pointer: coarse)").matches)).toBe(
|
||||
true,
|
||||
);
|
||||
const kebab = page.getByTestId(`sidebar-workspace-kebab-${workspaceKey}`);
|
||||
await expect(kebab).toHaveCount(0);
|
||||
await row.hover();
|
||||
await expect(kebab).toBeVisible({ timeout: 10_000 });
|
||||
} finally {
|
||||
await workspace.cleanup();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,6 +12,20 @@ describe("resolveSidebarResizeHandleGeometry", () => {
|
||||
expect(geometry.height ?? 0).toBeGreaterThanOrEqual(MIN_TOUCH_TARGET);
|
||||
});
|
||||
|
||||
it("keeps a web touch grip inside the sidebar, level with the top navigation rows", () => {
|
||||
const geometry = resolveSidebarResizeHandleGeometry(false, true);
|
||||
|
||||
// The sidebar clips its overflow, so a grip outside it can't be touched.
|
||||
expect(geometry.edgeOffset).toBeGreaterThanOrEqual(0);
|
||||
expect(geometry.width).toBeGreaterThanOrEqual(MIN_TOUCH_TARGET);
|
||||
// Not centred, where it would cover a row's menu button.
|
||||
expect(geometry.top).toBe(48);
|
||||
});
|
||||
|
||||
it("centres the native touch grip", () => {
|
||||
expect(resolveSidebarResizeHandleGeometry(false).top).toBeNull();
|
||||
});
|
||||
|
||||
it("straddles the border for a fine pointer", () => {
|
||||
const geometry = resolveSidebarResizeHandleGeometry(true);
|
||||
|
||||
|
||||
@@ -10,6 +10,13 @@
|
||||
* children whose ancestors contain the point. A strip hanging outside the
|
||||
* sidebar is dead on touch, and what remains is far too small for a finger.
|
||||
* So the touch variant sits fully inside the sidebar and is sized for a thumb.
|
||||
*
|
||||
* A touch screen on the web (an iPad in the browser) shows every row's menu button
|
||||
* at the sidebar's right edge, and a grip centred on that edge covers the menu of
|
||||
* whichever row is at mid-height. The grip can't move outside the sidebar either:
|
||||
* the sidebar clips its overflow, which in a browser also clips hit-testing. So on
|
||||
* the web the touch grip stays inside and sits level with the top navigation rows
|
||||
* (New workspace, History, Search...), which have nothing at their right edge.
|
||||
*/
|
||||
|
||||
export const POINTER_HANDLE_WIDTH = 10;
|
||||
@@ -37,21 +44,29 @@ export interface SidebarResizeHandleGeometry {
|
||||
width: number;
|
||||
/** `null` stretches the hit area to the sidebar's full height. */
|
||||
height: number | null;
|
||||
/** Distance from the sidebar's top to the hit area; `null` centres it vertically. */
|
||||
top: number | null;
|
||||
}
|
||||
|
||||
/** The web touch grip's distance from the sidebar top: beside the top navigation rows. */
|
||||
export const WEB_TOUCH_HANDLE_TOP = 48;
|
||||
|
||||
export function resolveSidebarResizeHandleGeometry(
|
||||
finePointer: boolean,
|
||||
web = false,
|
||||
): SidebarResizeHandleGeometry {
|
||||
if (finePointer) {
|
||||
return {
|
||||
edgeOffset: -POINTER_HANDLE_WIDTH / 2,
|
||||
width: POINTER_HANDLE_WIDTH,
|
||||
height: null,
|
||||
top: null,
|
||||
};
|
||||
}
|
||||
return {
|
||||
edgeOffset: 0,
|
||||
width: TOUCH_HANDLE_WIDTH,
|
||||
height: TOUCH_HANDLE_HEIGHT,
|
||||
top: web ? WEB_TOUCH_HANDLE_TOP : null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -85,14 +85,24 @@ function PointerResizeHandle({ edge, gesture, testID }: SidebarResizeHandleProps
|
||||
);
|
||||
}
|
||||
|
||||
// On the web the grip shows at rest, so a touch user can find it.
|
||||
function restingGripStyle(pressed: boolean) {
|
||||
if (pressed) return styles.visibleGrip;
|
||||
if (isWeb) return styles.restingGrip;
|
||||
return styles.hiddenGrip;
|
||||
}
|
||||
|
||||
function TouchResizeHandle({ edge, gesture, pressed, testID }: SidebarResizeHandleProps) {
|
||||
const geometry = resolveSidebarResizeHandleGeometry(false);
|
||||
const geometry = resolveSidebarResizeHandleGeometry(false, isWeb && edge === "right");
|
||||
// `box-none` keeps the full-height column out of hit-testing so only the
|
||||
// grab target steals taps from the rows behind it.
|
||||
const layerStyle = [
|
||||
styles.touchLayer,
|
||||
{ width: geometry.width },
|
||||
edgeOffsetStyle(edge, geometry.edgeOffset),
|
||||
geometry.top === null
|
||||
? null
|
||||
: { justifyContent: "flex-start" as const, paddingTop: geometry.top },
|
||||
];
|
||||
const targetStyle = [
|
||||
styles.touchTarget,
|
||||
@@ -101,7 +111,7 @@ function TouchResizeHandle({ edge, gesture, pressed, testID }: SidebarResizeHand
|
||||
const gripStyle = [
|
||||
styles.grip,
|
||||
edge === "left" ? styles.leftEdgeGrip : styles.rightEdgeGrip,
|
||||
pressed ? styles.visibleGrip : styles.hiddenGrip,
|
||||
restingGripStyle(pressed),
|
||||
];
|
||||
|
||||
return (
|
||||
@@ -159,7 +169,10 @@ const styles = StyleSheet.create((theme) => ({
|
||||
opacity: 0,
|
||||
},
|
||||
visibleGrip: {
|
||||
opacity: 0.3,
|
||||
opacity: 0.55,
|
||||
},
|
||||
restingGrip: {
|
||||
opacity: 0.35,
|
||||
},
|
||||
leftEdgeGrip: {
|
||||
alignSelf: "flex-start",
|
||||
|
||||
@@ -106,6 +106,7 @@ import {
|
||||
SidebarWorkspaceRowContent,
|
||||
SidebarWorkspaceShortcutBadge,
|
||||
resolveTrailingActionVisibility,
|
||||
useRowActionsAlwaysVisible,
|
||||
SidebarWorkspaceTrailingActionBase,
|
||||
SidebarWorkspaceTrailingActionOverlay,
|
||||
SidebarWorkspaceTrailingActionSlot,
|
||||
@@ -409,7 +410,6 @@ function ProjectRowTrailingActions({
|
||||
settingsTarget,
|
||||
projectPath,
|
||||
isHovered,
|
||||
isMobileBreakpoint,
|
||||
isProjectActive,
|
||||
onBeginWorkspaceSetup,
|
||||
onRemoveProject,
|
||||
@@ -421,13 +421,12 @@ function ProjectRowTrailingActions({
|
||||
settingsTarget: { serverId: string; projectId: string } | null;
|
||||
projectPath: string;
|
||||
isHovered: boolean;
|
||||
isMobileBreakpoint: boolean;
|
||||
isProjectActive: boolean;
|
||||
onBeginWorkspaceSetup: () => void;
|
||||
onRemoveProject?: () => void;
|
||||
removeProjectStatus: "idle" | "pending" | "success";
|
||||
}) {
|
||||
const actionsVisible = isHovered || platformIsNative || isMobileBreakpoint;
|
||||
const actionsVisible = useRowActionsAlwaysVisible() || isHovered;
|
||||
return (
|
||||
<View style={styles.projectTrailingActions}>
|
||||
{worktreeTarget ? (
|
||||
@@ -604,7 +603,7 @@ function WorkspaceRowRightGroup({
|
||||
workspace,
|
||||
backdrop,
|
||||
isHovered,
|
||||
isTouchPlatform,
|
||||
actionsAlwaysVisible,
|
||||
isCreating,
|
||||
showShortcutBadge,
|
||||
shortcutNumber,
|
||||
@@ -624,7 +623,7 @@ function WorkspaceRowRightGroup({
|
||||
workspace: SidebarWorkspaceEntry;
|
||||
backdrop: SidebarSurfaceBackdrop;
|
||||
isHovered: boolean;
|
||||
isTouchPlatform: boolean;
|
||||
actionsAlwaysVisible: boolean;
|
||||
isCreating: boolean;
|
||||
showShortcutBadge: boolean;
|
||||
shortcutNumber: number | null;
|
||||
@@ -657,7 +656,7 @@ function WorkspaceRowRightGroup({
|
||||
trailing,
|
||||
hasArchiveAction: Boolean(onArchive),
|
||||
isHovered,
|
||||
isTouchPlatform,
|
||||
actionsAlwaysVisible,
|
||||
showShortcut,
|
||||
});
|
||||
const kebab = useOpenKebabMenuVisibility(showKebabInSlot);
|
||||
@@ -881,7 +880,6 @@ function ProjectHeaderRow({
|
||||
const [isHovered, setIsHovered] = useState(false);
|
||||
const [isHighlighted, setIsHighlighted] = useState(false);
|
||||
const [contextMenuOpen, setContextMenuOpen] = useState(false);
|
||||
const isMobileBreakpoint = useIsCompactFormFactor();
|
||||
const localDaemonServerId = useLocalDaemonServerId();
|
||||
const projectPath = resolveSidebarProjectLocalPath(project, localDaemonServerId);
|
||||
const settingsTarget = project.hosts[0] ?? null;
|
||||
@@ -964,7 +962,6 @@ function ProjectHeaderRow({
|
||||
settingsTarget={settingsTarget}
|
||||
projectPath={projectPath}
|
||||
isHovered={isHovered}
|
||||
isMobileBreakpoint={isMobileBreakpoint}
|
||||
isProjectActive={isProjectActive}
|
||||
onBeginWorkspaceSetup={handleBeginWorkspaceSetup}
|
||||
onRemoveProject={onRemoveProject}
|
||||
@@ -1079,6 +1076,7 @@ function WorkspaceRowInner({
|
||||
const isCompact = useIsCompactFormFactor();
|
||||
const [isHighlighted, setIsHighlighted] = useState(false);
|
||||
const isTouchPlatform = platformIsNative || isCompact;
|
||||
const actionsAlwaysVisible = useRowActionsAlwaysVisible();
|
||||
const interaction = useLongPressDragInteraction({
|
||||
drag,
|
||||
menuController,
|
||||
@@ -1173,7 +1171,7 @@ function WorkspaceRowInner({
|
||||
workspace={workspace}
|
||||
backdrop={backdrop}
|
||||
isHovered={isHovered}
|
||||
isTouchPlatform={isTouchPlatform}
|
||||
actionsAlwaysVisible={actionsAlwaysVisible}
|
||||
isCreating={isCreating}
|
||||
showShortcutBadge={showShortcutBadge}
|
||||
shortcutNumber={shortcutNumber}
|
||||
|
||||
@@ -46,6 +46,7 @@ import {
|
||||
SidebarWorkspaceRowFrame,
|
||||
SidebarWorkspaceRowContent,
|
||||
resolveTrailingActionVisibility,
|
||||
useRowActionsAlwaysVisible,
|
||||
type SidebarWorkspaceTrailingPresentation,
|
||||
SidebarWorkspaceTrailingActionBase,
|
||||
SidebarWorkspaceTrailingActionOverlay,
|
||||
@@ -828,6 +829,7 @@ function StatusWorkspaceRowInnerContent({
|
||||
}) {
|
||||
const isCompact = useIsCompactFormFactor();
|
||||
const isTouchPlatform = platformIsNative || isCompact;
|
||||
const actionsAlwaysVisible = useRowActionsAlwaysVisible();
|
||||
const [isHighlighted, setIsHighlighted] = useState(false);
|
||||
const trailing = useSidebarWorkspaceTrailing();
|
||||
const {
|
||||
@@ -874,7 +876,7 @@ function StatusWorkspaceRowInnerContent({
|
||||
trailing,
|
||||
hasArchiveAction: Boolean(onArchive),
|
||||
isHovered,
|
||||
isTouchPlatform,
|
||||
actionsAlwaysVisible,
|
||||
showShortcut,
|
||||
});
|
||||
const workspaceRowStyle = getStatusWorkspaceRowStyle({
|
||||
|
||||
@@ -16,6 +16,8 @@ import {
|
||||
type SidebarWorkspaceTrailing,
|
||||
} from "@/components/sidebar/workspace-trailing";
|
||||
import { useAppSettings } from "@/hooks/use-settings";
|
||||
import { usePointerCapabilities } from "@/hooks/pointer-capabilities";
|
||||
import { useIsCompactFormFactor } from "@/constants/layout";
|
||||
import { densityIconBox } from "@/styles/density";
|
||||
import type { Theme } from "@/styles/theme";
|
||||
import type { SidebarStateBucket } from "@/utils/sidebar-agent-state";
|
||||
@@ -365,6 +367,17 @@ export function SidebarWorkspaceShortcutBadge({ number }: { number: number }) {
|
||||
|
||||
export type SidebarWorkspaceTrailingPresentation = "visible" | "hidden" | "absent";
|
||||
|
||||
/**
|
||||
* Whether a sidebar row keeps its actions shown instead of revealing them on hover. True on the
|
||||
* compact layout and wherever the primary pointer can't hover: native apps, and a touch screen in
|
||||
* a wide browser (an iPad in Safari), where the menu button is the only way to the row menu.
|
||||
*/
|
||||
export function useRowActionsAlwaysVisible(): boolean {
|
||||
const isCompact = useIsCompactFormFactor();
|
||||
const { finePointer } = usePointerCapabilities();
|
||||
return isCompact || !finePointer;
|
||||
}
|
||||
|
||||
/**
|
||||
* What the trailing slot shows for a row. Derived in one place because three row renderers
|
||||
* share it: the two project-mode rows and the status-mode row. The rule used to be copied
|
||||
@@ -380,14 +393,14 @@ export function resolveTrailingActionVisibility({
|
||||
trailing,
|
||||
hasArchiveAction,
|
||||
isHovered,
|
||||
isTouchPlatform,
|
||||
actionsAlwaysVisible,
|
||||
showShortcut,
|
||||
}: {
|
||||
workspace: SidebarWorkspaceEntry;
|
||||
trailing: SidebarWorkspaceTrailing;
|
||||
hasArchiveAction: boolean;
|
||||
isHovered: boolean;
|
||||
isTouchPlatform: boolean;
|
||||
actionsAlwaysVisible: boolean;
|
||||
showShortcut: boolean;
|
||||
}): {
|
||||
trailingPresentation: SidebarWorkspaceTrailingPresentation;
|
||||
@@ -398,10 +411,11 @@ export function resolveTrailingActionVisibility({
|
||||
reserveSlotWidth: boolean;
|
||||
} {
|
||||
const hasTrailing = hasSidebarWorkspaceTrailing({ workspace, trailing });
|
||||
const showKebab = Boolean(hasArchiveAction && (isHovered || isTouchPlatform)) && !showShortcut;
|
||||
const showKebab =
|
||||
Boolean(hasArchiveAction && (isHovered || actionsAlwaysVisible)) && !showShortcut;
|
||||
// Touch permanently replaces the stats with the menu. Only temporary shortcut hints
|
||||
// conceal content while retaining its width, so desktop rows do not shift.
|
||||
const hasContent = hasTrailing && !(hasArchiveAction && isTouchPlatform);
|
||||
const hasContent = hasTrailing && !(hasArchiveAction && actionsAlwaysVisible);
|
||||
let trailingPresentation: SidebarWorkspaceTrailingPresentation = "absent";
|
||||
if (hasContent) trailingPresentation = showShortcut ? "hidden" : "visible";
|
||||
return {
|
||||
@@ -409,7 +423,7 @@ export function resolveTrailingActionVisibility({
|
||||
showKebab,
|
||||
// One-click archive is a pointer affordance: on touch it would sit a few pixels from the
|
||||
// kebab and turn a miss into an archive.
|
||||
showArchiveButton: showKebab && isHovered && !isTouchPlatform,
|
||||
showArchiveButton: showKebab && isHovered && !actionsAlwaysVisible,
|
||||
// The scrim paints the row's own hover background, so it can only be drawn on a hovered
|
||||
// row — over an unhovered one the gradient fades to the wrong color. That is also why
|
||||
// touch, which shows the kebab without ever hovering, never gets one.
|
||||
@@ -419,7 +433,7 @@ export function resolveTrailingActionVisibility({
|
||||
// does; the kebab only does on touch, where there is no hover for it to appear on and so
|
||||
// no scrim to let it overlay the title. Everywhere else the width goes back to the title
|
||||
// and the kebab fades in over its tail.
|
||||
reserveSlotWidth: hasContent || (hasArchiveAction && isTouchPlatform),
|
||||
reserveSlotWidth: hasContent || (hasArchiveAction && actionsAlwaysVisible),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user