Repository navigation
fix(core): formatting toolbar stuck after a tap on iOS Safari's address bar #3259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
matthewlipski
merged 3 commits into
TypeCellOS:main
from
RovshanMuradov:fix/touch-selection-blur
Oct 26, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
7cee0b0
fix(core): collapse the selection when focus leaves a touch editor
RovshanMuradov b4c14ab
fix(core): drop the editor's focus when the window blurs on touch
RovshanMuradov a8ff0f2
test(core): model WebKit's page blur in the touch focus tests
RovshanMuradov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
packages/core/src/extensions/FormattingToolbar/FormattingToolbar.browser.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import { TextSelection } from "prosemirror-state"; | ||
| import { afterEach, beforeEach, describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js"; | ||
| import { FormattingToolbarExtension } from "./FormattingToolbar.js"; | ||
|
|
||
| // Runs in the desktop browser instances, where `isTouchDevice()` is false. | ||
| // The touch side is pinned in tests/src/end-to-end/mobile/mobileToolbar.test.tsx. | ||
|
|
||
| /** Resolves once the deferred focus settle has run (see attachUIFocusTracker). */ | ||
| function settle() { | ||
| return new Promise((resolve) => setTimeout(resolve, 20)); | ||
| } | ||
|
|
||
| describe("Formatting toolbar focus", () => { | ||
| let editor: BlockNoteEditor<any, any, any>; | ||
| let container: HTMLElement; | ||
| let outside: HTMLInputElement; | ||
|
|
||
| beforeEach(() => { | ||
| outside = document.createElement("input"); | ||
| document.body.append(outside); | ||
|
|
||
| // Nested like `BlockNoteView`: the mount element's parent is the | ||
| // editor's boundary (see `isWithinEditor`). | ||
| container = document.createElement("div"); | ||
| const mountPoint = document.createElement("div"); | ||
| container.append(mountPoint); | ||
| document.body.append(container); | ||
| editor = BlockNoteEditor.create({ | ||
| initialContent: [{ type: "paragraph", content: "Selected text" }], | ||
| }); | ||
| editor.mount(mountPoint); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| editor.unmount(); | ||
| container.remove(); | ||
| outside.remove(); | ||
| }); | ||
|
|
||
| it("keeps the selection and the toolbar across a blur", async () => { | ||
| const toolbar = editor.getExtension(FormattingToolbarExtension)!; | ||
| editor.focus(); | ||
| editor.transact((tr) => | ||
| tr.setSelection(TextSelection.create(tr.doc, 3, 11)), | ||
| ); | ||
| expect(toolbar.store.state).toBe(true); | ||
|
|
||
| outside.focus(); | ||
| await settle(); | ||
| expect(toolbar.store.state).toBe(false); | ||
|
|
||
| editor.focus(); | ||
| await settle(); | ||
| expect(editor.transact((tr) => tr.selection.empty)).toBe(false); | ||
| expect(toolbar.store.state).toBe(true); | ||
| }); | ||
|
|
||
| // Only touch devices drop the editor's focus when the window blurs; a | ||
| // desktop keeps it, e.g. across a switch to another window and back. | ||
| it("keeps focus, the selection and the toolbar when only the window blurs", async () => { | ||
| const toolbar = editor.getExtension(FormattingToolbarExtension)!; | ||
| editor.focus(); | ||
| editor.transact((tr) => | ||
| tr.setSelection(TextSelection.create(tr.doc, 3, 11)), | ||
| ); | ||
| expect(toolbar.store.state).toBe(true); | ||
|
|
||
| // WebKit's page blur: `blur` on the focused element, without focusout and | ||
| // without moving `document.activeElement`, then on the window. | ||
| editor.prosemirrorView.dom.dispatchEvent(new FocusEvent("blur")); | ||
| window.dispatchEvent(new FocusEvent("blur")); | ||
| await settle(); | ||
|
|
||
| expect(editor.isFocused()).toBe(true); | ||
| expect(editor.transact((tr) => tr.selection.empty)).toBe(false); | ||
| expect(toolbar.store.state).toBe(true); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔎 Supported by static analysis
Script executed:
Repository: TypeCellOS/BlockNote
Length of output: 5550
Script executed:
Repository: TypeCellOS/BlockNote
Length of output: 41993
Script executed:
Repository: TypeCellOS/BlockNote
Length of output: 41595
Script executed:
Repository: TypeCellOS/BlockNote
Length of output: 31212
Script executed:
Repository: TypeCellOS/BlockNote
Length of output: 17285
Handle selections with no text cursor.
In a touch document that contains only image blocks,
Selection.near(tr.selection.$head)can return a non-emptyNodeSelectionorAllSelection.shouldShow()accepts these selections, so the toolbar can reappear on focus without a new selection action. Keep the toolbar hidden until a new selection action when no empty text cursor is available. Add an image-only case to the touch test.