@nibling/editor 0.0.0-stage → 0.0.1
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/LICENSE +21 -0
- package/README.md +53 -2
- package/dist/commands/autoclose.d.ts +13 -0
- package/dist/commands/autoclose.js +78 -0
- package/dist/commands/commands.d.ts +104 -0
- package/dist/commands/commands.js +442 -0
- package/dist/commands/comments.d.ts +3 -0
- package/dist/commands/comments.js +9 -0
- package/dist/commands/fold.d.ts +18 -0
- package/dist/commands/fold.js +75 -0
- package/dist/commands/keymap.d.ts +40 -0
- package/dist/commands/keymap.js +118 -0
- package/dist/complete/autocomplete.d.ts +35 -0
- package/dist/complete/autocomplete.js +386 -0
- package/dist/complete/source.d.ts +72 -0
- package/dist/complete/source.js +52 -0
- package/dist/complete/words.d.ts +53 -0
- package/dist/complete/words.js +203 -0
- package/dist/element.d.ts +119 -0
- package/dist/element.js +1011 -0
- package/dist/expand/expansions.d.ts +68 -0
- package/dist/expand/expansions.js +143 -0
- package/dist/expand/projection.d.ts +73 -0
- package/dist/expand/projection.js +189 -0
- package/dist/expand/resolver.d.ts +42 -0
- package/dist/expand/resolver.js +585 -0
- package/dist/expand/slice-tokens.d.ts +25 -0
- package/dist/expand/slice-tokens.js +79 -0
- package/dist/extension.d.ts +58 -0
- package/dist/extension.js +1 -0
- package/dist/find/find.d.ts +12 -0
- package/dist/find/find.js +469 -0
- package/dist/find/search.d.ts +81 -0
- package/dist/find/search.js +308 -0
- package/dist/headless.d.ts +16 -0
- package/dist/headless.js +19 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/inline-expansion.d.ts +89 -0
- package/dist/inline-expansion.js +324 -0
- package/dist/input/edit-context.d.ts +23 -0
- package/dist/input/edit-context.js +102 -0
- package/dist/input/surface.d.ts +101 -0
- package/dist/input/surface.js +84 -0
- package/dist/input/textarea.d.ts +26 -0
- package/dist/input/textarea.js +125 -0
- package/dist/sheet.d.ts +6 -0
- package/dist/sheet.js +12 -0
- package/dist/state/core.d.ts +73 -0
- package/dist/state/core.js +86 -0
- package/dist/state/fold-ranges.d.ts +41 -0
- package/dist/state/fold-ranges.js +167 -0
- package/dist/state/folds.d.ts +45 -0
- package/dist/state/folds.js +240 -0
- package/dist/state/history.d.ts +25 -0
- package/dist/state/history.js +127 -0
- package/dist/state/indent.d.ts +33 -0
- package/dist/state/indent.js +121 -0
- package/dist/state/selection.d.ts +45 -0
- package/dist/state/selection.js +106 -0
- package/dist/state/whitespace.d.ts +16 -0
- package/dist/state/whitespace.js +54 -0
- package/dist/text/changeset.d.ts +56 -0
- package/dist/text/changeset.js +321 -0
- package/dist/text/text.d.ts +30 -0
- package/dist/text/text.js +321 -0
- package/dist/tokens/bridge.d.ts +107 -0
- package/dist/tokens/bridge.js +461 -0
- package/dist/tokens/engine.d.ts +39 -0
- package/dist/tokens/engine.js +360 -0
- package/dist/tokens/protocol.d.ts +113 -0
- package/dist/tokens/protocol.js +38 -0
- package/dist/tokens/textmate/ascii-regex.d.ts +5 -0
- package/dist/tokens/textmate/ascii-regex.js +156 -0
- package/dist/tokens/textmate/index.d.ts +7 -0
- package/dist/tokens/textmate/index.js +19 -0
- package/dist/tokens/textmate/linker.d.ts +67 -0
- package/dist/tokens/textmate/linker.js +238 -0
- package/dist/tokens/textmate/scopes.d.ts +14 -0
- package/dist/tokens/textmate/scopes.js +54 -0
- package/dist/tokens/textmate/theme.d.ts +54 -0
- package/dist/tokens/textmate/theme.js +138 -0
- package/dist/tokens/textmate/tokenizer.d.ts +29 -0
- package/dist/tokens/textmate/tokenizer.js +684 -0
- package/dist/tokens/textmate.d.ts +49 -0
- package/dist/tokens/textmate.js +4 -0
- package/dist/view/decorations.d.ts +183 -0
- package/dist/view/decorations.js +51 -0
- package/dist/view/guides.d.ts +58 -0
- package/dist/view/guides.js +174 -0
- package/dist/view/heightmap.d.ts +97 -0
- package/dist/view/heightmap.js +229 -0
- package/dist/view/line-dom.d.ts +54 -0
- package/dist/view/line-dom.js +168 -0
- package/dist/view/measure.d.ts +37 -0
- package/dist/view/measure.js +136 -0
- package/dist/view/overlays.d.ts +32 -0
- package/dist/view/overlays.js +135 -0
- package/dist/view/rail.d.ts +27 -0
- package/dist/view/rail.js +232 -0
- package/dist/view/remote.d.ts +24 -0
- package/dist/view/remote.js +143 -0
- package/dist/view/scope-focus.d.ts +27 -0
- package/dist/view/scope-focus.js +255 -0
- package/dist/view/view.d.ts +114 -0
- package/dist/view/view.js +1231 -0
- package/dist/vite.d.ts +12 -0
- package/dist/vite.js +64 -0
- package/dist/worker.d.ts +1 -0
- package/dist/worker.js +64 -0
- package/grammars/astro.mjs +2 -0
- package/grammars/chunks/r-90cb351dba.mjs +1 -0
- package/grammars/chunks/r-b92a500aab.mjs +1 -0
- package/grammars/chunks/r-ced5311992.mjs +1 -0
- package/grammars/chunks/r-ebae91d4ec.mjs +1 -0
- package/grammars/chunks/s-1821e66170.mjs +1 -0
- package/grammars/css.mjs +1 -0
- package/grammars/diff.mjs +1 -0
- package/grammars/docker.mjs +1 -0
- package/grammars/dotenv.mjs +1 -0
- package/grammars/graphql.mjs +1 -0
- package/grammars/html.mjs +2 -0
- package/grammars/ini.mjs +1 -0
- package/grammars/javascript.mjs +5 -0
- package/grammars/json.mjs +1 -0
- package/grammars/json5.mjs +1 -0
- package/grammars/jsonc.mjs +1 -0
- package/grammars/less.mjs +1 -0
- package/grammars/manifest.json +58 -0
- package/grammars/markdown.mjs +1 -0
- package/grammars/mdx.mjs +1 -0
- package/grammars/pug.mjs +1 -0
- package/grammars/scss.mjs +1 -0
- package/grammars/shellscript.mjs +1 -0
- package/grammars/sql.mjs +1 -0
- package/grammars/stylus.mjs +1 -0
- package/grammars/svelte.mjs +1 -0
- package/grammars/toml.mjs +1 -0
- package/grammars/tsx.mjs +5 -0
- package/grammars/typescript.mjs +2 -0
- package/grammars/vue.mjs +1 -0
- package/grammars/yaml.mjs +1 -0
- package/package.json +71 -3
- package/themes/dark-plus.json +1 -0
- package/themes/light-plus.json +1 -0
- package/themes/monokai.json +1 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { lineIndent } from "../state/indent.js";
|
|
2
|
+
import { sheetFor } from "../sheet.js";
|
|
3
|
+
/**
|
|
4
|
+
* Two scope cues borrowed from Xcode's code-folding ribbon. The focus band: while the pointer is on
|
|
5
|
+
* a fold chevron, a quiet band tints the block that clicking it folds. The scope line: beside the
|
|
6
|
+
* line numbers, an accent line spans the block around each cursor. Both read the same block rule
|
|
7
|
+
* (`#blockAt`).
|
|
8
|
+
*/
|
|
9
|
+
/** Cursors whose block gets a scope line. Past this many, only the primary's does. */
|
|
10
|
+
const SCOPE_LINE_LIMIT = 64;
|
|
11
|
+
const scopeFocusCss = `
|
|
12
|
+
:host{
|
|
13
|
+
--nib-editor-scope-focus:var(--nib-color-hover,color-mix(in srgb,var(--nib-fg,#d4d4d4) 6%,transparent));
|
|
14
|
+
--nib-editor-scope-line:var(--nib-color-accent,color-mix(in srgb,var(--nib-fg,#d4d4d4) 45%,var(--nib-bg,#1e1e1e)));
|
|
15
|
+
}
|
|
16
|
+
.nib-scope-line{position:absolute;right:calc(var(--nib-rail-gap,14px) - 6px);width:2px;border-radius:1px;
|
|
17
|
+
top:0;height:0;pointer-events:none;background:var(--nib-editor-scope-line)}
|
|
18
|
+
@media (prefers-reduced-motion:no-preference){
|
|
19
|
+
.nib-scope-line{transition:top var(--nib-editor-motion-duration-fast) var(--nib-editor-motion-ease-out),
|
|
20
|
+
height var(--nib-editor-motion-duration-fast) var(--nib-editor-motion-ease-out)}
|
|
21
|
+
}
|
|
22
|
+
.nib-scope-focus{position:absolute;left:var(--nib-gutter);right:0;top:0;height:0;
|
|
23
|
+
pointer-events:none;background:var(--nib-editor-scope-focus);opacity:0}
|
|
24
|
+
@media (prefers-reduced-motion:no-preference){
|
|
25
|
+
.nib-scope-focus{transition:opacity var(--nib-editor-motion-duration-fast) var(--nib-editor-motion-ease-out),
|
|
26
|
+
top var(--nib-editor-motion-duration-fast) var(--nib-editor-motion-ease-out),
|
|
27
|
+
height var(--nib-editor-motion-duration-fast) var(--nib-editor-motion-ease-out)}
|
|
28
|
+
/* Appearing: in place at once, and only the fade animates. Moves between blocks glide. */
|
|
29
|
+
.nib-scope-focus.nib-scope-snap{transition-property:opacity}
|
|
30
|
+
}
|
|
31
|
+
.nib-scope-focus.nib-scope-visible{opacity:1}
|
|
32
|
+
`;
|
|
33
|
+
/**
|
|
34
|
+
* One absolutely positioned element in the content layer, never a line class: a line-class change
|
|
35
|
+
* would make the view rerender every changed line (`#renderIfChanged`'s identity check), so
|
|
36
|
+
* hovering down the rail would rerender lines on every pointer move. Positioned from the
|
|
37
|
+
* HeightMap, so folds inside the region (and elsewhere in the document) are respected, and a
|
|
38
|
+
* region partly or wholly outside the mounted range still lands in the right place.
|
|
39
|
+
*
|
|
40
|
+
* Mounted as the sizer's first child, so it paints behind the gutter, the lines (text, selection
|
|
41
|
+
* highlights, indent guides, which are line backgrounds) and the carets, all of which come after
|
|
42
|
+
* it in document order or sit at a higher z-index.
|
|
43
|
+
*/
|
|
44
|
+
export class ScopeFocus {
|
|
45
|
+
#source;
|
|
46
|
+
#host;
|
|
47
|
+
#core;
|
|
48
|
+
#band = null;
|
|
49
|
+
#gutter = null;
|
|
50
|
+
/** The pointer's last clientY over the gutter, or null while not hovering it. */
|
|
51
|
+
#pointerY = null;
|
|
52
|
+
#region = null;
|
|
53
|
+
#top = -1;
|
|
54
|
+
#height = -1;
|
|
55
|
+
#visible = false;
|
|
56
|
+
#rafId = 0;
|
|
57
|
+
#scheduled = false;
|
|
58
|
+
/** Scope lines, one per distinct cursor block, and what they were computed from. */
|
|
59
|
+
#lines = [];
|
|
60
|
+
#blocks = [];
|
|
61
|
+
#blocksFor = { text: null, selection: null };
|
|
62
|
+
constructor(core, source, host) {
|
|
63
|
+
this.#core = core;
|
|
64
|
+
this.#source = source;
|
|
65
|
+
this.#host = host;
|
|
66
|
+
}
|
|
67
|
+
/** Adopt the band's stylesheet, insert its element, and start tracking the pointer. */
|
|
68
|
+
mount(root, signal) {
|
|
69
|
+
const sheet = sheetFor(root);
|
|
70
|
+
sheet.replaceSync(scopeFocusCss);
|
|
71
|
+
root.adoptedStyleSheets = [...root.adoptedStyleSheets, sheet];
|
|
72
|
+
const sizer = root.querySelector('.nib-sizer');
|
|
73
|
+
const gutter = root.querySelector('.nib-gutter');
|
|
74
|
+
if (sizer && gutter) {
|
|
75
|
+
const band = sizer.ownerDocument.createElement('div');
|
|
76
|
+
band.className = 'nib-scope-focus';
|
|
77
|
+
band.setAttribute('aria-hidden', 'true');
|
|
78
|
+
sizer.insertBefore(band, sizer.firstChild);
|
|
79
|
+
this.#band = band;
|
|
80
|
+
this.#gutter = gutter;
|
|
81
|
+
gutter.addEventListener('pointermove', (e) => this.#onMove(e), { signal });
|
|
82
|
+
gutter.addEventListener('pointerleave', () => this.#onLeave(), { signal });
|
|
83
|
+
}
|
|
84
|
+
const offFrame = this.#host.onFrame(() => this.#onViewFrame());
|
|
85
|
+
signal.addEventListener('abort', () => {
|
|
86
|
+
offFrame();
|
|
87
|
+
cancelAnimationFrame(this.#rafId);
|
|
88
|
+
this.#band?.remove();
|
|
89
|
+
for (const l of this.#lines)
|
|
90
|
+
l.remove();
|
|
91
|
+
root.adoptedStyleSheets = root.adoptedStyleSheets.filter((s) => s !== sheet);
|
|
92
|
+
}, { once: true });
|
|
93
|
+
}
|
|
94
|
+
/** The band follows only a fold chevron, the thing a click folds; a plain number hides it. */
|
|
95
|
+
#onMove(e) {
|
|
96
|
+
const onChevron = e.target instanceof Element && e.target.closest('.nib-fold-toggle') !== null;
|
|
97
|
+
this.#pointerY = onChevron ? e.clientY : null;
|
|
98
|
+
this.#schedule();
|
|
99
|
+
}
|
|
100
|
+
#onLeave() {
|
|
101
|
+
this.#pointerY = null;
|
|
102
|
+
this.#schedule();
|
|
103
|
+
}
|
|
104
|
+
/** The view just painted a frame (a fold toggle, an edit, or a scroll): geometry under an
|
|
105
|
+
* unmoved pointer may now be stale. */
|
|
106
|
+
#onViewFrame() {
|
|
107
|
+
this.#placeLines();
|
|
108
|
+
if (this.#pointerY !== null)
|
|
109
|
+
this.#schedule();
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Runs inside the view's frame, after its writes: the HeightMap is current and reading it does
|
|
113
|
+
* no layout. Blocks are found again only when the selection or the text changed; positions are
|
|
114
|
+
* rewritten only when they moved.
|
|
115
|
+
*/
|
|
116
|
+
#placeLines() {
|
|
117
|
+
const gutter = this.#gutter;
|
|
118
|
+
if (!gutter)
|
|
119
|
+
return;
|
|
120
|
+
const { text, selection } = this.#core.state;
|
|
121
|
+
if (text !== this.#blocksFor.text || selection !== this.#blocksFor.selection) {
|
|
122
|
+
this.#blocksFor = { text, selection };
|
|
123
|
+
const ranges = selection.ranges.length > SCOPE_LINE_LIMIT ? [selection.primary] : selection.ranges;
|
|
124
|
+
const seen = new Set();
|
|
125
|
+
const blocks = [];
|
|
126
|
+
for (const r of ranges) {
|
|
127
|
+
const b = this.#blockAt(text.lineAt(r.head).number);
|
|
128
|
+
if (b && !seen.has(b.line)) {
|
|
129
|
+
seen.add(b.line);
|
|
130
|
+
blocks.push(b);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
this.#blocks = blocks.sort((a, b) => a.line - b.line);
|
|
134
|
+
}
|
|
135
|
+
const heights = this.#host.heights;
|
|
136
|
+
const blocks = this.#blocks;
|
|
137
|
+
while (this.#lines.length > blocks.length)
|
|
138
|
+
this.#lines.pop().remove();
|
|
139
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
140
|
+
let el = this.#lines[i];
|
|
141
|
+
if (!el) {
|
|
142
|
+
el = gutter.ownerDocument.createElement('div');
|
|
143
|
+
el.className = 'nib-scope-line';
|
|
144
|
+
el.setAttribute('aria-hidden', 'true');
|
|
145
|
+
gutter.appendChild(el);
|
|
146
|
+
this.#lines.push(el);
|
|
147
|
+
}
|
|
148
|
+
const b = blocks[i];
|
|
149
|
+
const top = `${heights.topOf(b.line)}px`;
|
|
150
|
+
const height = `${Math.max(0, heights.topOf(b.end) + heights.heightOf(b.end) - heights.topOf(b.line))}px`;
|
|
151
|
+
if (el.style.top !== top)
|
|
152
|
+
el.style.top = top;
|
|
153
|
+
if (el.style.height !== height)
|
|
154
|
+
el.style.height = height;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
#schedule() {
|
|
158
|
+
if (this.#scheduled)
|
|
159
|
+
return;
|
|
160
|
+
this.#scheduled = true;
|
|
161
|
+
this.#rafId = requestAnimationFrame(() => {
|
|
162
|
+
this.#scheduled = false;
|
|
163
|
+
this.#update();
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
/** Read (pointer position, gutter rect, HeightMap), then write. */
|
|
167
|
+
#update() {
|
|
168
|
+
const band = this.#band;
|
|
169
|
+
const gutter = this.#gutter;
|
|
170
|
+
if (!band || !gutter)
|
|
171
|
+
return;
|
|
172
|
+
const y = this.#pointerY;
|
|
173
|
+
const heights = this.#host.heights;
|
|
174
|
+
let region = null;
|
|
175
|
+
if (y !== null) {
|
|
176
|
+
const top = y - gutter.getBoundingClientRect().top;
|
|
177
|
+
if (top >= 0 && top < heights.totalHeight)
|
|
178
|
+
region = this.#ownBlock(heights.lineAt(top));
|
|
179
|
+
}
|
|
180
|
+
this.#region = region;
|
|
181
|
+
if (!region) {
|
|
182
|
+
if (this.#visible) {
|
|
183
|
+
this.#visible = false;
|
|
184
|
+
band.classList.remove('nib-scope-visible');
|
|
185
|
+
}
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const top = heights.topOf(region.line);
|
|
189
|
+
const height = Math.max(0, heights.topOf(region.end) + heights.heightOf(region.end) - top);
|
|
190
|
+
// A hidden band still sits where it last was. Snap it into place before it fades in, so it
|
|
191
|
+
// never slides over from there; lift the snap a frame later so later moves glide again.
|
|
192
|
+
const appearing = !this.#visible;
|
|
193
|
+
if (appearing) {
|
|
194
|
+
band.classList.add('nib-scope-snap');
|
|
195
|
+
requestAnimationFrame(() => requestAnimationFrame(() => band.classList.remove('nib-scope-snap')));
|
|
196
|
+
}
|
|
197
|
+
if (top !== this.#top) {
|
|
198
|
+
this.#top = top;
|
|
199
|
+
band.style.top = `${top}px`;
|
|
200
|
+
}
|
|
201
|
+
if (height !== this.#height) {
|
|
202
|
+
this.#height = height;
|
|
203
|
+
band.style.height = `${height}px`;
|
|
204
|
+
}
|
|
205
|
+
if (!this.#visible) {
|
|
206
|
+
this.#visible = true;
|
|
207
|
+
band.classList.add('nib-scope-visible');
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* The block under `line`: the innermost fold region holding it (its own header included, the
|
|
212
|
+
* rail's rule for a cursor), widened to take in the closing line that follows it. A fold stops
|
|
213
|
+
* before its `}` so the brace stays visible when folded, but a focus band should show the whole
|
|
214
|
+
* block. Hovering a closing line focuses the block it closes, as Xcode's ribbon does.
|
|
215
|
+
*/
|
|
216
|
+
#blockAt(line) {
|
|
217
|
+
const text = this.#core.state.text;
|
|
218
|
+
const source = this.#source;
|
|
219
|
+
if (isCloser(text, line)) {
|
|
220
|
+
const indent = lineIndent(text, line, 4);
|
|
221
|
+
let prev = line - 1;
|
|
222
|
+
while (prev >= 1 && lineIndent(text, prev, 4) < 0)
|
|
223
|
+
prev--;
|
|
224
|
+
// Walk out from the line before the closer to the region whose header it lines up with.
|
|
225
|
+
let r = prev >= 1 ? (source.startsFold(prev) ? source.rangeAt(prev) : source.enclosing(prev)) : null;
|
|
226
|
+
for (let k = 0; r && k < 32; k++) {
|
|
227
|
+
if (lineIndent(text, r.line, 4) === indent && r.end < line)
|
|
228
|
+
return { line: r.line, end: line };
|
|
229
|
+
r = source.enclosing(r.line);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return this.#widen(source.startsFold(line) ? source.rangeAt(line) : source.enclosing(line));
|
|
233
|
+
}
|
|
234
|
+
/** The block a chevron on `header` folds, widened to its closing line. */
|
|
235
|
+
#ownBlock(header) {
|
|
236
|
+
return this.#source.startsFold(header) ? this.#widen(this.#source.rangeAt(header)) : null;
|
|
237
|
+
}
|
|
238
|
+
/** A fold region plus the closing line that follows it at its header's indent, if any. */
|
|
239
|
+
#widen(r) {
|
|
240
|
+
if (!r)
|
|
241
|
+
return null;
|
|
242
|
+
const text = this.#core.state.text;
|
|
243
|
+
let next = r.end + 1;
|
|
244
|
+
while (next <= text.lines && next - r.end <= 2 && lineIndent(text, next, 4) < 0)
|
|
245
|
+
next++;
|
|
246
|
+
return next <= text.lines && isCloser(text, next) && lineIndent(text, next, 4) === lineIndent(text, r.line, 4) ? { line: r.line, end: next } : r;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/** A line that starts with a closing bracket after its indentation: `}`, `]`, or `)`. */
|
|
250
|
+
function isCloser(text, n) {
|
|
251
|
+
const l = text.line(n);
|
|
252
|
+
const s = text.slice(l.from, Math.min(l.to, l.from + 256)).trimStart();
|
|
253
|
+
const c = s.charCodeAt(0);
|
|
254
|
+
return c === 125 || c === 93 || c === 41;
|
|
255
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { EditorCore } from '../state/core.ts';
|
|
2
|
+
import { type Layout } from '../commands/commands.ts';
|
|
3
|
+
import type { LineTokenSource } from '../tokens/bridge.ts';
|
|
4
|
+
import type { LineClassSource, OverlaySource, RemoteCursorSource, ViewBlocks, ViewFolding } from './decorations.ts';
|
|
5
|
+
import { type HeightMap } from './heightmap.ts';
|
|
6
|
+
import { IndentGuides } from './guides.ts';
|
|
7
|
+
import { type WhitespaceMode } from '../state/whitespace.ts';
|
|
8
|
+
export interface ViewOptions {
|
|
9
|
+
readonly overscan?: number;
|
|
10
|
+
readonly instance: string;
|
|
11
|
+
readonly folding?: ViewFolding;
|
|
12
|
+
/** Draw indent guides. Default true. */
|
|
13
|
+
readonly indentGuides?: boolean;
|
|
14
|
+
/** Which whitespace to mark. Default 'selection'. */
|
|
15
|
+
readonly whitespace?: WhitespaceMode;
|
|
16
|
+
/** Block widgets between lines (inline expansions). */
|
|
17
|
+
readonly blocks?: ViewBlocks;
|
|
18
|
+
/** Gutter numbers: line n shows n + offset(), with at least digits() digits. An inline
|
|
19
|
+
* expansion shows its source's line numbers this way. Call `invalidateGutter` when they change. */
|
|
20
|
+
readonly lineNumbers?: {
|
|
21
|
+
readonly offset: () => number;
|
|
22
|
+
readonly digits?: () => number;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The virtualized DOM view (D1), one per element. A follower of EditorCore and of the TokenBridge.
|
|
27
|
+
*
|
|
28
|
+
* DOM it owns, inside the element's shadow root:
|
|
29
|
+
* scroller (overflow: auto)
|
|
30
|
+
* sizer (height = heightMap.totalHeight)
|
|
31
|
+
* gutter: one absolutely positioned number per mounted line
|
|
32
|
+
* content: one absolutely positioned div per mounted line (LineBox), top = heightMap.topOf
|
|
33
|
+
* carets: one absolutely positioned element per cursor, plus past-EOL selection boxes
|
|
34
|
+
*
|
|
35
|
+
* Per scroll frame: viewport = heightMap.lineAt(scrollTop - overscan..scrollTop + height + overscan);
|
|
36
|
+
* reuse LineBoxes still mounted, recycle the rest into the newly mounted lines (renderLine);
|
|
37
|
+
* bridge.setViewport; re-query overlay sources for the mounted range; position carets.
|
|
38
|
+
* No reads of layout except scrollTop/clientHeight (read first, then write only).
|
|
39
|
+
* Per keystroke: core Update (sync) -> heightMap.update, mark changed lines + overlays + carets
|
|
40
|
+
* + reveal; bridge has already re-keyed its window, so touched lines rerender with provisional
|
|
41
|
+
* runs in the same frame. Line-count changes shift `top` of boxes below; no rerender for them.
|
|
42
|
+
* Per token batch: mark the batch's lines; the frame rerenders only lines whose (text, tokens)
|
|
43
|
+
* identity changed, then invalidates their overlay ranges.
|
|
44
|
+
*
|
|
45
|
+
* Coordinates: offsets -> (x, y) via heightMap.topOf(line) + measurer.xAt(box, col). Positions
|
|
46
|
+
* on unmounted lines return null; nothing asks for them in the first slice.
|
|
47
|
+
*/
|
|
48
|
+
export declare class EditorView {
|
|
49
|
+
#private;
|
|
50
|
+
constructor(root: ShadowRoot, core: EditorCore, bridge: LineTokenSource, options: ViewOptions, signal: AbortSignal);
|
|
51
|
+
/** For vertical motion commands. */
|
|
52
|
+
get layout(): Layout;
|
|
53
|
+
/** Segments the overlay budget dropped in the last frame. */
|
|
54
|
+
get droppedOverlays(): number;
|
|
55
|
+
/** Current vertical geometry, for a follower that positions its own element in the content
|
|
56
|
+
* layer (ScopeFocus) instead of asking the view to draw it. */
|
|
57
|
+
get heights(): HeightMap;
|
|
58
|
+
/** Turn indent guides on or off. */
|
|
59
|
+
setIndentGuides(on: boolean): void;
|
|
60
|
+
/** Change which whitespace is marked. Every mounted line is checked again. */
|
|
61
|
+
setWhitespace(mode: WhitespaceMode): void;
|
|
62
|
+
/** The indent unit guides are drawn with. For tests and tools. */
|
|
63
|
+
get guides(): Pick<IndentGuides, 'unit' | 'enabled'>;
|
|
64
|
+
/** Carets show only while focused, and blink then. */
|
|
65
|
+
setFocused(focused: boolean): void;
|
|
66
|
+
/**
|
|
67
|
+
* Document offset for a pointer. A press (`drag` false) returns null on the scrollbars or
|
|
68
|
+
* outside the scroller; inside, it clamps to the content, so the gutter and the space below the
|
|
69
|
+
* last line still hit text. A drag clamps from anywhere to the visible content.
|
|
70
|
+
*/
|
|
71
|
+
pointerPos(clientX: number, clientY: number, drag: boolean): number | null;
|
|
72
|
+
/** Document offset under a client point, or null outside the content. Used for clicks and
|
|
73
|
+
* Alt-click. Hit-tests lines via heightMap.lineAt, columns via measurer.offsetAt. */
|
|
74
|
+
posAtCoords(clientX: number, clientY: number): number | null;
|
|
75
|
+
/** Client rect of a zero-width caret at pos, or null when its line is not mounted. */
|
|
76
|
+
coordsAtPos(pos: number): DOMRect | null;
|
|
77
|
+
addOverlaySource(source: OverlaySource, signal?: AbortSignal): void;
|
|
78
|
+
/** Scrolls `pos` into view on the next frame without moving the selection, as following someone does. */
|
|
79
|
+
revealPos(pos: number): void;
|
|
80
|
+
/** Collaborators' carets, labels, and selections. */
|
|
81
|
+
addRemoteCursorSource(source: RemoteCursorSource, signal?: AbortSignal): void;
|
|
82
|
+
addLineClassSource(source: LineClassSource, signal?: AbortSignal): void;
|
|
83
|
+
/** Height of the whole document's content, block widgets included. */
|
|
84
|
+
get contentHeight(): number;
|
|
85
|
+
/**
|
|
86
|
+
* Space the scroller's horizontal scrollbar takes, 0 with overlay scrollbars. It reads layout,
|
|
87
|
+
* so it is read again only after the content width or the scroller's size changed; reading it
|
|
88
|
+
* on every frame forced a layout per keystroke in an inline expansion.
|
|
89
|
+
*/
|
|
90
|
+
get scrollbarHeight(): number;
|
|
91
|
+
/** Line height in px, as last calibrated. */
|
|
92
|
+
get lineHeight(): number;
|
|
93
|
+
/** `lineNumbers` changed: write every gutter number again on the next frame. */
|
|
94
|
+
invalidateGutter(): void;
|
|
95
|
+
/** Called after each frame with fresh geometry; the element forwards it to the InputSurface. */
|
|
96
|
+
onFrame(listener: () => void): () => void;
|
|
97
|
+
/**
|
|
98
|
+
* Hide text until every visible line has tokens, for at most `ms`, so a document that opens with
|
|
99
|
+
* a grammar first paints colored instead of flashing plain or coloring in batch by batch (the
|
|
100
|
+
* worker flushes every slice). Layout, gutter, carets and selection stay visible. If the
|
|
101
|
+
* tokenizer is slow or fails, plain text shows when the time runs out.
|
|
102
|
+
*
|
|
103
|
+
* A far jump (`#frame`) calls this too, for `JUMP_HOLD_MS`, with `blank: true`: its freshly
|
|
104
|
+
* mounted lines that have no cached tokens are cleared instead of rendered plain (`#blankLine`),
|
|
105
|
+
* so a jump costs one render per line instead of a plain one immediately followed by a colored
|
|
106
|
+
* one. It marks the content `nib-jump-hold`, which hides nothing: lines that already have
|
|
107
|
+
* tokens stay painted. The document-open hold (`blank: false`, the default) keeps rendering plain text under the
|
|
108
|
+
* CSS hide, because `element.ts`'s hold spans a one-time cold load rather than a per-jump cost.
|
|
109
|
+
*/
|
|
110
|
+
awaitTokens(ms: number, blank?: boolean): void;
|
|
111
|
+
/** True while a frame runs inside a ResizeObserver callback. A frame listener that resizes an
|
|
112
|
+
* observed element then should wait for the next frame, or the browser reports a loop. */
|
|
113
|
+
get inResizeObserver(): boolean;
|
|
114
|
+
}
|