From 9dd5eda171ae3d45a8bdcc926d667f16a7c0aee5 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Wed, 6 Aug 2025 12:06:44 +0100 Subject: [PATCH] Only decorate itemize end line when no other text on line (#27601) GitOrigin-RevId: 6c6b3cfe99cfec4b09476e15adc2f0758b033865 --- .../extensions/visual/atomic-decorations.ts | 28 +++++++++++-------- .../extensions/visual/utils/line.ts | 5 ++++ 2 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 services/web/frontend/js/features/source-editor/extensions/visual/utils/line.ts diff --git a/services/web/frontend/js/features/source-editor/extensions/visual/atomic-decorations.ts b/services/web/frontend/js/features/source-editor/extensions/visual/atomic-decorations.ts index 03b9aea758..92f0ae4934 100644 --- a/services/web/frontend/js/features/source-editor/extensions/visual/atomic-decorations.ts +++ b/services/web/frontend/js/features/source-editor/extensions/visual/atomic-decorations.ts @@ -86,6 +86,7 @@ import { mathAncestorNode, parseMathContainer, } from '../../utils/tree-operations/math' +import { lineContainsOnlyNode } from './utils/line' type Options = { previewByPath: (path: string) => PreviewPath | null @@ -325,14 +326,20 @@ export const atomicDecorations = (options: Options) => { !selectionIntersects(state.selection, end) && getListItems(nodeRef.node).length > 0 // not empty ) { - decorations.push( - Decoration.replace({ - block: true, - }).range(begin.from, begin.to), - Decoration.replace({ - block: true, - }).range(end.from, end.to) - ) + if (lineContainsOnlyNode(beginLine, beginNode)) { + decorations.push( + Decoration.replace({ + block: true, + }).range(begin.from, begin.to) + ) + } + if (lineContainsOnlyNode(endLine, endNode)) { + decorations.push( + Decoration.replace({ + block: true, + }).range(end.from, end.to) + ) + } } } } else if (nodeRef.type.is('TabularEnvironment')) { @@ -904,10 +911,7 @@ export const atomicDecorations = (options: Options) => { const line = state.doc.lineAt(nodeRef.from) - const lineContainsOnlyNode = - line.text.trim().length === nodeRef.to - nodeRef.from - - if (lineContainsOnlyNode) { + if (lineContainsOnlyNode(line, nodeRef)) { const Widget = state.readOnly ? GraphicsWidget : EditableGraphicsWidget diff --git a/services/web/frontend/js/features/source-editor/extensions/visual/utils/line.ts b/services/web/frontend/js/features/source-editor/extensions/visual/utils/line.ts new file mode 100644 index 0000000000..77cbf38ae1 --- /dev/null +++ b/services/web/frontend/js/features/source-editor/extensions/visual/utils/line.ts @@ -0,0 +1,5 @@ +import { Line } from '@codemirror/state' +import { SyntaxNodeRef } from '@lezer/common' + +export const lineContainsOnlyNode = (line: Line, nodeRef: SyntaxNodeRef) => + line.text.trim().length === nodeRef.to - nodeRef.from