mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-17 05:40:26 +01:00
Answer architecture round 1: every container joining several walks sums their projections before it joins, the portable reduction refuses a list whose spelling is refused, and heldTextLength moves beside textLength
This commit is contained in:
@@ -86,6 +86,17 @@ export function textLength(node: AdfNode): number {
|
||||
return node.text?.length ?? 0
|
||||
}
|
||||
|
||||
// A line spells every character of its nodes' text at least once, so this much text cannot fit.
|
||||
export function heldTextLength(nodes: readonly AdfNode[]): number {
|
||||
let length = 0
|
||||
const pending = [...nodes]
|
||||
for (let node = pending.pop(); node !== undefined; node = pending.pop()) {
|
||||
length += textLength(node)
|
||||
for (const child of nodeContent(node)) pending.push(child)
|
||||
}
|
||||
return length
|
||||
}
|
||||
|
||||
export function mergeAdjacentText(nodes: readonly AdfNode[], joins: (previous: AdfNode, node: AdfNode) => boolean): AdfNode[] {
|
||||
const merged: AdfNode[] = []
|
||||
for (const node of nodes) {
|
||||
|
||||
Reference in New Issue
Block a user