
fixing two bugs stacked on top of each other in ProseMirror
i'm building a markdown editor built on Milkdown (which wraps ProseMirror). i hit a bug in how marks behave when you join blocks together. the bug type a bold heading. move your cursor to the start of it. press Backspace. the heading joins into the paragraph above, but the bold marks bleed into the previously-unstyled paragraph text. i assumed this was a bug in joinTextblockBackward . it wasn't. what's actually going on when you press Backspace at position 0 of a textblock, joinTextblockBackward fires. under the hood, joinTextblocksAround calls: replaceStep ( state . doc , beforePos , afterPos , Slice . empty ) this deletes the boundary between the two blocks. the Fitter algorithm stitches the content of the second block into the first. it doesn't touch inline marks. the text nodes transfer as-is, bold and all. there's a clearIncompatible function that strips marks disallowed by the target node type, but paragraphs allow bold, so nothing gets stripped. there's also splitBlockKeepMarks
Continue reading on Dev.to
Opens in a new tab

