Repository navigation
Only apply markdown decorations when the note has markdown enabled - #3408
gunjanjaswal wants to merge 5 commits into
Conversation
|
Gentle bump on this one. It only applies the markdown decorations when the note actually contains markdown, so plain notes stop getting decorated. It's been sitting a while and is still green and mergeable. Happy to rebase if it's drifted from trunk, just flagging it's ready for a look whenever someone has a moment. |
|
Friendly bump on this. It's been open a while without a first look. The change is small and self-contained: only apply the markdown decorations when the note actually has markdown enabled, so plain notes stop getting them. Glad to rebase or adjust anything if that makes review easier. |
|
I support this, would be great to have normal plain text formatting back when no markdown is selected |
|
Gentle bump now that @lotard has chimed in above wanting the same thing. It's a small, self-contained change: markdown decorations only get applied when the note actually has markdown turned on, so plain notes stop getting decorated. Still green and mergeable, and I'm glad to rebase if it's drifted from trunk. Would really appreciate a first look whenever someone has a moment. |
stephdau
left a comment
There was a problem hiding this comment.
Thanks for picking this up, and sorry for the long wait! The change fixes the main case in #3379: a plain-text note opens with no Markdown styling. 👍
One thing needs fixing before we merge. Turning Markdown on or off for an open note in edit mode doesn't update the styling until the next edit. setDecorators only runs on mount, on content changes, on composition end and on search-query changes. When systemTags changes, componentDidUpdate only warms the renderer, and the editor is keyed by note ID, so it doesn't remount either. In practice:
- Open a Markdown note containing
# heading, then turn Markdown off: the heading styling stays until you type. - Turn Markdown on for a plain note: the text stays plain until you type.
(Turning it off from preview mode works, because the editor mounts fresh.) We reproduced this locally on the branch. The fix should be small. In the existing branch in componentDidUpdate:
if (
prevProps.noteId !== this.props.noteId ||
prevProps.note.systemTags !== this.props.note.systemTags
) {
this.warmMarkdownRendererIfNeeded();
this.setDecorators();
}Two smaller suggestions:
- Consider making
markdownEnabledrequired instead of defaulting it totrue. Today a caller that leaves it out silently gets decorations again, which is how #3379 happened, and the type checker wouldn't catch it. - A test on the editor side would help. The new test covers the helper, but nothing checks that
NoteContentEditorpasses the note's tag or updates when the tag changes. That's where this regression lives. Even a small test that switchessystemTagson a mounted editor would cover the bug above.
Thanks again!
Addresses the review on Automattic#3408. Toggling markdown for a note open in edit mode changes systemTags but neither remounts the editor (it is keyed by note id) nor edits content, so setDecorators never re-ran and the styling stayed stale until the next keystroke. Re-run it from componentDidUpdate when noteId or systemTags changes. Also make markdownEnabled a required argument to getMarkdownDecorations so a caller that omits it can't silently fall back to decorating (the path that let Automattic#3379 through), and add an editor-side test that drives componentDidUpdate across a systemTags toggle to cover the regression directly.
|
Thanks for the thorough review, and for reproducing it on the branch, that pinned it exactly. Fixed all three:
Green locally: |
stephdau
left a comment
There was a problem hiding this comment.
Brilliant, @gunjanjaswal; thanks for the quick turnaround! This works as expected now: turning Markdown on or off for an open note updates the styling right away, in both directions, and plain-text notes stay plain. I tested it locally on the branch. Making markdownEnabled required and adding the editor-side test are both nice improvements. 🙌
Two optional notes, fine to skip:
- The new editor test mocks
setDecorators, so it covers thecomponentDidUpdatewiring, but not thatsetDecoratorspasses the note's tag togetMarkdownDecorations. virtual: truein themonaco-editormock isn't needed, since the package is installed.
Approving. Thanks again for fixing #3379!
Its package entry isn't resolvable by jest, so the mock registration throws 'Cannot find module' without it. Comment so the next reader doesn't remove it.
|
Thanks! On your two notes: the first is fair — the test proves the wiring but stubs On the second: |
|
Gentle nudge on this one, @stephdau — thanks again for the review and approval. Is there anything else needed from me before it can land, or is it just waiting on a committer to merge? Happy to rebase if it's drifted since. |
|
Another gentle nudge, @stephdau. This one's been approved and green since mid-October. Happy to rebase if it's drifted at all, just let me know if anything's blocking the merge. No rush, only keeping it on the radar. |
Fixes #3379.
Markdown decorations (headings, bold, italic, list markers, and so on) were applied in the editor even when the note had Markdown disabled. Every other Markdown behavior in
note-content-editor.tsxgates on the note'smarkdownsystem tag, but the decoration path insetDecoratorsdid not, so a plain note with a line like# commentor*.confstill got heading/emphasis styling. This is the v2.26.0 regression reported in #3379.Changes proposed
markdown-decorations.ts:getMarkdownDecorationsnow takes amarkdownEnabledflag (defaults totrue) and returns[]when it is false.note-content-editor.tsx: passnote.systemTags.includes('markdown'). The existingclear()stays unconditional, so decorations are removed when Markdown is toggled off on an open note.markdown-decorations.test.ts: add a case asserting no decorations are returned when markdown is disabled.Testing instructions
npx jest lib/markdown-decorations.test.tsOr manually: open a note with Markdown disabled and a body containing
# headingor**bold**, confirm the text stays plain, then toggle Markdown on and confirm the styling appears.