mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-30 20:25:50 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d71ac161e8 |
@@ -52,17 +52,28 @@ async function exitSelection(page: Page) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Walks the Finder click matrix on four rows, starting with the first row open: a modifier click
|
||||
* from normal mode selects only the clicked row, Cmd/Ctrl+click toggles, Shift+click extends and
|
||||
* shrinks a range from the anchor, and plain clicks keep toggling while select mode is on.
|
||||
* Walks the sidebar selection click matrix on four rows: Cmd/Ctrl+click (and Cmd/Ctrl+Shift+click)
|
||||
* from normal mode navigates instead of entering select mode, Shift+click enters select mode on the
|
||||
* clicked row alone, Cmd/Ctrl+click and plain clicks toggle while select mode is active, and
|
||||
* Shift+click extends, shrinks, and flips a range from the anchor.
|
||||
*/
|
||||
async function exerciseClickMatrix(page: Page, rows: readonly Locator[]) {
|
||||
const [first, second, third, fourth] = rows;
|
||||
await first.click();
|
||||
await expect(first).toHaveAttribute("aria-selected", "true");
|
||||
|
||||
// Cmd/Ctrl+click and Cmd/Ctrl+Shift+click outside select mode navigate normally.
|
||||
await third.click({ modifiers: [MOD] });
|
||||
await expect(third).toHaveAttribute("aria-selected", "true");
|
||||
await expect(page.getByTestId("workspace-selection-toast")).toHaveCount(0);
|
||||
|
||||
await first.click({ modifiers: [MOD, "Shift"] });
|
||||
await expect(first).toHaveAttribute("aria-selected", "true");
|
||||
await expect(page.getByTestId("workspace-selection-toast")).toHaveCount(0);
|
||||
const openWorkspaceUrl = page.url();
|
||||
|
||||
await third.click({ modifiers: [MOD] });
|
||||
// Shift+click enters select mode on the clicked row alone; Cmd/Ctrl+click and plain clicks toggle.
|
||||
await third.click({ modifiers: ["Shift"] });
|
||||
await expectSelectedCount(page, 1);
|
||||
await expectChecked(rows, [false, false, true, false]);
|
||||
|
||||
@@ -102,7 +113,7 @@ test.describe("sidebar workspace selection clicks", () => {
|
||||
seeded = null;
|
||||
});
|
||||
|
||||
test("Cmd/Ctrl+click and Shift+click select like Finder in project grouping", async ({
|
||||
test("Shift+click enters select mode while Cmd/Ctrl+click navigates in project grouping", async ({
|
||||
page,
|
||||
}) => {
|
||||
seeded = await seedProjectWithWorkspaces(4);
|
||||
@@ -111,7 +122,9 @@ test.describe("sidebar workspace selection clicks", () => {
|
||||
await exerciseClickMatrix(page, await rowsInSidebarOrder(page, seeded.workspaceIds));
|
||||
});
|
||||
|
||||
test("Cmd/Ctrl+click and Shift+click select like Finder in status grouping", async ({ page }) => {
|
||||
test("Shift+click enters select mode while Cmd/Ctrl+click navigates in status grouping", async ({
|
||||
page,
|
||||
}) => {
|
||||
seeded = await seedProjectWithWorkspaces(4);
|
||||
await gotoAppShell(page);
|
||||
await waitForSidebarHydration(page);
|
||||
|
||||
@@ -93,19 +93,54 @@ export function readPressModifiers(
|
||||
context: PressModifierContext = { isMac: getShortcutOs() === "mac", held: heldModifiers },
|
||||
): PressModifiers {
|
||||
const modKey: HeldModifierKey = context.isMac ? "Meta" : "Control";
|
||||
const trustEventFlags = !isTouchPressEvent(event);
|
||||
return {
|
||||
shift: hasPressFlag(event, "shiftKey") || context.held.isDown("Shift"),
|
||||
mod: hasPressFlag(event, MODIFIER_FLAGS[modKey]) || context.held.isDown(modKey),
|
||||
shift: resolveModifierFlag(event, "shiftKey", "Shift", trustEventFlags, context.held),
|
||||
mod: resolveModifierFlag(event, MODIFIER_FLAGS[modKey], modKey, trustEventFlags, context.held),
|
||||
};
|
||||
}
|
||||
|
||||
function hasPressFlag(event: unknown, flag: "shiftKey" | "metaKey" | "ctrlKey"): boolean {
|
||||
if (typeof event !== "object" || event === null) return false;
|
||||
if (Reflect.get(event, flag) === true) return true;
|
||||
function resolveModifierFlag(
|
||||
event: unknown,
|
||||
flag: "shiftKey" | "metaKey" | "ctrlKey",
|
||||
heldKey: HeldModifierKey,
|
||||
trustEventFlags: boolean,
|
||||
held: Pick<HeldModifierTracker, "isDown">,
|
||||
): boolean {
|
||||
const eventFlag = readPressFlag(event, flag);
|
||||
if (trustEventFlags && eventFlag !== undefined) {
|
||||
return eventFlag;
|
||||
}
|
||||
return eventFlag === true || held.isDown(heldKey);
|
||||
}
|
||||
|
||||
function readPressFlag(
|
||||
event: unknown,
|
||||
flag: "shiftKey" | "metaKey" | "ctrlKey",
|
||||
): boolean | undefined {
|
||||
if (typeof event !== "object" || event === null) return undefined;
|
||||
const direct = Reflect.get(event, flag);
|
||||
if (typeof direct === "boolean") return direct;
|
||||
const nativeEvent = Reflect.get(event, "nativeEvent");
|
||||
if (typeof nativeEvent !== "object" || nativeEvent === null) return undefined;
|
||||
const nativeFlag = Reflect.get(nativeEvent, flag);
|
||||
return typeof nativeFlag === "boolean" ? nativeFlag : undefined;
|
||||
}
|
||||
|
||||
function isTouchPressEvent(event: unknown): boolean {
|
||||
if (typeof event !== "object" || event === null) return false;
|
||||
return isTouchEventRecord(event) || isTouchEventRecord(Reflect.get(event, "nativeEvent"));
|
||||
}
|
||||
|
||||
function isTouchEventRecord(record: unknown): boolean {
|
||||
if (typeof record !== "object" || record === null) return false;
|
||||
if (Reflect.get(record, "pointerType") === "touch") return true;
|
||||
const type = Reflect.get(record, "type");
|
||||
if (typeof type === "string" && type.startsWith("touch")) return true;
|
||||
const sourceCapabilities = Reflect.get(record, "sourceCapabilities");
|
||||
return (
|
||||
typeof nativeEvent === "object" &&
|
||||
nativeEvent !== null &&
|
||||
Reflect.get(nativeEvent, flag) === true
|
||||
typeof sourceCapabilities === "object" &&
|
||||
sourceCapabilities !== null &&
|
||||
Reflect.get(sourceCapabilities, "firesTouchEvents") === true
|
||||
);
|
||||
}
|
||||
|
||||
@@ -407,6 +407,45 @@ describe("press modifiers", () => {
|
||||
mod: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("trusts explicit boolean flags on non-touch pointer events over stale held keys", async () => {
|
||||
const { createHeldModifierTracker, readPressModifiers } =
|
||||
await import("./internal/press-modifiers");
|
||||
const held = createHeldModifierTracker();
|
||||
// Simulate a missed key-up (e.g. OS overlay or native menu swallowing release).
|
||||
held.handleKeyDown(modifierKey("Shift", "ShiftLeft", { shiftKey: true }));
|
||||
held.handleKeyDown(modifierKey("Meta", "MetaLeft", { shiftKey: true, metaKey: true }));
|
||||
|
||||
const mouseClick = {
|
||||
nativeEvent: { shiftKey: false, metaKey: false, ctrlKey: false, pointerType: "mouse" },
|
||||
};
|
||||
expect(readPressModifiers(mouseClick, { isMac: true, held })).toEqual({
|
||||
shift: false,
|
||||
mod: false,
|
||||
});
|
||||
|
||||
// Touch-synthesized clicks on web may report false modifier flags while a hardware key is held.
|
||||
const touchPointerClick = {
|
||||
nativeEvent: { shiftKey: false, metaKey: false, ctrlKey: false, pointerType: "touch" },
|
||||
};
|
||||
expect(readPressModifiers(touchPointerClick, { isMac: true, held })).toEqual({
|
||||
shift: true,
|
||||
mod: true,
|
||||
});
|
||||
|
||||
const touchCapabilityClick = {
|
||||
nativeEvent: {
|
||||
shiftKey: false,
|
||||
metaKey: false,
|
||||
ctrlKey: false,
|
||||
sourceCapabilities: { firesTouchEvents: true },
|
||||
},
|
||||
};
|
||||
expect(readPressModifiers(touchCapabilityClick, { isMac: true, held })).toEqual({
|
||||
shift: true,
|
||||
mod: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("non-TextInput native focus registration", () => {
|
||||
|
||||
+25
-8
@@ -218,14 +218,24 @@ async function slowClick(element: HTMLElement) {
|
||||
const MOD_KEY = getShortcutOs() === "mac" ? "Meta" : "Control";
|
||||
|
||||
describe("sidebar workspace row presses", () => {
|
||||
it("enters select mode on the Cmd/Ctrl+clicked row alone and toggles rows without navigating", async () => {
|
||||
it("navigates on Cmd/Ctrl+click and Cmd/Ctrl+Shift+click outside select mode, and toggles with Cmd/Ctrl+click once active", async () => {
|
||||
mountHost(["a", "b", "c", "d"].map(makeEntry));
|
||||
|
||||
await userEvent.click(row("a"));
|
||||
expect(navigatedKeys).toEqual(["srv:a"]);
|
||||
expect(useSidebarSelectionStore.getState().active).toBe(false);
|
||||
|
||||
// Cmd/Ctrl+click (and Cmd/Ctrl+Shift+click) must not enter select mode from idle.
|
||||
await userEvent.click(row("c"), { modifiers: [MOD_KEY] });
|
||||
expect(useSidebarSelectionStore.getState().active).toBe(false);
|
||||
expect(navigatedKeys).toEqual(["srv:a", "srv:c"]);
|
||||
|
||||
await userEvent.click(row("d"), { modifiers: [MOD_KEY, "Shift"] });
|
||||
expect(useSidebarSelectionStore.getState().active).toBe(false);
|
||||
expect(navigatedKeys).toEqual(["srv:a", "srv:c", "srv:d"]);
|
||||
|
||||
// Once select mode is entered (e.g. via Shift+click), Cmd/Ctrl+click and plain clicks toggle.
|
||||
await userEvent.click(row("c"), { modifiers: ["Shift"] });
|
||||
expect(selectedIds()).toEqual(["c"]);
|
||||
|
||||
await userEvent.click(row("b"), { modifiers: [MOD_KEY] });
|
||||
@@ -238,31 +248,38 @@ describe("sidebar workspace row presses", () => {
|
||||
// Plain clicks keep toggling while select mode is on.
|
||||
await userEvent.click(row("a"));
|
||||
expect(selectedIds()).toEqual(["a", "b", "d"]);
|
||||
expect(navigatedKeys).toEqual(["srv:a"]);
|
||||
expect(navigatedKeys).toEqual(["srv:a", "srv:c", "srv:d"]);
|
||||
});
|
||||
|
||||
it("selects on the first modifier or select-mode click after an earlier gesture ended as a long press", async () => {
|
||||
mountHost(["a", "b"].map(makeEntry));
|
||||
it("selects on the first Shift+click or select-mode click after an earlier gesture ended as a long press", async () => {
|
||||
mountHost(["a", "b", "c"].map(makeEntry));
|
||||
|
||||
// A scroll, swipe, drag, or long-press menu leaves the flag set without firing onPress.
|
||||
// Ctrl+click on Windows/Linux gets no press-in on web, so nothing clears it first.
|
||||
markGestureCanceled("a");
|
||||
await userEvent.click(row("a"), { modifiers: [MOD_KEY] });
|
||||
await userEvent.click(row("a"), { modifiers: ["Shift"] });
|
||||
expect(selectedIds()).toEqual(["a"]);
|
||||
|
||||
markGestureCanceled("b");
|
||||
await userEvent.click(row("b"));
|
||||
await userEvent.click(row("b"), { modifiers: [MOD_KEY] });
|
||||
expect(selectedIds()).toEqual(["a", "b"]);
|
||||
|
||||
markGestureCanceled("c");
|
||||
await userEvent.click(row("c"));
|
||||
expect(selectedIds()).toEqual(["a", "b", "c"]);
|
||||
});
|
||||
|
||||
it("opens a row on a slow click and still selects it on the next Cmd/Ctrl+click", async () => {
|
||||
it("opens a row on a slow click and still selects it on the next Shift+click and Cmd/Ctrl+click", async () => {
|
||||
mountHost(["a", "b"].map(makeEntry));
|
||||
|
||||
await act(() => slowClick(row("a")));
|
||||
expect(navigatedKeys).toEqual(["srv:a"]);
|
||||
|
||||
await userEvent.click(row("a"), { modifiers: [MOD_KEY] });
|
||||
await userEvent.click(row("a"), { modifiers: ["Shift"] });
|
||||
expect(selectedIds()).toEqual(["a"]);
|
||||
|
||||
await userEvent.click(row("b"), { modifiers: [MOD_KEY] });
|
||||
expect(selectedIds()).toEqual(["a", "b"]);
|
||||
});
|
||||
|
||||
it("enters select mode on the Shift+clicked row alone, then extends and shrinks the range", async () => {
|
||||
|
||||
@@ -12,10 +12,12 @@ interface WorkspaceSelectionPressInput {
|
||||
}
|
||||
|
||||
/**
|
||||
* Routes a sidebar workspace row press between navigation and select mode, Finder-style:
|
||||
* Shift+click selects a range, Cmd+click (Ctrl+click off macOS) toggles one row, and either one
|
||||
* enters select mode on the clicked row alone. In select mode every press selects, so touch and
|
||||
* mouse users can keep tapping without a modifier.
|
||||
* Routes a sidebar workspace row press between navigation and select mode:
|
||||
* - Outside select mode, Shift+click (without Cmd/Ctrl) enters select mode on the clicked row
|
||||
* alone; plain clicks and Cmd/Ctrl+clicks navigate normally so shortcut rollover and Cmd-held
|
||||
* badge peeks never trigger bulk selection.
|
||||
* - Inside select mode, Shift+click selects a Finder-style range from the anchor, and plain clicks
|
||||
* or Cmd/Ctrl+clicks toggle one row without navigating.
|
||||
*
|
||||
* Selecting presses never consult the row's long-press flag. They never arm the long-press
|
||||
* gesture, a native long press already cancels the press, and react-native-web gives Ctrl+click
|
||||
@@ -30,7 +32,7 @@ export function useWorkspaceSelectionPress({
|
||||
(event: GestureResponderEvent) => {
|
||||
const modifiers = readPressModifiers(event);
|
||||
const store = useSidebarSelectionStore.getState();
|
||||
if (!store.active && !modifiers.shift && !modifiers.mod) {
|
||||
if (!store.active && (!modifiers.shift || modifiers.mod)) {
|
||||
onNavigate();
|
||||
return;
|
||||
}
|
||||
@@ -43,12 +45,14 @@ export function useWorkspaceSelectionPress({
|
||||
const handlePressIn = useCallback(
|
||||
(event: GestureResponderEvent) => {
|
||||
const modifiers = readPressModifiers(event);
|
||||
if (modifiers.shift || modifiers.mod) {
|
||||
const isSelectionMode = useSidebarSelectionStore.getState().active;
|
||||
const entersSelection = !isSelectionMode && modifiers.shift && !modifiers.mod;
|
||||
if (entersSelection || (isSelectionMode && (modifiers.shift || modifiers.mod))) {
|
||||
// Keep the browser from extending a text selection or starting a drag on modifier clicks.
|
||||
event.preventDefault?.();
|
||||
return;
|
||||
}
|
||||
if (!useSidebarSelectionStore.getState().active) {
|
||||
if (!isSelectionMode) {
|
||||
onPressIn?.(event);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user