Skip to content

fix(web-integration): preserve selection for cut shortcuts - #2938

Open
quanruzhuoxiu wants to merge 5 commits into
mainfrom
fix/playwright-cut-shortcut
Open

fix(web-integration): preserve selection for cut shortcuts#2938
quanruzhuoxiu wants to merge 5 commits into
mainfrom
fix/playwright-cut-shortcut

Conversation

@quanruzhuoxiu

@quanruzhuoxiu quanruzhuoxiu commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Preserve an existing selection when Copy or Cut targets the already focused element. This is the Playwright Cmd/Ctrl+X fix because the previous coordinate click collapsed the selected range before the shortcut.
  • Map Cmd/Ctrl+X to the CDP Cut editing command for Puppeteer. Playwright does not consume explicit editing commands through its public keyboard API, so this is an independent Puppeteer improvement.
  • Keep the target-focus contract by clicking when a different element owns focus.

Independent regression proof

  • Playwright focus behavior: verify that selection-preserving focus keeps the full selected range, while the previous coordinate click collapses it.
  • Command mapping: verify that Cmd/Ctrl+X produces the explicit Cut editing command.
  • Puppeteer command behavior: use a non-cut function key to prove that adding the explicit Cut command changes real Chromium behavior from preserving the selected value to cutting it, without invoking target-focus logic.
  • Puppeteer end to end: run Cmd/Ctrl+A followed by Cmd/Ctrl+X against the same target, assert that the full range remains selected before Cut, the value is removed, and Chromium emits a cut event.
  • Keep end-to-end Playwright coverage for select-all, copy, cut, and wrong-focus boundaries.

Review findings resolved

  • Separate the two behavioral changes so each has an independent failing boundary and passing assertion.
  • Prevent Copy/Cut from acting on the wrong element when another input owns focus.
  • Keep the new focus capability optional for Chrome Extension and Bridge structural adapters.
  • Expand and rename the editing-command test suite to match its responsibility.

Validation

  • pnpm run lint
  • pnpm --filter @midscene/web exec vitest --run tests/unit-test/base-page-editing-commands.test.ts tests/unit-test/util.test.ts (26 passed)
  • pnpm --filter @midscene/web exec vitest --run --coverage tests/unit-test/base-page-editing-commands.test.ts tests/unit-test/util.test.ts (26 passed)
  • pnpm exec tsc -p packages/web-integration/tsconfig.json --noEmit --pretty false
  • pnpm exec nx test @midscene/web (428 passed, 1 skipped)
  • pnpm exec nx build @midscene/web
  • git diff --check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant