Skip to content
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

Map positions forward to maintain key stability #74

Merged
merged 4 commits into from
Feb 1, 2024

Conversation

smoores-dev
Copy link
Collaborator

@smoores-dev smoores-dev commented Dec 13, 2023

Rather than attempting to map the new node positions backward to determine what the key used to be for that node, start with the previous positions and map them forward, taking care to skip any positions that are deleted by the transaction, and adding any new nodes that didn't exist in the old doc. This improves stability and correctness in more complex cases, such as splitting or wrapping nodes, and nested deletions.

Fixes #73.

This is the same change as #91, but for the old architecture!

@smoores-dev
Copy link
Collaborator Author

smoores-dev commented Dec 18, 2023

Howdy, anyone on @nytimes/react-prosemirror-maintainers wanna give this a peek before we all go into hibernation for the holidays?

Edit: Dang, I guess that team is private maybe? Gonna just tag people: @eelzon, @gabrielainsf, @annabialas, @halfghaninne, @saranrapjs

@smoores-dev smoores-dev changed the title Handle node split edge case in react plugin. Map positions forward to maintain key stability Jan 31, 2024
@saranrapjs
Copy link
Member

Is the test diff here expected?

@smoores-dev
Copy link
Collaborator Author

Nope! Haha. I forgot that this version of the plugin doesn't track the positions of text nodes; fixing now!

Rather than attempting to map the new node positions backward to
determine what the key used to be for that node, start with the previous
positions and map them forward, taking care to skip any positions that
are deleted by the transaction, and adding any new nodes that didn't
exist in the old doc. This improves stability and correctness in more
complex cases, such as splitting or wrapping nodes, and nested
deletions.
"[javascript][typescript]": {
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated to this PR, should we remove this file from source control? I know VS Code is very popular, but is it normal to have these kinds of editor settings checked in? I know it's common practice internally at some companies, but I'm not sure I see it much in the OSS world.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For VS code, especially with PnP, I think it's pretty standard? It's only project-specific settings. I actually was just thinking that the codeActionsOnSave settings should probably be removed from here, though; those are really a user preference and not particular to this project

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there an easy way for Code users to have their own settings that overlay these?

Copy link
Contributor

Choose a reason for hiding this comment

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

Interestingly, the TypeScript project has template files with a comment suggesting that you maybe use them: https://github.com/microsoft/TypeScript/tree/main/.vscode

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Huh, that is interesting. The VS Code docs suggest that sharing these among developers is one of the intended use cases: https://code.visualstudio.com/docs/getstarted/settings#_workspace-settings, which is how I'd always understood it (it's why they specifically live in the project directory, rather than elsewhere). The settings here take precedence over user settings, but anything unset here will fall back to user settings. So I think we should probably remove things that are preferences, but not really required for the project to "work" (like the auto-fix-on-save), but leave things like the default formatter config and PnP configurations for typescript, eslint, and prettier, since those are unintuitive to set up and required to have any sort of working editor support

Copy link
Contributor

Choose a reason for hiding this comment

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

That sounds fine to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done!

Copy link
Contributor

@tilgovi tilgovi left a comment

Choose a reason for hiding this comment

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

Looks good. Is there any test we could add that failed before and passes now?

@smoores-dev
Copy link
Collaborator Author

Yeah, good call. I can try to replicate #73 or #85 (maybe both, actually) in a unit test!

@tilgovi
Copy link
Contributor

tilgovi commented Jan 31, 2024

Yeah, good call. I can try to replicate #73 or #85 (maybe both, actually) in a unit test!

That'd be awesome, if we can!

@smoores-dev
Copy link
Collaborator Author

Working on another thing in the moment but I should have a chance to come back to this in a bit!

@smoores-dev
Copy link
Collaborator Author

Added tests for both cases, and verified that they currently fail on main and pass on this branch!

Copy link
Contributor

@tilgovi tilgovi left a comment

Choose a reason for hiding this comment

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

Looks good. Individual commits are great, too. Keep it as a merge commit?

@smoores-dev smoores-dev merged commit e849142 into main Feb 1, 2024
2 checks passed
@smoores-dev smoores-dev deleted the key-plugin-handle-new-node branch February 1, 2024 23:49
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.

Encountered two children with the same key for node views
3 participants