From d30e8769990f5834a340a63e576b26181774538d Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Tue, 5 Dec 2023 11:13:08 +0000 Subject: [PATCH] Merge pull request #16119 from overleaf/ae-revert-indentation Revert "Only rebuild changed line indentation decorations (#16092)" GitOrigin-RevId: 5c4fe9820812551863fc93d74e201bb159e2f14d --- .../extensions/line-wrapping-indentation.ts | 73 ++----------------- 1 file changed, 6 insertions(+), 67 deletions(-) diff --git a/services/web/frontend/js/features/source-editor/extensions/line-wrapping-indentation.ts b/services/web/frontend/js/features/source-editor/extensions/line-wrapping-indentation.ts index b745df8201..38dd85b51a 100644 --- a/services/web/frontend/js/features/source-editor/extensions/line-wrapping-indentation.ts +++ b/services/web/frontend/js/features/source-editor/extensions/line-wrapping-indentation.ts @@ -78,14 +78,12 @@ export const lineWrappingIndentation = (visual: boolean) => { update(update: ViewUpdate) { const maxIndent = view.state.field(field) - if (maxIndent !== previousMaxIndent) { + if ( + maxIndent !== previousMaxIndent || + update.geometryChanged || + update.viewportChanged + ) { value.decorations = buildDecorations(view, maxIndent) - } else if (update.geometryChanged || update.viewportChanged) { - value.decorations = updateDecorations( - value.decorations, - update, - maxIndent - ) } previousMaxIndent = maxIndent @@ -113,6 +111,7 @@ export const buildDecorations = (view: EditorView, maxIndent: number) => { let from = 0 for (const line of doc.iterLines()) { + // const indent = line.match(/^(\s*)/)[1].length const indent = calculateIndent(line, tabSize, maxIndent) if (indent) { @@ -125,66 +124,6 @@ export const buildDecorations = (view: EditorView, maxIndent: number) => { return Decoration.set(decorations) } -export const updateDecorations = ( - decorations: DecorationSet, - update: ViewUpdate, - maxIndent: number -) => { - const add: Range[] = [] - - const { doc, tabSize } = update.state - - const changedLinesFrom = new Set() - - let filterFrom = doc.length - let filterTo = 0 - - update.changes.iterChangedRanges((fromA, toA, fromB, toB) => { - // remove changed lines - const fromALineNumber = doc.lineAt(fromA).number - const toALineNumber = doc.lineAt(toA).number - - for ( - let lineNumber = fromALineNumber; - lineNumber <= toALineNumber; - lineNumber++ - ) { - const line = doc.line(lineNumber) - changedLinesFrom.add(line.from) - filterFrom = Math.min(line.from, filterFrom) - filterTo = Math.max(line.from, filterTo) - } - - // add changed lines - const fromBLineNumber = doc.lineAt(fromB).number - const toBLineNumber = doc.lineAt(toB).number - - for ( - let lineNumber = fromBLineNumber; - lineNumber <= toBLineNumber; - lineNumber++ - ) { - const line = doc.line(lineNumber) - const indent = calculateIndent(line.text, tabSize, maxIndent) - - if (indent) { - add.push(lineIndentDecoration(indent).range(line.from)) - } - } - }) - - return decorations - .update({ - filter(from) { - return !changedLinesFrom.has(from) - }, - filterFrom, - filterTo, - }) - .map(update.changes) - .update({ add }) -} - const lineIndentDecoration = (indent: number) => Decoration.line({ attributes: {