-
Notifications
You must be signed in to change notification settings - Fork 4.7k
[Experimental] Notes: Support partial text selection notes #74852
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
base: trunk
Are you sure you want to change the base?
Conversation
|
Size Change: -160 B (-0.01%) Total Size: 3 MB
ℹ️ View Unchanged
|
b0d2ea4 to
39f5b84
Compare
|
Annotations are meant to be continually re-evaluated. A use case is spelling or tone checking and stuff like that. I'm not sure if it's a good fit for notes. If we're currently anchoring block notes to blocks, then we should probably also anchor inline notes to the text? |
Requested design feedback in the issue - #59445 (comment). Using the parent-child system makes it easy to maintain the relationship between notes. Depending on the design, it can change. @ellatrix, I think a big plus for annotation format is that we don't store markup in the DB, and it won't be displayed on the front. Avoiding extra markup was mentioned a couple of times in the tracking issue, though I'm not sure if we can. Another problem I can think of with permanent markup is that, when collaboration features ship and we introduce inline suggestions, we might have to change our approach to inline notes again, making old markup obsolete. As I mentioned in the description, this PR is mainly an experiment. I wanted to get something out with the Annotations API and see what you folks think about :) |
This is what I originally used to implement partial text selection notes in "asblocks". I run into a lot of issues though, things like needing to keep the "pointers" (start, end...) of each annotation in sync when the user make changes... IMO it results in an implementation that is too complex. I agree that not storing markup in the DB is a pro of this approach but I have found the props of the alternative approach to be stronger:
For its downsides (DB storage), a simple |
|
The thing is also that we already went down the path of storing comment IDs in the block comment (in the same db post). I don't think it's ideal, but there's no great alternatives other than maybe storing a Yjs edit. Stripping the block comments is pretty similar. You're right that we should think about suggestions before committing to an approach. Not sure what's best there. Maybe the thing you comment on would be replaced by the content you comment (certain comment type or meta). When you only want to add content, we could store an empty span at the location to insert. |
|
@Mamaduka - thanks for working on this! 🎉 On the topic of placement and storage, have we considered the suggestion from @westonruter to use something like xpath? One challenge with the current approach of storing the note id on the block is that makes adding a note a content change that requires a post save to be stored. Leading to bugs like notes not being saved for new unsaved posts (#72717). One other note: when we implement this we should probably update the floating logic to ensure notes float next to the top of the selected next, not the top of the block as in the current approach. |
Some more inspiration would be text fragments, where the text span is included in the reference, with optional prefix and suffix. This essentially would opt for substring references instead of numeric indices. The problem remains for how to keep such referenced updated as the underlying text changes (or blocks are added, removed, and re-ordered). |
|
Noting that I shared some designs, for your consideration, here: #59445 (comment) |
|
@adamsilverstein, @westonruter, I'm not very familiar with XPath/XPointers. IIRC, you could use them in Puppetter for targeting elements, but that's the end of my experience. I think both will have similar problems as @youknowriad described above. We'll have to update/sync references when the selected text changes, which would also require saving, so I don't think that would resolve the issues mentioned in #72717. We'll just have a problem with different content types being out of sync or not saved. |
Thanks for the link, I didn't realize that was a standard. That approach seems better than xpath for this use case.
I agree there is quite a bit of added complexity to this approach, perhaps there is a hybrid approach where block attributes link to the notes, but notes themselves contain the Text-fragment link. On clear advantage of not storing note ids in blocks would be eliminating the issues we currently have with block duplication, syndication and splitting.
One way around this would be to expand the noteId stored in block meta to an array, enabling multiple linked notes per block. |
39f5b84 to
757d8cc
Compare
I think this is actually fine as-is, and I believe is also how Google Docs handles this scenario, as the comment can (though I agree may not) still relate to the overall selection of text so I don't think it would make sense to remove the inline comment if text within the selection were to change. |
|
@jeffpaul, I think you found a different bug 😄 If you remove parts of the marked text, save the content, and then refresh the page, the issue becomes visible. P.S. I'm working on an alt PR that uses RichText formats, and hope to have it read soon for initial feedback. ScreenshotCleanShot.2026-02-02.at.18.47.24.mp4 |
757d8cc to
43785b2
Compare



What?
Related #59445.
Important
This is an exploration PR for the technical side of this feature and doesn't include anything from design specs.
PR tests the ability to add notes for partial selections within a block's rich text fields. This works without adding content markers to the DB (see annotations package).
How?
@wordpress/annotationspackage.Challenges
Testing Instructions
Testing Instructions for Keyboard
Same.
Screenshots or screencast
CleanShot.2026-01-22.at.16.08.32.mp4