feat(API): add insertAt method#1140
Open
ReFFaT wants to merge 4 commits into
Open
Conversation
Reviewer's GuideAdds a new insertAt(markup, index?) API across editor implementations that inserts at the current cursor by default, or at an absolute position with bounds mapped to prepend/append, and wires it through public types plus tests for both Wysiwyg and markup editors. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
WysiwygContentHandler.insertAtyou computedocSizeasstate.doc.nodeSize - 2, which is a bit opaque and tied to ProseMirror internals; consider using a more direct/semantic measure (e.g.state.doc.content.size) so the meaning and bounds are clearer and less brittle. - Both branches of
WysiwygContentHandler.insertAtparse the markup and then conditionally usefirstChild?.content; you could parse once at the top of the method and reuse the resulting fragment to avoid duplicate work and keep the code more linear. - The CodeMirror
insertAtupdates the selection to the end of the inserted markup while the WysiwyginsertAtleaves the selection at the original cursor, which may surprise callers of the sharedinsertAtAPI—consider aligning the selection behavior across implementations or documenting the difference explicitly.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `WysiwygContentHandler.insertAt` you compute `docSize` as `state.doc.nodeSize - 2`, which is a bit opaque and tied to ProseMirror internals; consider using a more direct/semantic measure (e.g. `state.doc.content.size`) so the meaning and bounds are clearer and less brittle.
- Both branches of `WysiwygContentHandler.insertAt` parse the markup and then conditionally use `firstChild?.content`; you could parse once at the top of the method and reuse the resulting fragment to avoid duplicate work and keep the code more linear.
- The CodeMirror `insertAt` updates the selection to the end of the inserted markup while the Wysiwyg `insertAt` leaves the selection at the original cursor, which may surprise callers of the shared `insertAt` API—consider aligning the selection behavior across implementations or documenting the difference explicitly.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I added the isertAt method, which adds to the cursor if the parameter is not passed, and to the index if it is passed. If the index is out of range, it uses the standard isert and prepend methods.
Summary by Sourcery
Add support for inserting markup at a specific position or at the current cursor across editor implementations.
New Features:
Documentation:
Tests: