refactor(desktop): reuse XML text ancestor order (#17317)

This commit is contained in:
Vincent Koc
2026-12-06 08:43:43 +08:00
committed by GitHub
parent e5004c11ea
commit 0550f5f0b4
+5 -13
View File
@@ -268,17 +268,15 @@ const outsideRuns = (pointer: string, ends: Ends): readonly Candidate[] => {
const parent = parentBelowRoot(named);
if (parent === undefined) {
const stopped = xmlParentPointer(named);
const chain = [...passed, named].filter(
(element, index, all) => all.indexOf(element) === index,
);
passed.push(named);
// A record directly under the document can still hold a save time. Leave a formatting run out when the paragraph remains.
if (stopped !== undefined && noisy(stopped)) {
const narrower = withoutRuns(chain, noisy);
const narrower = withoutRuns(passed, noisy);
if (narrower.length > 0) return narrower;
}
// generation-cap: ancestor tags climbed to name an element
return [current, ...[...passed.slice(1), named].slice(0, MAX_TAG_CLIMB)]
.filter((element, index, all) => all.indexOf(element) === index)
return passed
.slice(0, 1 + MAX_TAG_CLIMB)
.map((element) => ({ element, pointer: element, identifier: false }));
}
passed.push(named);
@@ -287,13 +285,7 @@ const outsideRuns = (pointer: string, ends: Ends): readonly Candidate[] => {
}
// An ancestor whose text joins a timestamp fails a later save that only restamps it.
if (noisy(named)) {
const narrower = withoutRuns(
[...passed].filter(
(element, index, all) =>
all.indexOf(element) === index && element !== named,
),
noisy,
);
const narrower = withoutRuns(passed, noisy);
if (narrower.length > 0) return narrower;
}
const ranked = [