Skip to content

feat: Merged getSelection and getSelectionCutBlocks #1699

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

Open
wants to merge 255 commits into
base: main
Choose a base branch
from

Conversation

matthewlipski
Copy link
Collaborator

This PR merges the currently 2 separate getSelection methods into one.

The functionality of getSelection is unchanged, only the additional fields from getSelectionCutBlocks have been added (with blocks renamed to cutBlocks).

getSelectionCutBlocks is slightly different as the blocks field has been renamed to cutBlocks so as not to clash with the same field that was already in getSelection. Also, now returns undefined when the selection is collapsed.

TODO:

  • Review increment selection test cases as these are erroring. @Yousef are they necessary? Since we already test offsets in the get selection tests and AFAIK some of the selections represented here arent actually possible

Copy link

vercel bot commented May 19, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
blocknote ✅ Ready (Inspect) Visit Preview May 19, 2025 4:51pm
blocknote-website ✅ Ready (Inspect) Visit Preview May 19, 2025 4:51pm

Comment on lines +191 to +194
_meta: {
startPos: tr.selection.from,
endPos: tr.selection.to,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is useful to have, so let's just make it meta

Comment on lines +183 to +190
blocksCutAtStart:
startNode.nodeSize !== cutStartNode!.nodeSize
? $startBlockBeforePos.nodeAfter!.attrs.id
: undefined,
blocksCutAtEnd:
endNode!.nodeSize !== cutEndNode!.nodeSize
? $endBlockBeforePos.nodeAfter!.attrs.id
: undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still going to have to push back on this naming, I don't know what a blocksCutAtStart means.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I think I understand what cutBlocks are now from the tests. It is the slice of content that the selection range is over. imo, I don't think we should introduce another term on top of what prosemirror has already established for this (a slice).

I think it should be: blockSlice, I still don't understand the usefulness of blocksCutAtStart & blocksCutAtEnd, but I think it is something more like startBlockId or sliceBlockId

Comment on lines +153 to +154
node.type.name === startNode.type.name &&
node.attrs.id === startNode.attrs.id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
node.type.name === startNode.type.name &&
node.attrs.id === startNode.attrs.id
node.eq(startNode)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah maybe this won't match because it is the sliced node?

Comment on lines +160 to +161
node.type.name === endNode.type.name &&
node.attrs.id === endNode.attrs.id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
node.type.name === endNode.type.name &&
node.attrs.id === endNode.attrs.id
node.eq(endNode)

Comment on lines +14 to +17
cutBlocks: Block<BSchema, I, S>[];
blocksCutAtStart: string | undefined;
blocksCutAtEnd: string | undefined;
_meta: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add JSDoc to describe what each of these mean, and how they are different from each other?

Base automatically changed from feature/ai to main May 20, 2025 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants