| 6 | * @param factor The scaling factor for the margin (e.g., 0.25 for small, 0.5 for medium, 1.0 for full). |
| 7 | */ |
| 8 | export 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 | |
| 43 | export default scrollPastEndCustom; |