MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / scrollPastEndCustom

Function scrollPastEndCustom

src/cm/scrollPastEnd.ts:8–41  ·  view source on GitHub ↗
(factor: number)

Source from the content-addressed store, hash-verified

6 * @param factor The scaling factor for the margin (e.g., 0.25 for small, 0.5 for medium, 1.0 for full).
7 */
8export function scrollPastEndCustom(factor: number): Extension {
9 if (factor <= 0) {
10 return [];
11 }
12
13 const plugin = ViewPlugin.fromClass(
14 class {
15 height = 0;
16 attrs = { style: "" };
17
18 update(update: ViewUpdate) {
19 const { view } = update;
20 const anyView = view as any;
21 const maxScrollHeight =
22 (anyView.viewState?.editorHeight ?? 0) -
23 view.defaultLineHeight -
24 (anyView.documentPadding?.top ?? 0) -
25 0.5;
26 const height = Math.max(0, Math.round(maxScrollHeight * factor));
27 if (height !== this.height) {
28 this.height = height;
29 this.attrs = { style: `padding-bottom: ${height}px` };
30 }
31 }
32 },
33 );
34
35 return [
36 plugin,
37 EditorView.contentAttributes.of(
38 (view) => view.plugin(plugin)?.attrs || null,
39 ),
40 ];
41}
42
43export default scrollPastEndCustom;

Callers 1

buildFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected