@vscode/markdown-editor 0.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/dist/commands/cursorCommands.d.ts +13 -0
- package/dist/commands/editCommands.d.ts +14 -0
- package/dist/commands/index.d.ts +4 -0
- package/dist/commands/selectionCommands.d.ts +6 -0
- package/dist/commands/types.d.ts +26 -0
- package/dist/core/geometry.d.ts +37 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/lengthEdit.d.ts +38 -0
- package/dist/core/offsetRange.d.ts +26 -0
- package/dist/core/selection.d.ts +13 -0
- package/dist/core/sourceOffset.d.ts +1 -0
- package/dist/core/stringEdit.d.ts +27 -0
- package/dist/core/stringValue.d.ts +8 -0
- package/dist/core/wordUtils.d.ts +6 -0
- package/dist/highlighter/defaultMonacoSyntaxHighlighter.d.ts +20 -0
- package/dist/highlighter/index.d.ts +3 -0
- package/dist/highlighter/monacoSyntaxHighlighter.d.ts +38 -0
- package/dist/highlighter/syntaxHighlighter.d.ts +67 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +4274 -0
- package/dist/index.js.map +1 -0
- package/dist/model/cursorNavigation.d.ts +7 -0
- package/dist/model/editorModel.d.ts +54 -0
- package/dist/model/index.d.ts +4 -0
- package/dist/model/measuredLayoutModel.d.ts +50 -0
- package/dist/observables.d.ts +1 -0
- package/dist/observables.js +463 -0
- package/dist/observables.js.map +1 -0
- package/dist/parser/_micromarkAdapter.d.ts +7 -0
- package/dist/parser/ast.d.ts +274 -0
- package/dist/parser/index.d.ts +4 -0
- package/dist/parser/parse.d.ts +2 -0
- package/dist/parser/parser.d.ts +14 -0
- package/dist/parser/reconcile.d.ts +33 -0
- package/dist/parser/test/getAnnotatedSource.d.ts +2 -0
- package/dist/parser/test/snapshot.d.ts +9 -0
- package/dist/parser/visualizeAst.d.ts +33 -0
- package/dist/runOnChange-owE1SMC0.js +1514 -0
- package/dist/runOnChange-owE1SMC0.js.map +1 -0
- package/dist/test/random.d.ts +16 -0
- package/dist/view/content/blockView.d.ts +179 -0
- package/dist/view/content/documentView.d.ts +41 -0
- package/dist/view/content/dom.d.ts +16 -0
- package/dist/view/content/katexEditableIdentifiers.d.ts +36 -0
- package/dist/view/content/viewNode.d.ts +93 -0
- package/dist/view/editorController.d.ts +34 -0
- package/dist/view/editorView.d.ts +100 -0
- package/dist/view/fixture/astViewerView.d.ts +27 -0
- package/dist/view/fixture/cyclingTsHighlighter.d.ts +17 -0
- package/dist/view/fixture/debugColors.d.ts +26 -0
- package/dist/view/fixture/monacoDebugPanel.d.ts +7 -0
- package/dist/view/index.d.ts +9 -0
- package/dist/view/measuredLayoutDebugView.d.ts +70 -0
- package/dist/view/parts/cursorView.d.ts +29 -0
- package/dist/view/parts/selectionView.d.ts +57 -0
- package/dist/view/viewData.d.ts +251 -0
- package/dist/view/visualLineMap.d.ts +157 -0
- package/dist/view/visualizeViewTree.d.ts +5 -0
- package/package.json +68 -0
- package/src/view/editor.css +517 -0
- package/src/view/themes/default.css +235 -0
- package/src/view/themes/github.css +308 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CursorCommand, VisualCursorCommand } from './types.js';
|
|
2
|
+
export declare const cursorRight: CursorCommand;
|
|
3
|
+
export declare const cursorLeft: CursorCommand;
|
|
4
|
+
export declare const cursorMoveRight: CursorCommand;
|
|
5
|
+
export declare const cursorMoveLeft: CursorCommand;
|
|
6
|
+
export declare const cursorWordRight: CursorCommand;
|
|
7
|
+
export declare const cursorWordLeft: CursorCommand;
|
|
8
|
+
export declare const cursorLineStart: CursorCommand;
|
|
9
|
+
export declare const cursorLineEnd: CursorCommand;
|
|
10
|
+
export declare const cursorDocumentStart: CursorCommand;
|
|
11
|
+
export declare const cursorDocumentEnd: CursorCommand;
|
|
12
|
+
export declare const cursorDown: VisualCursorCommand;
|
|
13
|
+
export declare const cursorUp: VisualCursorCommand;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EditCommand } from './types.js';
|
|
2
|
+
export declare const deleteLeft: EditCommand;
|
|
3
|
+
export declare const deleteRight: EditCommand;
|
|
4
|
+
export declare const deleteWordLeft: EditCommand;
|
|
5
|
+
export declare const deleteWordRight: EditCommand;
|
|
6
|
+
export declare function insertText(text: string): EditCommand;
|
|
7
|
+
export declare const insertParagraph: EditCommand;
|
|
8
|
+
export declare const insertLineBreak: EditCommand;
|
|
9
|
+
/**
|
|
10
|
+
* A Markdown hard line break: a `\n` whose preceding line ends with two spaces.
|
|
11
|
+
* Any spaces already trailing the insertion point count toward the two, so the
|
|
12
|
+
* line never accumulates more than the two needed to form the break.
|
|
13
|
+
*/
|
|
14
|
+
export declare const insertHardLineBreak: EditCommand;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { CursorCommand, VisualCursorCommand, EditCommand, SelectionCommand, CursorCommandContext, VisualCursorCommandContext, CursorMoveResult } from './types.js';
|
|
2
|
+
export { cursorRight, cursorLeft, cursorMoveRight, cursorMoveLeft, cursorWordRight, cursorWordLeft, cursorLineStart, cursorLineEnd, cursorDocumentStart, cursorDocumentEnd, cursorDown, cursorUp } from './cursorCommands.js';
|
|
3
|
+
export { deleteLeft, deleteRight, deleteWordLeft, deleteWordRight, insertText, insertParagraph, insertLineBreak, insertHardLineBreak } from './editCommands.js';
|
|
4
|
+
export { selectAll, selectWord, selectBlock } from './selectionCommands.js';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { OffsetRange } from '../core/offsetRange.js';
|
|
2
|
+
import { Selection } from '../core/selection.js';
|
|
3
|
+
import { CursorCommandContext, SelectionCommand } from './types.js';
|
|
4
|
+
export declare const selectAll: SelectionCommand;
|
|
5
|
+
export declare const selectWord: SelectionCommand;
|
|
6
|
+
export declare function selectBlock(ctx: CursorCommandContext, blockRange: OffsetRange): Selection;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Selection } from '../core/selection.js';
|
|
2
|
+
import { SourceOffset } from '../core/sourceOffset.js';
|
|
3
|
+
import { StringEdit } from '../core/stringEdit.js';
|
|
4
|
+
import { BlockAstNode, DocumentAstNode } from '../parser/ast.js';
|
|
5
|
+
import { VisualLineMap } from '../view/visualLineMap.js';
|
|
6
|
+
export interface CursorCommandContext {
|
|
7
|
+
readonly text: string;
|
|
8
|
+
readonly selection: Selection;
|
|
9
|
+
readonly document: DocumentAstNode;
|
|
10
|
+
readonly activeBlock: BlockAstNode | undefined;
|
|
11
|
+
}
|
|
12
|
+
export interface VisualCursorCommandContext extends CursorCommandContext {
|
|
13
|
+
readonly lineMap: VisualLineMap;
|
|
14
|
+
readonly desiredColumn: number | undefined;
|
|
15
|
+
}
|
|
16
|
+
export type CursorCommand = (ctx: CursorCommandContext) => SourceOffset;
|
|
17
|
+
export type VisualCursorCommand = (ctx: VisualCursorCommandContext) => CursorMoveResult;
|
|
18
|
+
export type EditCommand = (ctx: CursorCommandContext) => {
|
|
19
|
+
readonly edit: StringEdit;
|
|
20
|
+
readonly selection: Selection;
|
|
21
|
+
} | undefined;
|
|
22
|
+
export type SelectionCommand = (ctx: CursorCommandContext, offset: SourceOffset) => Selection;
|
|
23
|
+
export interface CursorMoveResult {
|
|
24
|
+
readonly offset: SourceOffset;
|
|
25
|
+
readonly desiredColumn: number | undefined;
|
|
26
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Immutable point in 2D space, in CSS-pixel client coordinates.
|
|
3
|
+
*/
|
|
4
|
+
export declare class Point2D {
|
|
5
|
+
readonly x: number;
|
|
6
|
+
readonly y: number;
|
|
7
|
+
static readonly ZERO: Point2D;
|
|
8
|
+
constructor(x: number, y: number);
|
|
9
|
+
translate(dx: number, dy: number): Point2D;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Immutable axis-aligned rectangle in 2D space, in CSS-pixel client
|
|
13
|
+
* coordinates. `x`/`y` is the top-left corner, growing right/down.
|
|
14
|
+
*
|
|
15
|
+
* Half-open in both dimensions: `right` and `bottom` are excluded.
|
|
16
|
+
*/
|
|
17
|
+
export declare class Rect2D {
|
|
18
|
+
readonly x: number;
|
|
19
|
+
readonly y: number;
|
|
20
|
+
readonly width: number;
|
|
21
|
+
readonly height: number;
|
|
22
|
+
static readonly EMPTY: Rect2D;
|
|
23
|
+
static fromPointPoint(left: number, top: number, right: number, bottom: number): Rect2D;
|
|
24
|
+
static fromPointSize(x: number, y: number, width: number, height: number): Rect2D;
|
|
25
|
+
private constructor();
|
|
26
|
+
get left(): number;
|
|
27
|
+
get top(): number;
|
|
28
|
+
get right(): number;
|
|
29
|
+
get bottom(): number;
|
|
30
|
+
get topLeft(): Point2D;
|
|
31
|
+
containsX(x: number): boolean;
|
|
32
|
+
containsY(y: number): boolean;
|
|
33
|
+
containsPoint(p: Point2D): boolean;
|
|
34
|
+
/** Same y/height, zero-width band at `x = this.left`. Useful for caret rects derived from a line. */
|
|
35
|
+
withZeroWidthAt(x: number): Rect2D;
|
|
36
|
+
translate(dx: number, dy: number): Rect2D;
|
|
37
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { OffsetRange } from './offsetRange.js';
|
|
2
|
+
export { StringEdit, StringReplacement } from './stringEdit.js';
|
|
3
|
+
export { LengthEdit, LengthReplacement } from './lengthEdit.js';
|
|
4
|
+
export { StringValue } from './stringValue.js';
|
|
5
|
+
export { Selection } from './selection.js';
|
|
6
|
+
export type { SourceOffset } from './sourceOffset.js';
|
|
7
|
+
export { Point2D, Rect2D } from './geometry.js';
|
|
8
|
+
export { findWordBoundaryLeft, findWordBoundaryRight, findWordAt } from './wordUtils.js';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { OffsetRange } from './offsetRange.js';
|
|
2
|
+
/**
|
|
3
|
+
* A single "the text in `replaceRange` now spans `newLength` characters"
|
|
4
|
+
* statement. Unlike {@link StringReplacement} it carries no text — it only
|
|
5
|
+
* describes *where* and *by how much* something changed, not *what to*.
|
|
6
|
+
*
|
|
7
|
+
* For syntax highlighting it means: the characters that used to occupy
|
|
8
|
+
* `replaceRange` are replaced by `newLength` characters whose tokens may now
|
|
9
|
+
* be coloured differently. A same-length replacement (`replaceRange.length ===
|
|
10
|
+
* newLength`) therefore means "these characters kept their positions but got
|
|
11
|
+
* re-coloured".
|
|
12
|
+
*/
|
|
13
|
+
export declare class LengthReplacement {
|
|
14
|
+
readonly replaceRange: OffsetRange;
|
|
15
|
+
readonly newLength: number;
|
|
16
|
+
static replace(replaceRange: OffsetRange, newLength: number): LengthReplacement;
|
|
17
|
+
constructor(replaceRange: OffsetRange, newLength: number);
|
|
18
|
+
get lengthDelta(): number;
|
|
19
|
+
equals(other: LengthReplacement): boolean;
|
|
20
|
+
toString(): string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A set of disjoint, sorted {@link LengthReplacement}s — the length-only
|
|
24
|
+
* counterpart of {@link StringEdit}. Used as the change reason of an
|
|
25
|
+
* observable so observers learn which offset ranges of the previous value map
|
|
26
|
+
* to which ranges of the new value (and thus what to invalidate) without
|
|
27
|
+
* carrying the new content itself.
|
|
28
|
+
*/
|
|
29
|
+
export declare class LengthEdit {
|
|
30
|
+
static readonly empty: LengthEdit;
|
|
31
|
+
static single(replacement: LengthReplacement): LengthEdit;
|
|
32
|
+
static replace(replaceRange: OffsetRange, newLength: number): LengthEdit;
|
|
33
|
+
readonly replacements: readonly LengthReplacement[];
|
|
34
|
+
constructor(replacements: readonly LengthReplacement[]);
|
|
35
|
+
get isEmpty(): boolean;
|
|
36
|
+
equals(other: LengthEdit): boolean;
|
|
37
|
+
toString(): string;
|
|
38
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare class OffsetRange {
|
|
2
|
+
readonly start: number;
|
|
3
|
+
readonly endExclusive: number;
|
|
4
|
+
static fromTo(start: number, endExclusive: number): OffsetRange;
|
|
5
|
+
static ofLength(length: number): OffsetRange;
|
|
6
|
+
static ofStartAndLength(start: number, length: number): OffsetRange;
|
|
7
|
+
static emptyAt(offset: number): OffsetRange;
|
|
8
|
+
constructor(start: number, endExclusive: number);
|
|
9
|
+
get isEmpty(): boolean;
|
|
10
|
+
get length(): number;
|
|
11
|
+
delta(offset: number): OffsetRange;
|
|
12
|
+
deltaStart(offset: number): OffsetRange;
|
|
13
|
+
deltaEnd(offset: number): OffsetRange;
|
|
14
|
+
contains(offset: number): boolean;
|
|
15
|
+
containsRange(other: OffsetRange): boolean;
|
|
16
|
+
intersects(other: OffsetRange): boolean;
|
|
17
|
+
intersectsOrTouches(other: OffsetRange): boolean;
|
|
18
|
+
intersect(other: OffsetRange): OffsetRange | undefined;
|
|
19
|
+
join(other: OffsetRange): OffsetRange;
|
|
20
|
+
isBefore(other: OffsetRange): boolean;
|
|
21
|
+
isAfter(other: OffsetRange): boolean;
|
|
22
|
+
substring(str: string): string;
|
|
23
|
+
slice<T>(arr: readonly T[]): T[];
|
|
24
|
+
equals(other: OffsetRange): boolean;
|
|
25
|
+
toString(): string;
|
|
26
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SourceOffset } from './sourceOffset.js';
|
|
2
|
+
import { OffsetRange } from './offsetRange.js';
|
|
3
|
+
export declare class Selection {
|
|
4
|
+
readonly anchor: SourceOffset;
|
|
5
|
+
readonly active: SourceOffset;
|
|
6
|
+
static collapsed(offset: SourceOffset): Selection;
|
|
7
|
+
constructor(anchor: SourceOffset, active: SourceOffset);
|
|
8
|
+
get isCollapsed(): boolean;
|
|
9
|
+
get isForward(): boolean;
|
|
10
|
+
get range(): OffsetRange;
|
|
11
|
+
collapseToActive(): Selection;
|
|
12
|
+
withActive(active: SourceOffset): Selection;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type SourceOffset = number;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { OffsetRange } from './offsetRange.js';
|
|
2
|
+
export declare class StringReplacement {
|
|
3
|
+
readonly replaceRange: OffsetRange;
|
|
4
|
+
readonly newText: string;
|
|
5
|
+
static insert(offset: number, text: string): StringReplacement;
|
|
6
|
+
static replace(range: OffsetRange, text: string): StringReplacement;
|
|
7
|
+
static delete(range: OffsetRange): StringReplacement;
|
|
8
|
+
constructor(replaceRange: OffsetRange, newText: string);
|
|
9
|
+
get isEmpty(): boolean;
|
|
10
|
+
equals(other: StringReplacement): boolean;
|
|
11
|
+
toString(): string;
|
|
12
|
+
}
|
|
13
|
+
export declare class StringEdit {
|
|
14
|
+
static readonly empty: StringEdit;
|
|
15
|
+
static single(replacement: StringReplacement): StringEdit;
|
|
16
|
+
static replace(range: OffsetRange, text: string): StringEdit;
|
|
17
|
+
static insert(offset: number, text: string): StringEdit;
|
|
18
|
+
static delete(range: OffsetRange): StringEdit;
|
|
19
|
+
readonly replacements: readonly StringReplacement[];
|
|
20
|
+
constructor(replacements: readonly StringReplacement[]);
|
|
21
|
+
get isEmpty(): boolean;
|
|
22
|
+
apply(base: string): string;
|
|
23
|
+
inverse(original: string): StringEdit;
|
|
24
|
+
equals(other: StringEdit): boolean;
|
|
25
|
+
mapOffset(offset: number): number;
|
|
26
|
+
toString(): string;
|
|
27
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function findWordBoundaryLeft(text: string, offset: number): number;
|
|
2
|
+
export declare function findWordBoundaryRight(text: string, offset: number): number;
|
|
3
|
+
export declare function findWordAt(text: string, offset: number): {
|
|
4
|
+
start: number;
|
|
5
|
+
end: number;
|
|
6
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { MonacoSyntaxHighlighter, IMonarchApi } from './monacoSyntaxHighlighter.js';
|
|
2
|
+
/** The Monarch language definitions the default highlighter wires up. */
|
|
3
|
+
export interface IDefaultMonarchGrammars {
|
|
4
|
+
typescript: unknown;
|
|
5
|
+
javascript: unknown;
|
|
6
|
+
css: unknown;
|
|
7
|
+
html: unknown;
|
|
8
|
+
python: unknown;
|
|
9
|
+
rust: unknown;
|
|
10
|
+
shell: unknown;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A {@link MonacoSyntaxHighlighter} preloaded with a handful of common Monarch
|
|
14
|
+
* grammars (plus the usual short aliases). Unknown languages fall back to an
|
|
15
|
+
* unstyled single token, so the highlighter is always safe to call.
|
|
16
|
+
*
|
|
17
|
+
* The Monarch runtime and grammar definitions are injected so this package
|
|
18
|
+
* depends on `monaco-editor` for types only.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createDefaultMonacoSyntaxHighlighter(monaco: IMonarchApi, grammars: IDefaultMonarchGrammars): MonacoSyntaxHighlighter;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { Token, type ISyntaxHighlighter, type ISyntaxHighlighterDocument, type ISyntaxHighlightedSnapshot, type SnapshotTokens, } from './syntaxHighlighter.js';
|
|
2
|
+
export { MonacoSyntaxHighlighter, type IMonarchApi } from './monacoSyntaxHighlighter.js';
|
|
3
|
+
export { createDefaultMonacoSyntaxHighlighter, type IDefaultMonarchGrammars } from './defaultMonacoSyntaxHighlighter.js';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { MonarchTokenizer } from 'monaco-editor/esm/vs/editor/standalone/common/monarch/monarchLexer.js';
|
|
2
|
+
import { ISyntaxHighlighterDocument, ISyntaxHighlighter } from './syntaxHighlighter.js';
|
|
3
|
+
/**
|
|
4
|
+
* The slice of monaco's Monarch internals the highlighter needs at runtime.
|
|
5
|
+
*
|
|
6
|
+
* `monaco-editor` is only a *type* dependency of this package; the caller (who
|
|
7
|
+
* owns a real monaco runtime) passes these in, keeping monaco out of the bundle.
|
|
8
|
+
*/
|
|
9
|
+
export interface IMonarchApi {
|
|
10
|
+
/** Compiles a Monarch language definition into the internal lexer form. */
|
|
11
|
+
compile(languageId: string, json: unknown): unknown;
|
|
12
|
+
MonarchTokenizer: new (languageService: unknown, standaloneThemeService: unknown, languageId: string, lexer: unknown, configurationService: unknown) => MonarchTokenizer;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* {@link ISyntaxHighlighter} backed by monaco's Monarch tokenizer.
|
|
16
|
+
*
|
|
17
|
+
* Highlighting is synchronous and incremental: an edit only re-runs the
|
|
18
|
+
* tokenizer from the first changed line onward (earlier lines and their saved
|
|
19
|
+
* end-states are reused), and the {@link LengthEdit} delivered with the new
|
|
20
|
+
* snapshot is the minimal char range whose colour actually changed.
|
|
21
|
+
*
|
|
22
|
+
* Only Monarch's *classic* tokenizer path is used, which needs neither a theme
|
|
23
|
+
* nor the DOM, so this runs headless (Node, workers) as well as in the browser.
|
|
24
|
+
*/
|
|
25
|
+
export declare class MonacoSyntaxHighlighter implements ISyntaxHighlighter {
|
|
26
|
+
private readonly _monaco;
|
|
27
|
+
private readonly _grammars;
|
|
28
|
+
private readonly _tokenizers;
|
|
29
|
+
/**
|
|
30
|
+
* @param _monaco The Monarch runtime ({@link IMonarchApi}), injected so this
|
|
31
|
+
* package depends on `monaco-editor` for types only.
|
|
32
|
+
* @param _grammars Maps a language id to its Monarch language definition.
|
|
33
|
+
*/
|
|
34
|
+
constructor(_monaco: IMonarchApi, _grammars: ReadonlyMap<string, unknown>);
|
|
35
|
+
create(language: string, initialText: string): ISyntaxHighlighterDocument;
|
|
36
|
+
dispose(): void;
|
|
37
|
+
private _tokenizerFor;
|
|
38
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { IObservableWithChange, ITransaction, IDisposable } from '@vscode/observables';
|
|
2
|
+
import { OffsetRange } from '../core/offsetRange.js';
|
|
3
|
+
import { StringEdit } from '../core/stringEdit.js';
|
|
4
|
+
import { LengthEdit } from '../core/lengthEdit.js';
|
|
5
|
+
export interface ISyntaxHighlighter {
|
|
6
|
+
create(language: string, initialText: string): ISyntaxHighlighterDocument;
|
|
7
|
+
}
|
|
8
|
+
export interface ISyntaxHighlighterDocument extends IDisposable {
|
|
9
|
+
/**
|
|
10
|
+
* Apply a source edit. The {@link snapshot} updates synchronously within
|
|
11
|
+
* `tx`, and the change it carries is the *minimal* {@link LengthEdit} that
|
|
12
|
+
* actually re-coloured — not the whole document.
|
|
13
|
+
*/
|
|
14
|
+
update(edit: StringEdit, tx: ITransaction): void;
|
|
15
|
+
/**
|
|
16
|
+
* The current snapshot. Its change reason is a {@link LengthEdit} mapping
|
|
17
|
+
* the previous snapshot's offsets to this one's wherever tokens changed.
|
|
18
|
+
*/
|
|
19
|
+
readonly snapshot: IObservableWithChange<ISyntaxHighlightedSnapshot, LengthEdit>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* An immutable view of one document's tokens at a point in time. It may be a
|
|
23
|
+
* thin view over the highlighter's mutable state: once the underlying document
|
|
24
|
+
* advances, calling a stale snapshot is allowed to throw.
|
|
25
|
+
*
|
|
26
|
+
* Token stability: across snapshots `S1 -> S2` (with the change delivered as a
|
|
27
|
+
* {@link LengthEdit}), `getTokens(r)` returns the same tokens for any range `r`
|
|
28
|
+
* not touched by that edit. Only ranges the edit reports as changed may recolour.
|
|
29
|
+
*/
|
|
30
|
+
export interface ISyntaxHighlightedSnapshot {
|
|
31
|
+
/**
|
|
32
|
+
* Tokens covering a region that contains `queryRange`. Tokens are never
|
|
33
|
+
* split: the returned {@link SnapshotTokens.range} is `queryRange` *grown*
|
|
34
|
+
* to whole-token boundaries, so a token that straddles an end of
|
|
35
|
+
* `queryRange` is returned in full. The result is dense over that grown
|
|
36
|
+
* range — `sum(token.length) === range.length` — which is why the range is
|
|
37
|
+
* returned alongside the tokens.
|
|
38
|
+
*/
|
|
39
|
+
getTokens(queryRange: OffsetRange): SnapshotTokens;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A run of {@link Token}s together with the exact {@link OffsetRange} they
|
|
43
|
+
* cover.
|
|
44
|
+
*
|
|
45
|
+
* Because tokens are returned whole (never clipped), this is the natural unit
|
|
46
|
+
* of structural comparison: for any region untouched by an edit, two snapshots
|
|
47
|
+
* return an equal `SnapshotTokens` (same `range`, same token lengths/classes).
|
|
48
|
+
*/
|
|
49
|
+
export interface SnapshotTokens {
|
|
50
|
+
readonly range: OffsetRange;
|
|
51
|
+
readonly tokens: readonly Token[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A coloured run of `length` characters. Tokens are *dense* and *offset-free*:
|
|
55
|
+
* a snapshot's tokens for a range cover it exactly, back to back, so
|
|
56
|
+
* `sum(token.length) === range.length`. A token never stores where it is — its
|
|
57
|
+
* position is implied by the lengths of the tokens before it, mirroring how the
|
|
58
|
+
* rest of the editor keeps source offsets out of its data structures.
|
|
59
|
+
*/
|
|
60
|
+
export declare class Token {
|
|
61
|
+
readonly length: number;
|
|
62
|
+
/** CSS class for this run, or `undefined` for an unstyled run. */
|
|
63
|
+
readonly className: string | undefined;
|
|
64
|
+
constructor(length: number,
|
|
65
|
+
/** CSS class for this run, or `undefined` for an unstyled run. */
|
|
66
|
+
className: string | undefined);
|
|
67
|
+
}
|