MCPcopy Create free account
hub / github.com/Noumena-Network/code / drainAdaptive

Function drainAdaptive

src/ink/render-node-to-output.ts:127–160  ·  view source on GitHub ↗
(
  node: DOMElement,
  pending: number,
  innerHeight: number,
)

Source from the content-addressed store, hash-verified

125
126// xterm.js adaptive drain. Returns rows applied; mutates pendingScrollDelta.
127function drainAdaptive(
128 node: DOMElement,
129 pending: number,
130 innerHeight: number,
131): number {
132 const sign = pending > 0 ? 1 : -1
133 let abs = Math.abs(pending)
134 let applied = 0
135 // Snap excess beyond animation window so big flicks don't coast.
136 if (abs > SCROLL_MAX_PENDING) {
137 applied += sign * (abs - SCROLL_MAX_PENDING)
138 abs = SCROLL_MAX_PENDING
139 }
140 // ≤5: drain all (slow click = instant). Above: small fixed step.
141 const step =
142 abs <= SCROLL_INSTANT_THRESHOLD
143 ? abs
144 : abs < SCROLL_HIGH_PENDING
145 ? SCROLL_STEP_MED
146 : SCROLL_STEP_HIGH
147 applied += sign * step
148 const rem = abs - step
149 // Cap total at innerHeight-1 so DECSTBM blit+shift fast path fires
150 // (matches drainProportional). Excess stays in pendingScrollDelta.
151 const cap = Math.max(1, innerHeight - 1)
152 const totalAbs = Math.abs(applied)
153 if (totalAbs > cap) {
154 const excess = totalAbs - cap
155 node.pendingScrollDelta = sign * (rem + excess)
156 return sign * cap
157 }
158 node.pendingScrollDelta = rem > 0 ? sign * rem : undefined
159 return applied
160}
161
162// Native proportional drain. step = max(MIN, floor(abs*3/4)), capped at
163// innerHeight-1 so DECSTBM + blit+shift fast path fire.

Callers 1

renderNodeToOutputFunction · 0.85

Calls 1

maxMethod · 0.80

Tested by

no test coverage detected