Skip to content

fix(editor): preserve first-click caret in WKWebView - #737

Merged
murongg merged 1 commit into
v2from
fix/736-webview-first-click
Sep 19, 2026
Merged

murongg merged 1 commit into
v2from
fix/736-webview-first-click

Conversation

@murongg

@murongg murongg commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

Opening a long note and clicking below the fold for the first time can scroll macOS WKWebView back to the top and create a large selection. WKWebView omits the Version/ user-agent token, so CodeMirror detects Safari version 0 and skips its Safari 26+ workaround for broken focus({ preventScroll: true }) support. The scroll reset changes the document position between the two hit tests for the same click.

Apply a pnpm patch to @codemirror/view@6.41.1 that includes unknown Safari versions in the existing scroll-restoration fallback. Both ESM and CommonJS entry points are patched, and the same dependency serves the visual and source editors. Add regression coverage for initial focus and refocus, including nested vertical and horizontal scroll positions, and document when to remove the patch.

Closes #736.

Validation

  • Regression tests failed before the patch with scroll position 0 instead of 1600, then passed for both module entry points.
  • corepack pnpm --filter @markra/editor test — 596 tests passed.
  • corepack pnpm --filter @markra/app test src/components/CodeMirrorPaperSurface.test.tsx src/components/MarkdownSourceEditor.test.tsx src/hooks/useCodeMirrorEditorController.test.tsx — 67 tests passed.
  • corepack pnpm --filter @markra/editor-react test — 6 tests passed.
  • corepack pnpm --filter @markra/editor typecheck:test — passed.
  • corepack pnpm install --frozen-lockfile --ignore-scripts — passed.
  • corepack pnpm build — passed, including web and desktop frontend builds and vendor-chunk validation.
  • Playwright component QA using synthetic long notes: 30 checks passed across WebKit with WKWebView UA, Safari UA, and Chromium, in both visual and source modes. First clicks at three scroll positions preserve the caret and scroll offset; drag selection and Shift-click after blur remain functional; Markdown stays unchanged. The unpatched WKWebView-UA reproduction failed at all three scroll positions.

Browser QA used the actual editor components after fonts and layout settled. The system WKWebView UA was independently confirmed with a native WebKit probe; the packaged Tauri app was not exercised.

Apply CodeMirror's existing Safari scroll-restoration fallback when WKWebView omits the browser version. Cover both module entry points with focus regression tests.

Fixes #736
@vercel

vercel Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
markra-web Ready Ready Preview Sep 19, 2026 12:38am UTC

@murongg
murongg merged commit da6c518 into v2 Sep 19, 2026
23 checks passed
@murongg
murongg deleted the fix/736-webview-first-click branch September 19, 2026 11:55

This branch was successfully deployed

1 active deployment
Preview — c4c68a8f Deployed Sep 19, 2026 by vercel[bot]
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.

[Bug]: First click in a freshly opened note creates a large text selection and scrolls the document back to the top

1 participant