Skip to content
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

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions packages/editor/CodeMirror/markdown/decoratorExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
});
Expand All @@ -97,6 +109,10 @@ const nodeNameToLineDecoration: Record<string, Decoration> = {
'CodeBlock': codeBlockDecoration,
'BlockMath': mathBlockDecoration,
'Blockquote': blockQuoteDecoration,
'OrderedList': orderedListDecoration,
'BulletList': unorderedListDecoration,

'ListItem': listItemDecoration,

'SetextHeading1': header1LineDecoration,
'ATXHeading1': header1LineDecoration,
Expand All @@ -122,6 +138,14 @@ const nodeNameToMarkDecoration: Record<string, Decoration> = {
'TaskMarker': taskMarkerDecoration,
};

const multilineNodes = {
'FencedCode': true,
'CodeBlock': true,
'BlockMath': true,
'Blockquote': true,
'OrderedList': true,
'BulletList': true,
};

type DecorationDescription = { pos: number; length: number; decoration: Decoration };

Expand Down Expand Up @@ -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);
Expand Down
Loading