-
Notifications
You must be signed in to change notification settings - Fork 91
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
Make images block nodes #3282
Make images block nodes #3282
Conversation
fcd9609
to
902d326
Compare
Mh, seems like inserting an image as first element in a new document is broken now 😢 |
3aba528
to
ba7c669
Compare
ba7c669
to
20dddd0
Compare
So @julien-nc and me spent some three more hours debugging the main remaining issue with this PR: inserting a (block node) image as first element into an empty editor breaks due to us doing It turns out to be a Tiptap (or maybe even ProseMirror) bug. I reported ueberdosis/tiptap#3355 upstream. |
20dddd0
to
4d1bfdc
Compare
635e5af
to
e4d4f6b
Compare
e4d4f6b
to
02dc2ba
Compare
Test summaryRun details
View run in Cypress Dashboard ➡️ Flakiness
This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard |
After some further debugging, we came up with a mostly working solution that
@max-nextcloud and me agreed that it is better to get this merged now and follow-up by looking into the underlying Tiptap issue later on. @max-nextcloud are you ok with merging this as is, or do you want to further look into it? |
Can you quickly summarize the remaining issue, so we can file this as a follow up? |
Sure, sorry for not doing so in the first place 🙈 So the fix involves moving the cursor two steps further after inserting the image and before inserting the hard break (if the image is not inserted as first element, which needs other special treatment). This is necessary because per default the cursor is in front of the image after inserting it, but we want to add the hard break afterwards. If you insert an image in between text, this results in the linebreak being inserted two characters further for the moment. I think that's an acceptable tradeoff given that images are block nodes now and most likely it will not happen that often that people insert them in the middle of text anyway. Here's the relevant code: text/src/components/Editor/MediaHandler.vue Lines 199 to 209 in 02dc2ba
If you have a quick idea how to detect that the cursor (i.e. the focus, |
02dc2ba
to
cabbaf2
Compare
/compile |
@mejo- There's still a test failing. I'm not sure what to make of this. I think we are adding two new lines on purpose in the Is this really required. I think it's unfortunate if we change the markdown syntax without any changes being made to the document. Why are those newlines needed? Can't we say every line that only contains an image is considered a block image even if no empty lines follow? Ahh... i guess markdown parsers will then think the line is part of a larger paragraph... Hmm... difficult. |
I think i will exclude 2f7ff70 for now so images still render the way they used to even if inline. |
Signed-off-by: Jonas <[email protected]>
Use markdown-it-image-figures to render standalone images inside `<figure>` elements instead of `<p>` when markdown source gets parsed into HTML. This allows to treat images as block elements by TipTap. Also keep support for inline images to not break markdown files that have inline images. Fixes: #2873 Signed-off-by: Jonas <[email protected]>
Replace `<p>` with `<figure>` now that we use markdown-it-image-figures. Signed-off-by: Jonas <[email protected]>
Signed-off-by: Jonas <[email protected]>
Needed to prevent block images getting merged with next paragraph. Signed-off-by: Jonas <[email protected]>
Tiptap `setImage()` marks the added image as selected when added as first element in the document), which leads to the image being overwritten by subsequent `insertContent()` command. See ueberdosis/tiptap#3355 for the relevant upstream bug. Mitigate this bug by explicitly placing the cursor at the end of the selection between adding the image and the line break. Signed-off-by: Jonas <[email protected]>
Right now we add an empty line after each image so it lives in its own paragraph. This is not needed at the end of the file and we should preserve the number of newlines instead (#3428). But for now it should not block merging the block images pr #3282. Signed-off-by: Max <[email protected]>
387c191
to
8f9a6c4
Compare
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.
I think this can be merged now. I created issues for the remaining things and even if they do not get fixed this is an improvement over the status quo.
/compile |
Signed-off-by: nextcloud-command <[email protected]>
@juliushaertl @mejo- I'm not sure if we should backport this. Right now in 25 images and attachments are often in the same paragraph as the following content. Turning that content into say a heading then also toggles the image as it's part of that paragraph. I think that's pretty bad. At the same time this change is pretty profound and we have not really tested it so much. It will also require a bunch of follow up changes. I don't think they would need to be backported - but still. I wonder if there would be a less intrusive fix we could apply to stable25. |
/backport 0c496fa,4b63cb684897f5512d86ed00cf290b3fffa1df43,5ee1d6b7c6e9edc03222ae470c456209e90b1a7b,59b2b68337bda059a71fbf81e2748f6d7c4d647b,47a203748157f922c17eb297d495d0b247998df0,f4b660d893ca3471310ac65a0a0ea9a475913ea9,8f9a6c4d42814d20916c8bec0a4f916b282a982b to stable25 |
Right now we add an empty line after each image so it lives in its own paragraph. This is not needed at the end of the file and we should preserve the number of newlines instead (#3428). But for now it should not block merging the block images pr #3282. Signed-off-by: Max <[email protected]>
Right now we add an empty line after each image so it lives in its own paragraph. This is not needed at the end of the file and we should preserve the number of newlines instead (#3428). But for now it should not block merging the block images pr #3282. Signed-off-by: Max <[email protected]>
Right now we add an empty line after each image so it lives in its own paragraph. This is not needed at the end of the file and we should preserve the number of newlines instead (#3428). But for now it should not block merging the block images pr #3282. Signed-off-by: Max <[email protected]>
Right now we add an empty line after each image so it lives in its own paragraph. This is not needed at the end of the file and we should preserve the number of newlines instead (#3428). But for now it should not block merging the block images pr #3282. Signed-off-by: Max <[email protected]>
Use markdown-it-image-figures to render standalone images inside
<figure>
elements instead of<p>
when markdown source gets parsedinto HTML. This allows to treat images as block elements by TipTap.
Also keep support for inline images to not break markdown files that
have inline images.
Summary