-
Notifications
You must be signed in to change notification settings - Fork 6
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
Fix prosemirror-noting bugs by passing storedMarks to inner editor, and passing up paste meta #409
Conversation
… handled properly by the prosemirror-noting plugin
eaa33e1
to
b2b2266
Compare
…n tests It's not clear why this is happening, and the behaviour of the editor in normal use appears to be correct (e.g. click 'bold' in field, focus field, begin typing works as expected)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great. The tests are really clear.
There are a few non-blocking comments. Lots of value here so keen to let you 🚢 at a cadence which makes sense for stakeholders!
Also non-blocking: ideally each fix would belong in its own PR, which would making managing reverting easier if there were problems downstream for those that don't know the code so well.
}); | ||
|
||
const getEditorWithTextField = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to DRY up this repetition! 👍
Co-authored-by: Jonathon Herbert <jonathon.herbert@guardian.co.uk>
Co-authored-by: Jonathon Herbert <jonathon.herbert@guardian.co.uk>
I will bear the separation of fixes in mind next time - would be keen to get this one out though as it's affecting users of the formats in production at the moment! |
What does this change?
We have encountered a few bugs related to the interaction of nested fields with notes from @guardian/prosemirror-noting - specifically:
This PR fixes these issues by making some changes to the
ProsemirrorFieldView
:storedMarks
defined by the outer editor to the inner editor, applying them on the next transaction in the inner editor. The note extension functionality is managed bystoredMarks
, rather than by setting aninclusive
attribute on the mark, as we see with something likestrong
orem
marks. Until now, we haven't passed stored marks from the outer editor to our fields.dispatchTransaction
- we now update the inner editor first, then update the outer editor.The existing order of operations here was leading to some issues with my
storedMarks
work.When a user moved their cursor in a note within a text field: the inner editor dispatched a transaction, the outer editor (which has the copy of the
prosemirror-noting
plugin, and therefore 'knows' about the note) would then introduce a stored mark representing the note mark, which was passed into the plugin. The inner state change would then finish, with no knowledge of the intermediate transaction from the outer editor that had occurred, effectively ignoring the introduced stored mark.Now, the inner transaction is dispatched, then the outer editor transaction is dispatched, including the stored mark, and it can be applied on the next transaction (e.g. a typed character).
This change also fixed the 'moving over a note boundary' issue.
prosemirror-noting
uses this to identify transactions that are pastes within a note, and apply the note mark to them.Noting without these changes:
![Kapture 2024-06-07 at 12 34 05](https://private-user-images.githubusercontent.com/34686302/337638901-f2b1e554-4395-4216-a60a-005160464c72.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE1MjI0OTcsIm5iZiI6MTcyMTUyMjE5NywicGF0aCI6Ii8zNDY4NjMwMi8zMzc2Mzg5MDEtZjJiMWU1NTQtNDM5NS00MjE2LWE2MGEtMDA1MTYwNDY0YzcyLmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzIxVDAwMzYzN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWNkMDE2ZDNkYTA4NzA2MDRlNTM2YmUxODVjNjFlMGIzYWQ3NmNmMThiODUzOTg5YTM5YWRlOWFkZTAwNjMxNGMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.MgesLwwkkzJg7mED7-SpvlE0-xyRyrc6nfyLpo2BJc0)
Noting with the change:
![Kapture 2024-06-07 at 12 37 45](https://private-user-images.githubusercontent.com/34686302/337638792-336060d2-f3e1-442c-bebb-96006c943f20.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE1MjI0OTcsIm5iZiI6MTcyMTUyMjE5NywicGF0aCI6Ii8zNDY4NjMwMi8zMzc2Mzg3OTItMzM2MDYwZDItZjNlMS00NDJjLWJlYmItOTYwMDZjOTQzZjIwLmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzIxVDAwMzYzN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTJjMDM0M2IyYjdiOWI4MDdlNTNkMDgxMTUxNDVhMDZhZWZjNDU3NjkyOTkyYTFjOTY1ZGQwZTBjYWE2N2Q3MmYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.rkCQnx3olIkeCKsnnJshCM6meXKE989zjD-Sc2cic-k)
How to test
Run the tests, I've added some.
You may want to test in Composer via
yalc
to test the noting behaviour specifically.