MCPcopy Create free account
hub / github.com/codeaashu/claude-code / drainAdaptive

Function drainAdaptive

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

Source from the content-addressed store, hash-verified

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