Repository navigation
Improve how notes highlight and connect to content #80578
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
Changes from 20 commits
2c1a1dc
6d65934
4e1ab82
5f965a5
b2e691c
222fcaf
ef832e4
a0ae378
82b44bd
8db1b39
917b2c9
0241129
d300ad5
525a8c1
04ae0e9
9247c62
0a8e84e
1771415
cdea363
9840932
2e871e7
5ba1fa9
b78bc34
2f59720
6e0d1a2
084442b
eb2f16a
596605b
cff0319
244ce23
04f5973
bf1d021
14e61c1
3f3fd01
cc46458
a0f591f
69a8975
1160164
6aa7f0e
7710b42
3f7cbfc
db6835b
d022658
6e60d3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -278,7 +278,8 @@ export function useNoteActions() { | |
| getSelectionStart, | ||
| getSelectionEnd, | ||
| } = useSelect( blockEditorStore ); | ||
| const { updateBlockAttributes } = useDispatch( blockEditorStore ); | ||
| const { selectionChange, updateBlockAttributes } = | ||
| useDispatch( blockEditorStore ); | ||
|
|
||
| const onError = ( error ) => { | ||
| const errorMessage = | ||
|
|
@@ -337,8 +338,9 @@ export function useNoteActions() { | |
|
|
||
| // Inline path: also wrap the selected text with a core/note | ||
| // marker so the anchor survives later edits. | ||
| let wrapped = null; | ||
| if ( inlineSelection ) { | ||
| const wrapped = wrapInlineNote( | ||
| wrapped = wrapInlineNote( | ||
| attributes?.[ inlineSelection.attributeKey ], | ||
| savedRecord.id, | ||
| inlineSelection.start, | ||
|
|
@@ -350,6 +352,25 @@ export function useNoteActions() { | |
| } | ||
|
|
||
| updateBlockAttributes( clientId, newAttributes ); | ||
|
|
||
| /* | ||
| * The anchoring range has done its job once the marker is | ||
| * written, but it lingers as the canvas's (inactive) native | ||
| * selection - and browsers paint text decorations inside a | ||
| * selected range with the selection's text color, so the fresh | ||
| * marker's underline would read as plain text-colored until | ||
| * the user happens to click somewhere. Collapse the selection | ||
| * to the end of the range so the marker shows its author | ||
| * color right away. | ||
| */ | ||
| if ( wrapped ) { | ||
| selectionChange( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works for a reason that is not obvious from the code, and it needs a check that the user has not moved on during the save. Why it works: the editor canvas lives in an embedded page (an iframe) inside the admin page. When you click into the sidebar, focus leaves the canvas, but the canvas's own record of which element has focus still says the paragraph. The rich-text code in The guard: this runs unconditionally after the save request returns. If the user clicked into a different block while the request was in flight, this pulls the recorded selection back to the end of the noted text while the cursor is really somewhere else. The rich-text code will not apply it (the noted paragraph is no longer the focused element), so the editor's idea of where the cursor is and the real cursor disagree, and the toolbar and blue outline jump to the wrong block. Fix: only dispatch when
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for working out why this works, that was not obvious. Claude took this one, here is what changed:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally, I'm not sure why inline notes need this special handling in the first place.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair points, especially the Shift+Tab one. Dropped it. Claude made the change, notes below:
|
||
| clientId, | ||
| inlineSelection.attributeKey, | ||
| inlineSelection.end, | ||
| inlineSelection.end | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| createNotice( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.