Repository navigation
perf(keyboard): the keyboard height no longer loads the selection lock #14289
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
+78
−38
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b98e7d7
perf(keyboard): the keyboard height no longer loads the selection lock
vjeux e84b7a7
perf(keyboard): review round: the changeset scopes the saving, and ca…
vjeux ed56d5e
test(keyboard): the snap-paging bundle test counts caretAt with the s…
vjeux 7ec7797
perf(keyboard): review round: the changeset's saving needs no other c…
vjeux 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
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,7 @@ | ||
| --- | ||
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [perf] The keyboard height reads the caret position from a module of its own, not from the selection lock. A page that loads the keyboard height, as a DropdownMenu or a Table does, no longer loads the selection lock with it. First-load JavaScript drops by about 1.6 KB gzip on such a page, with esbuild and with Rolldown. A text-only page built with esbuild drops by about 1.7 KB. A page that loads the selection lock for another of its uses loads up to 80 bytes more. The keyboard height reads the same caret as before. | ||
|
|
||
| @vjeux | ||
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
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,45 @@ | ||
| // Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
|
||
| /** | ||
| * @file caretAt.ts | ||
| * @input A document, a client point and the shadow roots to look into | ||
| * @output caretAt: the caret position the engine puts at that point | ||
| * @position An internal utility. The keyboard height reads it apart from the | ||
| * selection lock, so a page that locks no selection does not load the lock. | ||
|
astracat-bot[bot] marked this conversation as resolved.
Resolved
|
||
| */ | ||
|
|
||
| /** The caret position the engine puts at a point, by either query. */ | ||
| export function caretAt( | ||
|
astracat-bot[bot] marked this conversation as resolved.
Resolved
|
||
| doc: Document, | ||
| x: number, | ||
| y: number, | ||
| shadowRoots: ReadonlyArray<ShadowRoot>, | ||
| ): {node: Node; offset: number} | null { | ||
| const queries = doc as Document & { | ||
| caretPositionFromPoint?: ( | ||
| x: number, | ||
| y: number, | ||
| options?: {shadowRoots?: ShadowRoot[]}, | ||
| ) => {offsetNode: Node; offset: number} | null; | ||
| caretRangeFromPoint?: (x: number, y: number) => Range | null; | ||
| }; | ||
| if (typeof queries.caretPositionFromPoint === 'function') { | ||
| // Without the roots, a point over shadow text answers at its host. | ||
| const position = | ||
| shadowRoots.length > 0 | ||
| ? queries.caretPositionFromPoint(x, y, { | ||
| shadowRoots: [...shadowRoots], | ||
| }) | ||
| : queries.caretPositionFromPoint(x, y); | ||
| return position == null | ||
| ? null | ||
| : {node: position.offsetNode, offset: position.offset}; | ||
|
astracat-bot[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
| if (typeof queries.caretRangeFromPoint === 'function') { | ||
| const range = queries.caretRangeFromPoint(x, y); | ||
| return range == null | ||
| ? null | ||
| : {node: range.startContainer, offset: range.startOffset}; | ||
| } | ||
|
astracat-bot[bot] marked this conversation as resolved.
Resolved
|
||
| return null; | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.