Skip to content

code/editor/find/settle-scroll

import { … } from 'zidane-ui/code/editor'ui/src/code/editor/find/settle-scroll.ts

Functions#

settleScrollFunction#

Scrolls root so the target ends offset px below its top and holds it there while the content above settles; stops on stillness, after two seconds, or when the user scrolls.

TypeScript
function settleScroll(
  root: HTMLElement,
  target: () => ScrollTarget,
  options?: { offset?: number | ((root: HTMLElement) => number); smooth?: boolean },
): () => void
Parameters
NameTypeDefaultDescription
rootHTMLElement

The scroll container.

target() => ScrollTarget

Read every frame, so it can return a freshly rendered element; null stops.

options?{ offset?: number | ((root: HTMLElement) => number); smooth?: boolean }{}

offset: gap above the target, or a function of root for one that changes; smooth: ease in over several frames (default) or jump at once.

() => void

A function that cancels the scroll.

ui/src/code/editor/find/settle-scroll.ts:37

Types#

ScrollTargetType#

Where to go: an element, or an estimated position in the scroll content (top, in scrollTop terms) for a line that is not rendered yet.

TypeScript
type ScrollTarget = HTMLElement | { top: number } | null | undefined

ui/src/code/editor/find/settle-scroll.ts:25