From f7f4a50d35ac84e3600e97ae2c5c553c39ed7abf Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Wed, 30 Oct 2024 14:09:23 -0700 Subject: [PATCH] Desktop: Custom CSS: Add cm-listItem class to lines with list items, don't add region start/end markers for items that are always single-line (#11291) --- .../CodeMirror/markdown/decoratorExtension.ts | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/editor/CodeMirror/markdown/decoratorExtension.ts b/packages/editor/CodeMirror/markdown/decoratorExtension.ts index a9627f79a..7f46ed2ad 100644 --- a/packages/editor/CodeMirror/markdown/decoratorExtension.ts +++ b/packages/editor/CodeMirror/markdown/decoratorExtension.ts @@ -84,6 +84,18 @@ const tableDelimiterDecoration = Decoration.line({ attributes: { class: 'cm-tableDelimiter' }, }); +const orderedListDecoration = Decoration.line({ + attributes: { class: 'cm-orderedList' }, +}); + +const unorderedListDecoration = Decoration.line({ + attributes: { class: 'cm-unorderedList' }, +}); + +const listItemDecoration = Decoration.line({ + attributes: { class: 'cm-listItem' }, +}); + const horizontalRuleDecoration = Decoration.mark({ attributes: { class: 'cm-hr' }, }); @@ -97,6 +109,10 @@ const nodeNameToLineDecoration: Record = { 'CodeBlock': codeBlockDecoration, 'BlockMath': mathBlockDecoration, 'Blockquote': blockQuoteDecoration, + 'OrderedList': orderedListDecoration, + 'BulletList': unorderedListDecoration, + + 'ListItem': listItemDecoration, 'SetextHeading1': header1LineDecoration, 'ATXHeading1': header1LineDecoration, @@ -122,6 +138,14 @@ const nodeNameToMarkDecoration: Record = { 'TaskMarker': taskMarkerDecoration, }; +const multilineNodes = { + 'FencedCode': true, + 'CodeBlock': true, + 'BlockMath': true, + 'Blockquote': true, + 'OrderedList': true, + 'BulletList': true, +}; type DecorationDescription = { pos: number; length: number; decoration: Decoration }; @@ -179,8 +203,8 @@ const computeDecorations = (view: EditorView) => { addDecorationToRange(viewFrom, viewTo, decoration); } - // Only block decorations will have differing first and last lines - if (blockDecorated) { + // Only certain block decorations will have differing first and last lines + if (blockDecorated && multilineNodes.hasOwnProperty(node.name)) { // Allow different styles for the first, last lines in a block. if (viewFrom === node.from) { addDecorationToLines(viewFrom, viewFrom, regionStartDecoration);