MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / clamped_scroll

Function clamped_scroll

crates/openshell-tui/src/app.rs:2820–2829  ·  view source on GitHub ↗

Compute a new scroll position after applying `delta`, clamped so the last viewport of content remains visible. `current` - current scroll offset `delta` - lines to scroll (positive = down, negative = up) `total` - total number of lines/items `viewport` - visible line count (0 before first draw, treated as 1)

(current: usize, delta: isize, total: usize, viewport: usize)

Source from the content-addressed store, hash-verified

2818/// * `total` - total number of lines/items
2819/// * `viewport` - visible line count (0 before first draw, treated as 1)
2820fn clamped_scroll(current: usize, delta: isize, total: usize, viewport: usize) -> usize {
2821 let max = total.saturating_sub(viewport.max(1));
2822 if delta < 0 {
2823 current.saturating_sub(delta.unsigned_abs())
2824 } else {
2825 #[allow(clippy::cast_sign_loss)]
2826 let stepped = current + delta as usize;
2827 stepped.min(max)
2828 }
2829}
2830
2831#[cfg(test)]
2832mod tests {

Callers 1

scroll_policyMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected