Skip to content

fix(nodeUtil): moved blocks now included in the editor changes #1931

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rmolinamir
Copy link

@rmolinamir rmolinamir commented Aug 9, 2025

Context

#1924

Summary

Previously, only parent changes emitted a "move" (e.g, indentations). Reordering blocks within the same parent was missed. Now, we capture each block’s sibling index and emit a "move" when either parent or index changes.

Changes

  • nodeUtils.ts: On top of the parent IDs, we're now keeping track of each block’s index and emitting a "move" when either parent or index changes.
  • nodeUtils.test.ts: TODO

Copy link

vercel bot commented Aug 9, 2025

@rmolinamir is attempting to deploy a commit to the TypeCell Team on Vercel.

A member of the Team first needs to authorize it.

@rmolinamir rmolinamir marked this pull request as draft August 9, 2025 03:13
Comment on lines +713 to +728
handleDrop: (_view, _event, slice) => {
const draggedBlock = nodeToBlock(
slice.content.child(0),
editor.pmSchema,
);
this.draggedBlockId = draggedBlock.id;
return false;
},
},
filterTransaction: (tr) => {
if (tr.getMeta("uiEvent") === "drop" && this.draggedBlockId) {
tr.setMeta("draggedBlockId", this.draggedBlockId);
this.draggedBlockId = undefined;
}
return true;
},
Copy link
Author

Choose a reason for hiding this comment

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

Ended up attaching the draggedBlockId to the transaction, I'm unsure if this is the ideal approach though 😅

Screen.Recording.2025-08-10.at.12.50.38.AM.mp4

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I don't think this is the right approach. What should happen here is using the order of the blocks only, derive which block has actually moved

Copy link
Author

Choose a reason for hiding this comment

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

That's what I meant here. It's not possible with just indexes.

Say you have an editor with these values: [1,2,3]. If you drag 2 to the first slot, you end up with [2,1,3], but the user could also have dragged 1 into the second slot ending up with [2,1,3], this is why it's impossible to do it with indexes alone. Knowing which block was dragged is necessary if you want to filter the rest of the blocks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, yea. This is a good argument for over reporting on all of the indexes that have changed.

I don't want for dragged blocks to be handled specially in some sort of way, since that will mean having to maintain every possible way the editor may change (to get the most "fine-grained" update), when this should be a general solution.

Sorry to make you do more work here. I didn't see your comment since it was marked as resolved.

Copy link
Author

Choose a reason for hiding this comment

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

No worries at all, that's fair. In that case, would you rather go with the original approach (i.e., only check for blocks with different indexes)?

@rmolinamir rmolinamir requested a review from nperez0111 August 10, 2025 04:59
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.

2 participants