@nibling/editor 0.0.0-stage → 0.0.2
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 +66 -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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nate Moore
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,54 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nibling/editor
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A code editor as a web component, `<nib-editor>`. TextMate grammars and VS Code themes are tokenized in a worker, and grammars load on demand.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @nibling/editor
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Use it with Vite
|
|
10
|
+
|
|
11
|
+
The worker loads grammar modules by URL at runtime, so they are served as files, not bundled. The Vite plugin serves them in dev and emits them in a build:
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
// vite.config.js
|
|
15
|
+
import { nibEditor } from '@nibling/editor/vite';
|
|
16
|
+
|
|
17
|
+
export default { plugins: [nibEditor()] };
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Then point the editor at them:
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
import { editorDefaults } from '@nibling/editor';
|
|
24
|
+
|
|
25
|
+
const base = new URL(`${import.meta.env.BASE_URL}nib-editor/`, location.href);
|
|
26
|
+
const load = (path) => fetch(new URL(path, base)).then((r) => r.json());
|
|
27
|
+
const manifestUrl = new URL('grammars/manifest.json', base);
|
|
28
|
+
const [manifest, light, dark] = await Promise.all([load('grammars/manifest.json'), load('themes/light-plus.json'), load('themes/dark-plus.json')]);
|
|
29
|
+
|
|
30
|
+
editorDefaults.grammars = { ...manifest, base: manifestUrl.href };
|
|
31
|
+
editorDefaults.themes = { light, dark };
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```html
|
|
35
|
+
<nib-editor language="typescript"></nib-editor>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Importing `@nibling/editor` defines `<nib-editor>`. Import `@nibling/editor/element` to define it yourself, or `@nibling/editor/headless` for the DOM-free core.
|
|
39
|
+
|
|
40
|
+
## Entry points
|
|
41
|
+
|
|
42
|
+
| Path | What it is |
|
|
43
|
+
|---|---|
|
|
44
|
+
| `@nibling/editor` | Defines `<nib-editor>`, and exports the element, extensions, and the headless core |
|
|
45
|
+
| `@nibling/editor/element` | The element, without defining it |
|
|
46
|
+
| `@nibling/editor/headless` | The editor core, with no DOM |
|
|
47
|
+
| `@nibling/editor/worker` | The tokenizer worker |
|
|
48
|
+
| `@nibling/editor/vite` | The Vite plugin that serves and emits grammars and themes |
|
|
49
|
+
| `@nibling/editor/grammars/*` | Compiled grammars and their `manifest.json` |
|
|
50
|
+
| `@nibling/editor/themes/*` | Compiled themes: `light-plus`, `dark-plus`, `monokai` |
|
|
51
|
+
|
|
52
|
+
## License
|
|
53
|
+
|
|
54
|
+
MIT
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Command } from './commands.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Typing `(`, `[`, `{`, `"`, `'`, or `` ` ``: the input path's hook (element.ts `#onInput`, which
|
|
4
|
+
* does not go through the keymap). `null` when `ch` isn't one of those characters, so the caller
|
|
5
|
+
* falls back to plain `insertText`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const closeBrackets: (ch: string) => Command;
|
|
8
|
+
/**
|
|
9
|
+
* Backspace between an empty pair deletes both characters, per range. Bound ahead of the default
|
|
10
|
+
* Backspace (docs/design/core.md: "auto-close ... binds keymap commands at a higher priority").
|
|
11
|
+
* `null` when no range sits in an empty pair, so the default `deleteBackward` runs unchanged.
|
|
12
|
+
*/
|
|
13
|
+
export declare const deletePairBackward: Command;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { cursor, isCursor, rangeFrom, rangeTo } from "../state/selection.js";
|
|
2
|
+
import { isWordChar, perRange, prevGrapheme } from "./commands.js";
|
|
3
|
+
/** Opener -> its closer, for the three bracket pairs. Quotes close with themselves, so they are
|
|
4
|
+
* handled separately (`QUOTES`), never paired through this map. */
|
|
5
|
+
const OPEN_TO_CLOSE = { '(': ')', '[': ']', '{': '}' };
|
|
6
|
+
/** Closer -> its opener, for `deletePairBackward`'s only use of a reverse lookup. */
|
|
7
|
+
const CLOSE_TO_OPEN = { ')': '(', ']': '[', '}': '{' };
|
|
8
|
+
const QUOTES = new Set(['"', "'", '`']);
|
|
9
|
+
const isPairable = (ch) => Object.hasOwn(OPEN_TO_CLOSE, ch) || Object.hasOwn(CLOSE_TO_OPEN, ch) || QUOTES.has(ch);
|
|
10
|
+
/** The character immediately before/after `pos`, or `''` at a document edge. */
|
|
11
|
+
const charBefore = (text, pos) => (pos > 0 ? text.slice(pos - 1, pos) : '');
|
|
12
|
+
const charAfter = (text, pos) => (pos < text.length ? text.slice(pos, pos + 1) : '');
|
|
13
|
+
/**
|
|
14
|
+
* One range's reaction to typing `ch`, a bracket or quote character (docs/TODO.md,
|
|
15
|
+
* "Auto-closing brackets and quotes"):
|
|
16
|
+
* - A non-empty range: an opener or quote wraps it; a closer replaces it, same as plain typing.
|
|
17
|
+
* - A cursor right before the same closer (typed or auto-inserted) steps over it, inserting
|
|
18
|
+
* nothing.
|
|
19
|
+
* - A cursor before a word character doesn't pair ("inside a word"); a quote right after a word
|
|
20
|
+
* character doesn't pair either (an apostrophe in "it's" must stay a single character).
|
|
21
|
+
* - Otherwise an opener or quote inserts the pair with the cursor between; a closer with nothing
|
|
22
|
+
* to step over just types itself.
|
|
23
|
+
*/
|
|
24
|
+
function pairStep(r, text, ch) {
|
|
25
|
+
const close = OPEN_TO_CLOSE[ch];
|
|
26
|
+
const isOpener = close !== undefined;
|
|
27
|
+
const isCloser = Object.hasOwn(CLOSE_TO_OPEN, ch);
|
|
28
|
+
const isQuote = QUOTES.has(ch);
|
|
29
|
+
if (!isCursor(r)) {
|
|
30
|
+
const from = rangeFrom(r);
|
|
31
|
+
const to = rangeTo(r);
|
|
32
|
+
if (!isOpener && !isQuote)
|
|
33
|
+
return { change: { from, to, insert: ch }, range: cursor(from + ch.length) };
|
|
34
|
+
const insert = ch + text.slice(from, to) + (isQuote ? ch : close);
|
|
35
|
+
const forward = r.head >= r.anchor;
|
|
36
|
+
const inner = { anchor: from + 1, head: to + 1 };
|
|
37
|
+
return { change: { from, to, insert }, range: forward ? inner : { anchor: inner.head, head: inner.anchor } };
|
|
38
|
+
}
|
|
39
|
+
const pos = r.head;
|
|
40
|
+
if ((isCloser || isQuote) && charAfter(text, pos) === ch)
|
|
41
|
+
return { range: cursor(pos + 1) }; // step over
|
|
42
|
+
const plain = { change: { from: pos, to: pos, insert: ch }, range: cursor(pos + 1) };
|
|
43
|
+
if (isQuote)
|
|
44
|
+
return isWordChar(charBefore(text, pos)) || isWordChar(charAfter(text, pos)) ? plain : { change: { from: pos, to: pos, insert: ch + ch }, range: cursor(pos + 1) };
|
|
45
|
+
if (isOpener)
|
|
46
|
+
return isWordChar(charAfter(text, pos)) ? plain : { change: { from: pos, to: pos, insert: ch + close }, range: cursor(pos + 1) };
|
|
47
|
+
return plain; // a closer with nothing to step over
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Typing `(`, `[`, `{`, `"`, `'`, or `` ` ``: the input path's hook (element.ts `#onInput`, which
|
|
51
|
+
* does not go through the keymap). `null` when `ch` isn't one of those characters, so the caller
|
|
52
|
+
* falls back to plain `insertText`.
|
|
53
|
+
*/
|
|
54
|
+
export const closeBrackets = (ch) => (ctx) => ch.length === 1 && isPairable(ch) ? perRange(ctx.state, 'input.type', (r, text) => pairStep(r, text, ch)) : null;
|
|
55
|
+
/** Whether `prev` and `next` are a bracket or quote pair with nothing between them. */
|
|
56
|
+
function isEmptyPair(prev, next) {
|
|
57
|
+
return QUOTES.has(prev) ? prev === next : OPEN_TO_CLOSE[prev] === next;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Backspace between an empty pair deletes both characters, per range. Bound ahead of the default
|
|
61
|
+
* Backspace (docs/design/core.md: "auto-close ... binds keymap commands at a higher priority").
|
|
62
|
+
* `null` when no range sits in an empty pair, so the default `deleteBackward` runs unchanged.
|
|
63
|
+
*/
|
|
64
|
+
export const deletePairBackward = (ctx) => {
|
|
65
|
+
const { text, selection } = ctx.state;
|
|
66
|
+
const any = selection.ranges.some((r) => isCursor(r) && r.head > 0 && isEmptyPair(charBefore(text, r.head), charAfter(text, r.head)));
|
|
67
|
+
if (!any)
|
|
68
|
+
return null;
|
|
69
|
+
return perRange(ctx.state, 'input.delete', (r, text) => {
|
|
70
|
+
if (!isCursor(r))
|
|
71
|
+
return { change: { from: rangeFrom(r), to: rangeTo(r) }, range: cursor(rangeFrom(r)) };
|
|
72
|
+
const pos = r.head;
|
|
73
|
+
if (pos > 0 && isEmptyPair(charBefore(text, pos), charAfter(text, pos)))
|
|
74
|
+
return { change: { from: pos - 1, to: pos + 1 }, range: cursor(pos - 1) };
|
|
75
|
+
const from = prevGrapheme(text, pos);
|
|
76
|
+
return { change: { from, to: pos }, range: cursor(from) };
|
|
77
|
+
});
|
|
78
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { type ChangeSpec } from '../text/changeset.ts';
|
|
2
|
+
import type { Text } from '../text/text.ts';
|
|
3
|
+
import type { Origin, Snapshot, TransactionSpec } from '../state/core.ts';
|
|
4
|
+
import { type SelRange } from '../state/selection.ts';
|
|
5
|
+
/**
|
|
6
|
+
* Vertical motion needs pixel geometry, which only a view has. Headless callers omit it and
|
|
7
|
+
* vertical commands fall back to same-column motion on the adjacent line.
|
|
8
|
+
*/
|
|
9
|
+
export interface Layout {
|
|
10
|
+
/** Position one visual line above (-1) or below (1) `pos`, aiming at `goalX`. */
|
|
11
|
+
moveVertically(pos: number, dir: -1 | 1, goalX: number | undefined): {
|
|
12
|
+
pos: number;
|
|
13
|
+
goalX: number;
|
|
14
|
+
};
|
|
15
|
+
/** Lines in one page, for PageUp/PageDown. */
|
|
16
|
+
readonly pageLines: number;
|
|
17
|
+
}
|
|
18
|
+
export interface CommandContext {
|
|
19
|
+
readonly state: Snapshot;
|
|
20
|
+
readonly layout?: Layout;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A command is pure: context in, spec out. null means "not applicable", which lets the keymap
|
|
24
|
+
* fall through to the next binding or to the platform default.
|
|
25
|
+
*/
|
|
26
|
+
export type Command = (ctx: CommandContext) => TransactionSpec | null;
|
|
27
|
+
/** What a per-range step produces: an optional change in old-document coordinates, plus the
|
|
28
|
+
* range it leaves behind, in *new*-document coordinates of that change alone. */
|
|
29
|
+
export interface RangeResult {
|
|
30
|
+
readonly change?: ChangeSpec;
|
|
31
|
+
readonly range: SelRange;
|
|
32
|
+
}
|
|
33
|
+
export declare function perRange(state: Snapshot, origin: Origin, step: (range: SelRange, text: Text) => RangeResult): TransactionSpec;
|
|
34
|
+
/** Next grapheme boundary after `pos`, crossing "\n" as one step. Segments only the current line. */
|
|
35
|
+
export declare function nextGrapheme(text: Text, pos: number): number;
|
|
36
|
+
export declare function prevGrapheme(text: Text, pos: number): number;
|
|
37
|
+
/** Replace every range with `text`. Origin decides undo grouping. Paste of N lines into N
|
|
38
|
+
* cursors distributes one line per cursor (TODO, CM6 behavior). */
|
|
39
|
+
export declare const insertText: (text: string, origin?: "input.type" | "input.paste" | "command") => Command;
|
|
40
|
+
export declare const deleteBackward: Command;
|
|
41
|
+
export declare const deleteForward: Command;
|
|
42
|
+
/** Inserts "\n" plus the current line's leading whitespace. */
|
|
43
|
+
export declare const insertNewline: Command;
|
|
44
|
+
export declare const moveGrapheme: (dir: -1 | 1, extend: boolean) => Command;
|
|
45
|
+
/** Home goes to the first non-whitespace column, then to column 0 on a second press. */
|
|
46
|
+
export declare const moveLineBoundary: (side: "start" | "end", extend: boolean) => Command;
|
|
47
|
+
export declare const moveVertical: (dir: -1 | 1, extend: boolean, page?: boolean) => Command;
|
|
48
|
+
export declare const selectAll: Command;
|
|
49
|
+
/** Escape: collapse to the primary cursor. Returns null with a single cursor so Escape can bubble. */
|
|
50
|
+
export declare const collapseSelection: Command;
|
|
51
|
+
/** Whether `ch` is a word character (letter, number, combining mark, or underscore). Shared with
|
|
52
|
+
* autoclose.ts, which skips pairing next to one. `''` (an edge of the document) is not a word
|
|
53
|
+
* character. */
|
|
54
|
+
export declare const isWordChar: (ch: string) => boolean;
|
|
55
|
+
/** The word boundary from `pos` in `dir`: skip spaces, then one run of word characters or of
|
|
56
|
+
* punctuation. At a line edge, the line break is one step, as with graphemes. */
|
|
57
|
+
export declare function wordBoundary(text: Text, pos: number, dir: -1 | 1): number;
|
|
58
|
+
export declare const moveWord: (dir: -1 | 1, extend: boolean) => Command;
|
|
59
|
+
export declare const deleteWord: (dir: -1 | 1) => Command;
|
|
60
|
+
/** Cmd-Backspace / Cmd-Delete on Apple platforms: to the start or end of the line. At the edge,
|
|
61
|
+
* the line break goes, as with a single Backspace. */
|
|
62
|
+
export declare const deleteToLineBoundary: (side: "start" | "end") => Command;
|
|
63
|
+
/** Delete every line any range touches, with its line break. */
|
|
64
|
+
export declare const deleteLine: Command;
|
|
65
|
+
/** How a language writes comments. A language with neither cannot toggle. */
|
|
66
|
+
export interface CommentSyntax {
|
|
67
|
+
readonly line?: string;
|
|
68
|
+
readonly block?: readonly [open: string, close: string];
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Mod-/. With a line comment, every non-blank line the selection touches gets the token at the
|
|
72
|
+
* smallest indentation among them, or loses it when all of them already have it. With only a
|
|
73
|
+
* block comment, each touched line's content is wrapped or unwrapped.
|
|
74
|
+
*/
|
|
75
|
+
export declare const toggleComment: (syntax: CommentSyntax | undefined) => Command;
|
|
76
|
+
/** Mod-Alt-ArrowUp / ArrowDown: a new primary cursor on the line above the topmost range, or
|
|
77
|
+
* below the bottommost, at the same goal column. */
|
|
78
|
+
export declare const addCursorVertical: (dir: -1 | 1) => Command;
|
|
79
|
+
/** The word around `pos`, or null when `pos` touches no word character. */
|
|
80
|
+
export declare function wordAt(text: Text, pos: number): {
|
|
81
|
+
from: number;
|
|
82
|
+
to: number;
|
|
83
|
+
} | null;
|
|
84
|
+
/** Mod-d: select the word at a bare cursor, then add the next occurrence of the primary
|
|
85
|
+
* selection after it, wrapping, as a new primary. */
|
|
86
|
+
export declare const selectNextOccurrence: Command;
|
|
87
|
+
/** Mod-Shift-l: every occurrence of the primary selection, or of the word at a bare cursor. */
|
|
88
|
+
export declare const selectAllOccurrences: Command;
|
|
89
|
+
/** Longest selection "highlight other occurrences" will search for (docs/TODO.md). Past this, a
|
|
90
|
+
* frame-budget scan of the mounted range isn't worth it. */
|
|
91
|
+
export declare const SELECTION_MATCH_MAX_LENGTH = 200;
|
|
92
|
+
/**
|
|
93
|
+
* Other occurrences of the primary selection within `[from, to)`, document offsets, skipping the
|
|
94
|
+
* selection itself. CodeMirror's `highlightSelectionMatches()`: whole-word when the selection
|
|
95
|
+
* spans exactly one word (so selecting "do" inside "dog" doesn't light up "dog"), substring
|
|
96
|
+
* otherwise. Deliberately selection-only — a bare caret matches nothing, so the highlight stays
|
|
97
|
+
* subtle and doesn't fire on every cursor move; this mirrors CodeMirror's default. Matches nothing
|
|
98
|
+
* when the selection is empty, spans more than one line, is whitespace-only, or is longer than
|
|
99
|
+
* `SELECTION_MATCH_MAX_LENGTH`.
|
|
100
|
+
*/
|
|
101
|
+
export declare function selectionMatches(state: Snapshot, from: number, to: number): {
|
|
102
|
+
from: number;
|
|
103
|
+
to: number;
|
|
104
|
+
}[];
|