Merge pull request #16119 from overleaf/ae-revert-indentation

Revert "Only rebuild changed line indentation decorations (#16092)"

GitOrigin-RevId: 5c4fe9820812551863fc93d74e201bb159e2f14d
This commit is contained in:
Alf Eaton 2023-12-05 11:13:08 +00:00 committed by Copybot
parent 17ac0eb16b
commit d30e876999

View file

@ -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<Decoration>[] = []
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: {