@bhsd/codemirror-stickyscroll 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -10
- package/dist/compute.js +15 -14
- package/dist/facet.d.ts +0 -2
- package/dist/facet.js +1 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.js +1 -2
- package/dist/render.js +1 -10
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
> VS Code / Monaco-style **sticky scroll** (sticky lines) for [CodeMirror 6](https://codemirror.net/).
|
|
4
4
|
|
|
5
|
-
This is a fork of [@fazelstudio/codemirror-stickyscroll](https://github.com/fazelstudio/codemirror-stickyscroll)
|
|
5
|
+
This is a fork of [@fazelstudio/codemirror-stickyscroll](https://github.com/fazelstudio/codemirror-stickyscroll)
|
|
6
|
+
that adds support for [foldService](https://codemirror.net/docs/ref/#language.foldService),
|
|
7
|
+
which makes it compatible with legacy [StreamParser](https://codemirror.net/docs/ref/#language.StreamParser)
|
|
8
|
+
languages that register folding. This personal fork also removes some unused features.
|
|
6
9
|
|
|
7
10
|
Sticky lines keep the *opening* lines of the enclosing scopes (function, class,
|
|
8
11
|
if/loop blocks, …) pinned at the top of the editor while you scroll — exactly
|
|
@@ -15,16 +18,17 @@ extension** (no fork of `@codemirror/*`).
|
|
|
15
18
|
throttle keeps the bar glued to the scroll position; no "jumpy" updates.
|
|
16
19
|
- **Click-to-jump with margin compensation** — clicking a sticky line scrolls
|
|
17
20
|
the target line to the top *plus* the current bar height, so the line you
|
|
18
|
-
jump to is never hidden behind the bar. Keyboard (`Enter`/`Space`) +
|
|
21
|
+
jump to is never hidden behind the bar. Keyboard (`Enter`/`Space`) +
|
|
22
|
+
`role="button"` for a11y.
|
|
19
23
|
- **Reuses the consumer's theme** — the bar re-highlights lines through the
|
|
20
24
|
*active* highlight styles of the editor (`highlightingFor`), or clones the
|
|
21
25
|
already-rendered DOM line when available. The package **never** registers its
|
|
22
26
|
own `syntaxHighlighting(...)`.
|
|
23
|
-
- **Language-agnostic** — detection is based on `foldNodeProp` or `foldService`
|
|
24
|
-
`@codemirror/language` (the fold services / fold node props that every
|
|
27
|
+
- **Language-agnostic** — detection is based on `foldNodeProp` or `foldService`
|
|
28
|
+
from `@codemirror/language` (the fold services / fold node props that every
|
|
25
29
|
`@codemirror/lang-*` already registers). It includes a smart, generic denylist
|
|
26
|
-
that works across multiple languages (JS/TS, Python, Rust, Go, etc.) out of
|
|
27
|
-
and gracefully handles data languages like JSON.
|
|
30
|
+
that works across multiple languages (JS/TS, Python, Rust, Go, etc.) out of
|
|
31
|
+
the box, and gracefully handles data languages like JSON.
|
|
28
32
|
- **Gutter alignment, horizontal sync, RTL, resize-proof** — line numbers are
|
|
29
33
|
aligned with the real gutter (width tracked via `ResizeObserver`), the bar
|
|
30
34
|
follows horizontal scroll, and it reacts to font/zoom/resize changes.
|
|
@@ -72,12 +76,8 @@ interface StickyScrollOptions {
|
|
|
72
76
|
```ts
|
|
73
77
|
import {
|
|
74
78
|
stickyScroll,
|
|
75
|
-
stickyScrollFacet, // the configuration Facet (compose/override per instance)
|
|
76
79
|
defaultExcludeNode, // default denylist implementation
|
|
77
|
-
makeStickyScrollConfig, // merge options with defaults
|
|
78
|
-
stickyScrollBaseTheme, // layout-only base theme (no token colors)
|
|
79
80
|
type StickyScrollOptions,
|
|
80
|
-
type StickyLine,
|
|
81
81
|
} from "@bhsd/codemirror-stickyscroll";
|
|
82
82
|
```
|
|
83
83
|
|
package/dist/compute.js
CHANGED
|
@@ -141,20 +141,21 @@ function getStickyContextForRange(state, fromPos, config, t, maxSticky) {
|
|
|
141
141
|
if (!exclude(undefined, langName, ownerName)) {
|
|
142
142
|
for (const service of services) {
|
|
143
143
|
const foldRange = service(state, open.from, open.to);
|
|
144
|
-
if (foldRange) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
144
|
+
if (!foldRange) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
const nodeTo = Math.min(foldRange.to, doc.length);
|
|
148
|
+
const close = doc.lineAt(nodeTo);
|
|
149
|
+
const closeLine = close.number;
|
|
150
|
+
if (closeLine - openLine + 1 >= minBlockLines && closeLine >= topLineNumber) {
|
|
151
|
+
found.push({
|
|
152
|
+
lineNumber: openLine,
|
|
153
|
+
from: open.from,
|
|
154
|
+
to: open.to,
|
|
155
|
+
text: open.text,
|
|
156
|
+
nodeFrom: foldRange.from,
|
|
157
|
+
nodeTo,
|
|
158
|
+
});
|
|
158
159
|
}
|
|
159
160
|
}
|
|
160
161
|
}
|
package/dist/facet.d.ts
CHANGED
|
@@ -35,8 +35,6 @@ export interface StickyScrollConfig extends Required<Pick<StickyScrollOptions, "
|
|
|
35
35
|
* for a language you need exact behavior on.
|
|
36
36
|
*/
|
|
37
37
|
export declare const defaultExcludeNode: (nodeName?: string, langName?: string, ownerName?: string) => boolean;
|
|
38
|
-
/** Merge partial options with built-in defaults. */
|
|
39
|
-
export declare function makeStickyScrollConfig(options?: StickyScrollOptions): StickyScrollConfig;
|
|
40
38
|
/**
|
|
41
39
|
* The facet carrying the sticky-scroll configuration.
|
|
42
40
|
*
|
package/dist/facet.js
CHANGED
|
@@ -59,7 +59,7 @@ export const defaultExcludeNode = (nodeName, langName, ownerName) => {
|
|
|
59
59
|
const DEFAULT_MAX_STICKY_LINES = 4;
|
|
60
60
|
const DEFAULT_MIN_BLOCK_LINES = 6;
|
|
61
61
|
/** Merge partial options with built-in defaults. */
|
|
62
|
-
|
|
62
|
+
function makeStickyScrollConfig(options) {
|
|
63
63
|
var _a, _b, _c;
|
|
64
64
|
return {
|
|
65
65
|
maxStickyLines: (_a = options === null || options === void 0 ? void 0 : options.maxStickyLines) !== null && _a !== void 0 ? _a : DEFAULT_MAX_STICKY_LINES,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { Extension } from "@codemirror/state";
|
|
2
2
|
import { type StickyScrollOptions } from "./facet";
|
|
3
|
-
export type {
|
|
4
|
-
export
|
|
5
|
-
export { stickyScrollFacet, defaultExcludeNode, makeStickyScrollConfig } from "./facet";
|
|
6
|
-
export { stickyScrollBaseTheme } from "./theme";
|
|
3
|
+
export type { StickyScrollOptions } from "./facet";
|
|
4
|
+
export { defaultExcludeNode } from "./facet";
|
|
7
5
|
/**
|
|
8
6
|
* Add Monaco/VS Code-style sticky scroll to a CodeMirror 6 editor.
|
|
9
7
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { stickyScrollFacet } from "./facet";
|
|
2
2
|
import { scrollStickyPlugin } from "./plugin";
|
|
3
3
|
import { stickyScrollBaseTheme } from "./theme";
|
|
4
|
-
export {
|
|
5
|
-
export { stickyScrollBaseTheme } from "./theme";
|
|
4
|
+
export { defaultExcludeNode } from "./facet";
|
|
6
5
|
/**
|
|
7
6
|
* Add Monaco/VS Code-style sticky scroll to a CodeMirror 6 editor.
|
|
8
7
|
*
|
package/dist/render.js
CHANGED
|
@@ -16,9 +16,6 @@ class StateHighlighter {
|
|
|
16
16
|
style(tags) {
|
|
17
17
|
return highlightingFor(this.state, tags, this.topNodeType);
|
|
18
18
|
}
|
|
19
|
-
scope() {
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
19
|
}
|
|
23
20
|
// ---------------------------------------------------------------------------
|
|
24
21
|
// Internal: find the live `.cm-line` DOM element for a document line
|
|
@@ -35,13 +32,7 @@ function findRenderedLineElement(view, lineNumber) {
|
|
|
35
32
|
// (Block widgets, placeholder lines and render-margin lines make those two
|
|
36
33
|
// lists diverge, which previously caused wrong — blank / comment / `}` —
|
|
37
34
|
// line text to be cloned into the sticky bar.)
|
|
38
|
-
|
|
39
|
-
try {
|
|
40
|
-
dom = view.domAtPos(lineFrom, 1);
|
|
41
|
-
}
|
|
42
|
-
catch {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
35
|
+
const dom = view.domAtPos(lineFrom, 1);
|
|
45
36
|
let el = dom.node instanceof HTMLElement ? dom.node : dom.node.parentElement;
|
|
46
37
|
while (el && !el.classList.contains("cm-line"))
|
|
47
38
|
el = el.parentElement;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bhsd/codemirror-stickyscroll",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "VS Code / Monaco-style sticky scroll (sticky lines) extension for CodeMirror 6",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codemirror",
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
"@codemirror/view": "^6.0.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@bhsd/code-standard": "^4.
|
|
43
|
+
"@bhsd/code-standard": "^4.3.0",
|
|
44
44
|
"@codemirror/language": "^6.12.4",
|
|
45
|
-
"@codemirror/state": "^6.7.
|
|
46
|
-
"@codemirror/view": "^6.43.
|
|
47
|
-
"eslint": "^10.
|
|
48
|
-
"markdownlint-cli2": "^0.23.
|
|
49
|
-
"stylelint": "^17.
|
|
45
|
+
"@codemirror/state": "^6.7.6",
|
|
46
|
+
"@codemirror/view": "^6.43.13",
|
|
47
|
+
"eslint": "^10.11.0",
|
|
48
|
+
"markdownlint-cli2": "^0.23.3",
|
|
49
|
+
"stylelint": "^17.16.0",
|
|
50
50
|
"typescript": "^6.0.3"
|
|
51
51
|
}
|
|
52
52
|
}
|