@bhsd/codemirror-stickyscroll 0.2.0 → 0.3.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 +1 -0
- package/dist/compute.js +15 -22
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/plugin.d.ts +1 -0
- package/dist/plugin.js +5 -2
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -77,6 +77,7 @@ interface StickyScrollOptions {
|
|
|
77
77
|
import {
|
|
78
78
|
stickyScroll,
|
|
79
79
|
defaultExcludeNode, // default denylist implementation
|
|
80
|
+
stickyScrollEffect, // StateEffect to trigger a re-render (e.g. after theme change)
|
|
80
81
|
type StickyScrollOptions,
|
|
81
82
|
} from "@bhsd/codemirror-stickyscroll";
|
|
82
83
|
```
|
package/dist/compute.js
CHANGED
|
@@ -85,6 +85,19 @@ function getStickyContextForRange(state, fromPos, config, t, maxSticky) {
|
|
|
85
85
|
const exclude = config.excludeNode;
|
|
86
86
|
const langName = lang.name;
|
|
87
87
|
const found = [];
|
|
88
|
+
const pushStickyLine = (open, closeLine, nodeFrom, nodeTo) => {
|
|
89
|
+
const openLine = open.number;
|
|
90
|
+
if (closeLine - openLine + 1 >= minBlockLines && closeLine >= topLineNumber) {
|
|
91
|
+
found.push({
|
|
92
|
+
lineNumber: openLine,
|
|
93
|
+
from: open.from,
|
|
94
|
+
to: open.to,
|
|
95
|
+
text: open.text,
|
|
96
|
+
nodeFrom,
|
|
97
|
+
nodeTo,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
};
|
|
88
101
|
const services = state.facet(foldService);
|
|
89
102
|
if (services.length === 0) {
|
|
90
103
|
let node = t.resolveInner(fromPos, 0);
|
|
@@ -115,16 +128,7 @@ function getStickyContextForRange(state, fromPos, config, t, maxSticky) {
|
|
|
115
128
|
// what delays the slide-away until the real closing brace.
|
|
116
129
|
const close = doc.lineAt(Math.min(owner.to, doc.length));
|
|
117
130
|
const closeLine = close.number;
|
|
118
|
-
|
|
119
|
-
found.push({
|
|
120
|
-
lineNumber: openLine,
|
|
121
|
-
from: open.from,
|
|
122
|
-
to: open.to,
|
|
123
|
-
text: open.text,
|
|
124
|
-
nodeFrom: owner.from,
|
|
125
|
-
nodeTo: owner.to,
|
|
126
|
-
});
|
|
127
|
-
}
|
|
131
|
+
pushStickyLine(open, closeLine, owner.from, owner.to);
|
|
128
132
|
}
|
|
129
133
|
}
|
|
130
134
|
}
|
|
@@ -145,18 +149,7 @@ function getStickyContextForRange(state, fromPos, config, t, maxSticky) {
|
|
|
145
149
|
continue;
|
|
146
150
|
}
|
|
147
151
|
const nodeTo = Math.min(foldRange.to, doc.length);
|
|
148
|
-
|
|
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
|
-
});
|
|
159
|
-
}
|
|
152
|
+
pushStickyLine(open, doc.lineAt(nodeTo).number, foldRange.from, nodeTo);
|
|
160
153
|
}
|
|
161
154
|
}
|
|
162
155
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Extension } from "@codemirror/state";
|
|
|
2
2
|
import { type StickyScrollOptions } from "./facet";
|
|
3
3
|
export type { StickyScrollOptions } from "./facet";
|
|
4
4
|
export { defaultExcludeNode } from "./facet";
|
|
5
|
+
export { stickyScrollEffect } from "./plugin";
|
|
5
6
|
/**
|
|
6
7
|
* Add Monaco/VS Code-style sticky scroll to a CodeMirror 6 editor.
|
|
7
8
|
*
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { stickyScrollFacet } from "./facet";
|
|
|
2
2
|
import { scrollStickyPlugin } from "./plugin";
|
|
3
3
|
import { stickyScrollBaseTheme } from "./theme";
|
|
4
4
|
export { defaultExcludeNode } from "./facet";
|
|
5
|
+
export { stickyScrollEffect } from "./plugin";
|
|
5
6
|
/**
|
|
6
7
|
* Add Monaco/VS Code-style sticky scroll to a CodeMirror 6 editor.
|
|
7
8
|
*
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EditorView, ViewPlugin, type ViewUpdate } from "@codemirror/view";
|
|
2
2
|
import type { StickyLine } from "./types";
|
|
3
|
+
export declare const stickyScrollEffect: import("@codemirror/state").StateEffectType<true>;
|
|
3
4
|
declare class StickyScrollPlugin {
|
|
4
5
|
private readonly dom;
|
|
5
6
|
private readonly inner;
|
package/dist/plugin.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { language, syntaxTree } from "@codemirror/language";
|
|
2
2
|
import { Direction, EditorView, ViewPlugin } from "@codemirror/view";
|
|
3
|
+
import { StateEffect } from "@codemirror/state";
|
|
3
4
|
import { getStickyContext } from "./compute";
|
|
4
5
|
import { stickyScrollFacet } from "./facet";
|
|
5
6
|
import { renderLineCode } from "./render";
|
|
7
|
+
export const stickyScrollEffect = StateEffect.define();
|
|
6
8
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
7
9
|
// Utilities
|
|
8
10
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -102,7 +104,8 @@ class StickyScrollPlugin {
|
|
|
102
104
|
this.config = update.state.facet(stickyScrollFacet);
|
|
103
105
|
const contentChanged = configChanged ||
|
|
104
106
|
update.docChanged ||
|
|
105
|
-
syntaxTree(update.startState) !== syntaxTree(update.state)
|
|
107
|
+
syntaxTree(update.startState) !== syntaxTree(update.state) ||
|
|
108
|
+
update.transactions.some(({ effects }) => effects.some((e) => e.is(stickyScrollEffect)));
|
|
106
109
|
if (contentChanged) {
|
|
107
110
|
this.clearCache();
|
|
108
111
|
}
|
|
@@ -330,4 +333,4 @@ class StickyScrollPlugin {
|
|
|
330
333
|
return semiTransparent;
|
|
331
334
|
}
|
|
332
335
|
}
|
|
333
|
-
export const scrollStickyPlugin = ViewPlugin.fromClass(StickyScrollPlugin, {});
|
|
336
|
+
export const scrollStickyPlugin = /* #__PURE__ */ ViewPlugin.fromClass(StickyScrollPlugin, {});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bhsd/codemirror-stickyscroll",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "VS Code / Monaco-style sticky scroll (sticky lines) extension for CodeMirror 6",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codemirror",
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
"lint:md": "markdownlint-cli2 '**/*.md'",
|
|
33
33
|
"lint:css": "stylelint --cache '**/*.css'",
|
|
34
34
|
"lint": "npm run lint:ts && npm run lint:css && npm run lint:md",
|
|
35
|
-
"build": "tsc && eslint --no-inline-config --no-config-lookup -c eslint.dist.js dist/*.js"
|
|
35
|
+
"build": "tsc && eslint --no-inline-config --no-config-lookup -c eslint.dist.js dist/*.js",
|
|
36
|
+
"test": "echo 'This package has no tests.'"
|
|
36
37
|
},
|
|
37
38
|
"peerDependencies": {
|
|
38
39
|
"@codemirror/language": "^6.3.0",
|
|
@@ -44,7 +45,7 @@
|
|
|
44
45
|
"@codemirror/language": "^6.12.4",
|
|
45
46
|
"@codemirror/state": "^6.7.6",
|
|
46
47
|
"@codemirror/view": "^6.43.13",
|
|
47
|
-
"eslint": "^10.
|
|
48
|
+
"eslint": "^10.12.0",
|
|
48
49
|
"markdownlint-cli2": "^0.23.3",
|
|
49
50
|
"stylelint": "^17.16.0",
|
|
50
51
|
"typescript": "^6.0.3"
|