@pierre/diffs 1.3.5 → 1.4.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/components/CodeView.d.ts +113 -68
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +153 -58
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts +75 -15
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +223 -62
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +97 -21
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +400 -100
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/UnresolvedFile.d.ts +2 -2
- package/dist/components/UnresolvedFile.d.ts.map +1 -1
- package/dist/components/UnresolvedFile.js +2 -2
- package/dist/components/UnresolvedFile.js.map +1 -1
- package/dist/components/VirtualizedFile.d.ts +16 -7
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +140 -51
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts +14 -8
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +183 -93
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/components/VirtulizerDevelopment.d.ts +1 -1
- package/dist/components/VirtulizerDevelopment.d.ts.map +1 -1
- package/dist/edit/index.d.ts +7 -4
- package/dist/edit/index.js +5 -1
- package/dist/editor/EditStateManager.d.ts +56 -0
- package/dist/editor/EditStateManager.d.ts.map +1 -0
- package/dist/editor/EditStateManager.js +135 -0
- package/dist/editor/EditStateManager.js.map +1 -0
- package/dist/editor/cloneRetainedDiffSessionSnapshot.d.ts +7 -0
- package/dist/editor/cloneRetainedDiffSessionSnapshot.d.ts.map +1 -0
- package/dist/editor/cloneRetainedDiffSessionSnapshot.js +16 -0
- package/dist/editor/cloneRetainedDiffSessionSnapshot.js.map +1 -0
- package/dist/editor/editPrediction.d.ts +76 -0
- package/dist/editor/editPrediction.d.ts.map +1 -0
- package/dist/editor/editPrediction.js +365 -0
- package/dist/editor/editPrediction.js.map +1 -0
- package/dist/editor/editStack.d.ts +19 -40
- package/dist/editor/editStack.d.ts.map +1 -1
- package/dist/editor/editStack.js +67 -4
- package/dist/editor/editStack.js.map +1 -1
- package/dist/editor/editor.d.ts +118 -29
- package/dist/editor/editor.d.ts.map +1 -1
- package/dist/editor/editor.js +1196 -403
- package/dist/editor/editor.js.map +1 -1
- package/dist/editor/editor2.js +1 -1
- package/dist/editor/languages.d.ts +3 -3
- package/dist/editor/languages.d.ts.map +1 -1
- package/dist/editor/languages.js.map +1 -1
- package/dist/editor/lineAnnotations.d.ts +3 -3
- package/dist/editor/lineAnnotations.d.ts.map +1 -1
- package/dist/editor/lineAnnotations.js +16 -7
- package/dist/editor/lineAnnotations.js.map +1 -1
- package/dist/editor/marker.d.ts +2 -2
- package/dist/editor/marker.d.ts.map +1 -1
- package/dist/editor/marker.js.map +1 -1
- package/dist/editor/matchBrackets.d.ts +2 -2
- package/dist/editor/matchBrackets.d.ts.map +1 -1
- package/dist/editor/matchBrackets.js.map +1 -1
- package/dist/editor/pieceTable.d.ts +1 -1
- package/dist/editor/pieceTable.js.map +1 -1
- package/dist/editor/searchPanel.d.ts +2 -2
- package/dist/editor/searchPanel.d.ts.map +1 -1
- package/dist/editor/searchPanel.js +3 -2
- package/dist/editor/searchPanel.js.map +1 -1
- package/dist/editor/selection.d.ts +33 -23
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/selection.js +3 -3
- package/dist/editor/selection.js.map +1 -1
- package/dist/editor/selectionAction.d.ts +3 -3
- package/dist/editor/selectionAction.d.ts.map +1 -1
- package/dist/editor/selectionAction.js.map +1 -1
- package/dist/editor/textDocument.d.ts +11 -8
- package/dist/editor/textDocument.d.ts.map +1 -1
- package/dist/editor/textDocument.js +28 -5
- package/dist/editor/textDocument.js.map +1 -1
- package/dist/editor/textDocumentChangeTransaction.d.ts +15 -0
- package/dist/editor/textDocumentChangeTransaction.d.ts.map +1 -0
- package/dist/editor/textDocumentChangeTransaction.js +12 -0
- package/dist/editor/textDocumentChangeTransaction.js.map +1 -0
- package/dist/editor/textMeasure.d.ts +5 -0
- package/dist/editor/textMeasure.d.ts.map +1 -1
- package/dist/editor/textMeasure.js +10 -0
- package/dist/editor/textMeasure.js.map +1 -1
- package/dist/editor/tokenizer.d.ts +1 -1
- package/dist/editor/tokenizer.d.ts.map +1 -1
- package/dist/editor/tokenizer.js +6 -3
- package/dist/editor/tokenizer.js.map +1 -1
- package/dist/editor/types.d.ts +267 -0
- package/dist/editor/types.d.ts.map +1 -0
- package/dist/editor/types.js +0 -0
- package/dist/editor/utils.d.ts +2 -1
- package/dist/editor/utils.d.ts.map +1 -1
- package/dist/editor/utils.js +4 -1
- package/dist/editor/utils.js.map +1 -1
- package/dist/index.d.ts +8 -6
- package/dist/index.js +9 -8
- package/dist/managers/InteractionManager.d.ts.map +1 -1
- package/dist/managers/InteractionManager.js +7 -0
- package/dist/managers/InteractionManager.js.map +1 -1
- package/dist/react/CodeView.d.ts +36 -25
- package/dist/react/CodeView.d.ts.map +1 -1
- package/dist/react/CodeView.js +15 -14
- package/dist/react/CodeView.js.map +1 -1
- package/dist/react/EditContext.d.ts +8 -11
- package/dist/react/EditContext.d.ts.map +1 -1
- package/dist/react/EditContext.js +2 -9
- package/dist/react/EditContext.js.map +1 -1
- package/dist/react/File.d.ts +10 -6
- package/dist/react/File.d.ts.map +1 -1
- package/dist/react/File.js +8 -4
- package/dist/react/File.js.map +1 -1
- package/dist/react/FileDiff.d.ts +10 -5
- package/dist/react/FileDiff.d.ts.map +1 -1
- package/dist/react/FileDiff.js +8 -4
- package/dist/react/FileDiff.js.map +1 -1
- package/dist/react/MultiFileDiff.d.ts +8 -5
- package/dist/react/MultiFileDiff.d.ts.map +1 -1
- package/dist/react/MultiFileDiff.js +8 -12
- package/dist/react/MultiFileDiff.js.map +1 -1
- package/dist/react/PatchDiff.d.ts +7 -4
- package/dist/react/PatchDiff.d.ts.map +1 -1
- package/dist/react/PatchDiff.js +8 -4
- package/dist/react/PatchDiff.js.map +1 -1
- package/dist/react/UnresolvedFile.d.ts +3 -3
- package/dist/react/UnresolvedFile.d.ts.map +1 -1
- package/dist/react/UnresolvedFile.js.map +1 -1
- package/dist/react/index.d.ts +8 -5
- package/dist/react/types.d.ts +46 -9
- package/dist/react/types.d.ts.map +1 -1
- package/dist/react/utils/renderDiffChildren.d.ts +14 -12
- package/dist/react/utils/renderDiffChildren.d.ts.map +1 -1
- package/dist/react/utils/renderDiffChildren.js +2 -2
- package/dist/react/utils/renderDiffChildren.js.map +1 -1
- package/dist/react/utils/renderFileChildren.d.ts +14 -12
- package/dist/react/utils/renderFileChildren.d.ts.map +1 -1
- package/dist/react/utils/renderFileChildren.js +2 -2
- package/dist/react/utils/renderFileChildren.js.map +1 -1
- package/dist/react/utils/useFileDiffInstance.d.ts +22 -10
- package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileDiffInstance.js +112 -22
- package/dist/react/utils/useFileDiffInstance.js.map +1 -1
- package/dist/react/utils/useFileInstance.d.ts +15 -9
- package/dist/react/utils/useFileInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileInstance.js +84 -25
- package/dist/react/utils/useFileInstance.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +30 -15
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +172 -108
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts +27 -11
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js +138 -64
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.d.ts +2 -2
- package/dist/renderers/UnresolvedFileHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.js +2 -2
- package/dist/renderers/UnresolvedFileHunksRenderer.js.map +1 -1
- package/dist/shiki-stream/tokenizer.d.ts.map +1 -1
- package/dist/shiki-stream/tokenizer.js +2 -1
- package/dist/shiki-stream/tokenizer.js.map +1 -1
- package/dist/ssr/index.d.ts +2 -2
- package/dist/ssr/preloadDiffs.d.ts +21 -21
- package/dist/ssr/preloadDiffs.d.ts.map +1 -1
- package/dist/ssr/preloadDiffs.js +1 -1
- package/dist/ssr/preloadDiffs.js.map +1 -1
- package/dist/ssr/preloadFile.d.ts +6 -6
- package/dist/ssr/preloadFile.d.ts.map +1 -1
- package/dist/ssr/preloadFile.js.map +1 -1
- package/dist/ssr/preloadPatchFile.d.ts +4 -4
- package/dist/ssr/preloadPatchFile.d.ts.map +1 -1
- package/dist/ssr/preloadPatchFile.js.map +1 -1
- package/dist/style.js +1 -1
- package/dist/types.d.ts +13 -263
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/appendItems.d.ts +5 -0
- package/dist/utils/appendItems.d.ts.map +1 -0
- package/dist/utils/appendItems.js +8 -0
- package/dist/utils/appendItems.js.map +1 -0
- package/dist/utils/areDiffTargetsEqual.js +1 -1
- package/dist/utils/areDiffTargetsEqual.js.map +1 -1
- package/dist/utils/areFileTargetsEqual.d.ts +7 -0
- package/dist/utils/areFileTargetsEqual.d.ts.map +1 -0
- package/dist/utils/areFileTargetsEqual.js +8 -0
- package/dist/utils/areFileTargetsEqual.js.map +1 -0
- package/dist/utils/areManagedSnapshotsEqual.d.ts +1 -1
- package/dist/utils/areManagedSnapshotsEqual.d.ts.map +1 -1
- package/dist/utils/areManagedSnapshotsEqual.js.map +1 -1
- package/dist/utils/areOptionsEqual.d.ts +3 -3
- package/dist/utils/areOptionsEqual.d.ts.map +1 -1
- package/dist/utils/areOptionsEqual.js.map +1 -1
- package/dist/utils/cloneFileDiffMetadata.d.ts +3 -2
- package/dist/utils/cloneFileDiffMetadata.d.ts.map +1 -1
- package/dist/utils/cloneFileDiffMetadata.js +8 -5
- package/dist/utils/cloneFileDiffMetadata.js.map +1 -1
- package/dist/utils/composeCacheKey.d.ts +6 -0
- package/dist/utils/composeCacheKey.d.ts.map +1 -0
- package/dist/utils/composeCacheKey.js +10 -0
- package/dist/utils/composeCacheKey.js.map +1 -0
- package/dist/utils/editSessionAnnotations.d.ts +69 -0
- package/dist/utils/editSessionAnnotations.d.ts.map +1 -0
- package/dist/utils/editSessionAnnotations.js +64 -0
- package/dist/utils/editSessionAnnotations.js.map +1 -0
- package/dist/utils/editSessionHunks.d.ts +5 -3
- package/dist/utils/editSessionHunks.d.ts.map +1 -1
- package/dist/utils/editSessionHunks.js +7 -5
- package/dist/utils/editSessionHunks.js.map +1 -1
- package/dist/utils/getDiffHunksRendererOptions.d.ts +1 -1
- package/dist/utils/getDiffHunksRendererOptions.d.ts.map +1 -1
- package/dist/utils/getDiffHunksRendererOptions.js.map +1 -1
- package/dist/utils/getFileRendererOptions.d.ts +1 -1
- package/dist/utils/getFileRendererOptions.d.ts.map +1 -1
- package/dist/utils/getFileRendererOptions.js.map +1 -1
- package/dist/utils/hydratePartialDiff.d.ts.map +1 -1
- package/dist/utils/hydratePartialDiff.js +2 -1
- package/dist/utils/hydratePartialDiff.js.map +1 -1
- package/dist/utils/lineAnnotationIdentity.d.ts +16 -0
- package/dist/utils/lineAnnotationIdentity.d.ts.map +1 -0
- package/dist/utils/lineAnnotationIdentity.js +17 -0
- package/dist/utils/lineAnnotationIdentity.js.map +1 -0
- package/dist/utils/parseDiffFromFile.d.ts +2 -2
- package/dist/utils/parseDiffFromFile.d.ts.map +1 -1
- package/dist/utils/parseDiffFromFile.js +6 -6
- package/dist/utils/parseDiffFromFile.js.map +1 -1
- package/dist/utils/parsePatchFiles.d.ts +6 -3
- package/dist/utils/parsePatchFiles.d.ts.map +1 -1
- package/dist/utils/parsePatchFiles.js +34 -9
- package/dist/utils/parsePatchFiles.js.map +1 -1
- package/dist/utils/renderDiffWithHighlighter.d.ts.map +1 -1
- package/dist/utils/renderDiffWithHighlighter.js +6 -5
- package/dist/utils/renderDiffWithHighlighter.js.map +1 -1
- package/dist/utils/renderFileWithHighlighter.d.ts.map +1 -1
- package/dist/utils/renderFileWithHighlighter.js +7 -4
- package/dist/utils/renderFileWithHighlighter.js.map +1 -1
- package/dist/utils/trimPatchContext.d.ts.map +1 -1
- package/dist/utils/trimPatchContext.js +3 -2
- package/dist/utils/trimPatchContext.js.map +1 -1
- package/dist/utils/updateDiffHunks.js +1 -1
- package/dist/utils/virtualDiffLayout.js +1 -1
- package/dist/worker/WorkerPoolManager.d.ts +4 -3
- package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
- package/dist/worker/WorkerPoolManager.js +33 -4
- package/dist/worker/WorkerPoolManager.js.map +1 -1
- package/dist/worker/types.d.ts +5 -0
- package/dist/worker/types.d.ts.map +1 -1
- package/dist/worker/worker-portable.js +14 -6
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +14 -6
- package/dist/worker/worker.js.map +1 -1
- package/package.json +9 -1
- package/dist/editor/stateStorage.d.ts +0 -15
- package/dist/editor/stateStorage.d.ts.map +0 -1
- package/dist/editor/stateStorage.js +0 -65
- package/dist/editor/stateStorage.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EditHistoryState, EditorChange, EditorLineAnnotation, EditorSelection, EditorType, Position, Range, ResolvedTextEdit, TextEdit } from "./types.js";
|
|
2
2
|
import { EditStack } from "./editStack.js";
|
|
3
3
|
import { SearchParams } from "./searchPanel.js";
|
|
4
4
|
|
|
@@ -27,20 +27,23 @@ interface TextDocumentChange {
|
|
|
27
27
|
/** Per-edit rendered line ranges before adjacent ranges are coalesced. */
|
|
28
28
|
readonly changedLineChanges?: readonly [startLine: number, endLine: number, lineDelta: number, startCharacter?: number, endCharacter?: number, endedAtDocumentEnd?: boolean][];
|
|
29
29
|
}
|
|
30
|
-
type TextDocumentHistoryResult<LAnnotation> = [change: TextDocumentChange, selections?: EditorSelection[], lineAnnotations?:
|
|
30
|
+
type TextDocumentHistoryResult<EType extends EditorType, LAnnotation> = [change: TextDocumentChange, selections?: EditorSelection[], lineAnnotations?: EditorLineAnnotation<EType, LAnnotation>[], selectionEdits?: ResolvedTextEdit[]];
|
|
31
31
|
/**
|
|
32
32
|
* A vscode-languageserver-textdocument compatible text document.
|
|
33
33
|
*/
|
|
34
|
-
declare class TextDocument<LAnnotation> {
|
|
34
|
+
declare class TextDocument<EType extends EditorType = EditorType, LAnnotation = unknown> {
|
|
35
35
|
#private;
|
|
36
|
-
constructor(uri: string, text: string, languageId?: string, version?: number, editStack?: EditStack<LAnnotation
|
|
36
|
+
constructor(uri: string, text: string, languageId?: string, version?: number, editStack?: EditStack<EType, LAnnotation>, eol?: '\n' | '\r\n' | '\r');
|
|
37
37
|
get uri(): string;
|
|
38
38
|
get languageId(): string;
|
|
39
39
|
get version(): number;
|
|
40
40
|
get lineCount(): number;
|
|
41
|
-
get eol():
|
|
41
|
+
get eol(): '\n' | '\r\n' | '\r';
|
|
42
|
+
get history(): EditHistoryState<EType, LAnnotation>;
|
|
42
43
|
get canUndo(): boolean;
|
|
43
44
|
get canRedo(): boolean;
|
|
45
|
+
/** Clear undo and redo history without changing the document contents. */
|
|
46
|
+
clearHistory(): void;
|
|
44
47
|
positionAt(offset: number): Position;
|
|
45
48
|
positionsAt(offsets: readonly number[]): Position[];
|
|
46
49
|
offsetAt(position: Position): number;
|
|
@@ -57,9 +60,9 @@ declare class TextDocument<LAnnotation> {
|
|
|
57
60
|
resolveEdits(edits: readonly TextEdit[]): ResolvedTextEdit[];
|
|
58
61
|
applyResolvedEdits(edits: ResolvedTextEdit[], updateHistory?: boolean, selectionsBefore?: EditorSelection[], selectionsAfter?: EditorSelection[], undoBoundary?: boolean): TextDocumentChange | undefined;
|
|
59
62
|
setLastUndoSelectionsAfter(selections: EditorSelection[]): void;
|
|
60
|
-
setLastUndoLineAnnotations(lineAnnotationsBefore:
|
|
61
|
-
undo(): TextDocumentHistoryResult<LAnnotation> | undefined;
|
|
62
|
-
redo(): TextDocumentHistoryResult<LAnnotation> | undefined;
|
|
63
|
+
setLastUndoLineAnnotations(lineAnnotationsBefore: EditorLineAnnotation<EType, LAnnotation>[], lineAnnotationsAfter: EditorLineAnnotation<EType, LAnnotation>[]): void;
|
|
64
|
+
undo(): TextDocumentHistoryResult<EType, LAnnotation> | undefined;
|
|
65
|
+
redo(): TextDocumentHistoryResult<EType, LAnnotation> | undefined;
|
|
63
66
|
normalizePosition(position: Position): Position;
|
|
64
67
|
}
|
|
65
68
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textDocument.d.ts","names":[],"sources":["../../src/editor/textDocument.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"textDocument.d.ts","names":[],"sources":["../../src/editor/textDocument.ts"],"mappings":";;;;;UAwBiB,kBAAA;EAAA;EAAA,SAEN,OAAA,EAAS,YAAY;;WAErB,SAAA;EAFA;EAAA,SAIA,cAAA;EAFA;EAAA,SAIA,YAAA;EAAA;EAAA,SAEA,OAAA;EAEA;EAAA,SAAA,kBAAA;EAIA;EAAA,SAFA,iBAAA;EAMA;EAAA,SAJA,SAAA;EAIgD;EAAA,SAFhD,SAAA;EAKP;EAAA,SAHO,iBAAA,YAA6B,SAAA,UAAmB,OAAA;EAKvD;EAAA,SAHO,kBAAA,aACP,SAAA,UACA,OAAA,UACA,SAAA,UACA,cAAA,WACA,YAAA,WACA,kBAAA;AAAA;AAAA,KAMC,yBAAA,eAAwC,UAAA,kBAC3C,MAAA,EAAQ,kBAAA,EACR,UAAA,GAAa,eAAA,IACb,eAAA,GAAkB,oBAAA,CAAqB,KAAA,EAAO,WAAA,KAC9C,cAAA,GAAiB,gBAAA;;;;cAMN,YAAA,eACG,UAAA,GAAa,UAAA;EAAA;EAU3B,WAAA,CACE,GAAA,UACA,IAAA,UACA,UAAA,WACA,OAAA,WAC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KAAA,EAAO,WAAA;EAyBzC,IAAA,IAAQ,yBAAA,CAA0B,KAAA,EAAO,WAAA;EAyBzC,iBAAA,CAAkB,QAAA,EAAU,QAAA,GAAW,QAAA;AAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { countLineBreaks } from "../utils/computeFileOffsets.js";
|
|
2
2
|
import { EditStack, coalesceEditStackEntries, createEditStackEntry, shouldCoalesceEditStackEntry } from "./editStack.js";
|
|
3
3
|
import { PieceTable } from "./pieceTable.js";
|
|
4
|
+
import { setTextDocumentChangeTransaction } from "./textDocumentChangeTransaction.js";
|
|
4
5
|
//#region src/editor/textDocument.ts
|
|
5
6
|
/**
|
|
6
7
|
* A vscode-languageserver-textdocument compatible text document.
|
|
@@ -12,16 +13,19 @@ var TextDocument = class TextDocument {
|
|
|
12
13
|
#pieceTable;
|
|
13
14
|
#editStack;
|
|
14
15
|
#eol;
|
|
15
|
-
constructor(uri, text, languageId = "text", version = 0, editStack = new EditStack()) {
|
|
16
|
+
constructor(uri, text, languageId = "text", version = 0, editStack = new EditStack(), eol) {
|
|
16
17
|
this.#uri = new URL(uri, "file://").toString();
|
|
17
18
|
this.#languageId = languageId;
|
|
18
19
|
this.#version = version;
|
|
19
20
|
this.#pieceTable = new PieceTable(text);
|
|
20
21
|
this.#editStack = editStack;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
if (eol != null) this.#eol = eol;
|
|
23
|
+
else {
|
|
24
|
+
const firstLineBreak = this.#pieceTable.getLineText(0, true);
|
|
25
|
+
if (firstLineBreak.endsWith("\r\n")) this.#eol = "\r\n";
|
|
26
|
+
else if (firstLineBreak.endsWith("\r")) this.#eol = "\r";
|
|
27
|
+
else this.#eol = "\n";
|
|
28
|
+
}
|
|
25
29
|
}
|
|
26
30
|
get uri() {
|
|
27
31
|
return this.#uri;
|
|
@@ -38,12 +42,19 @@ var TextDocument = class TextDocument {
|
|
|
38
42
|
get eol() {
|
|
39
43
|
return this.#eol;
|
|
40
44
|
}
|
|
45
|
+
get history() {
|
|
46
|
+
return this.#editStack.getLiveState();
|
|
47
|
+
}
|
|
41
48
|
get canUndo() {
|
|
42
49
|
return this.#editStack.canUndo;
|
|
43
50
|
}
|
|
44
51
|
get canRedo() {
|
|
45
52
|
return this.#editStack.canRedo;
|
|
46
53
|
}
|
|
54
|
+
/** Clear undo and redo history without changing the document contents. */
|
|
55
|
+
clearHistory() {
|
|
56
|
+
this.#editStack.clear();
|
|
57
|
+
}
|
|
47
58
|
positionAt(offset) {
|
|
48
59
|
return this.normalizePosition(this.#pieceTable.positionAt(offset));
|
|
49
60
|
}
|
|
@@ -103,6 +114,10 @@ var TextDocument = class TextDocument {
|
|
|
103
114
|
this.#version++;
|
|
104
115
|
if (change.lineDelta === 0 && shouldCoalesceEditStackEntry(previousEntry, entry)) this.#editStack.replaceLastUndo(coalesceEditStackEntries(previousEntry, entry));
|
|
105
116
|
else this.#editStack.push(entry);
|
|
117
|
+
setTextDocumentChangeTransaction(change, {
|
|
118
|
+
appliedEdits: entry.forwardEdits,
|
|
119
|
+
inverseEdits: entry.inverseEdits
|
|
120
|
+
});
|
|
106
121
|
return change;
|
|
107
122
|
}
|
|
108
123
|
setLastUndoSelectionsAfter(selections) {
|
|
@@ -116,6 +131,10 @@ var TextDocument = class TextDocument {
|
|
|
116
131
|
if (entry === void 0) return;
|
|
117
132
|
const change = this.#applyResolvedEditsToBuffer(entry.inverseEdits);
|
|
118
133
|
if (change === void 0) return;
|
|
134
|
+
setTextDocumentChangeTransaction(change, {
|
|
135
|
+
appliedEdits: entry.inverseEdits,
|
|
136
|
+
inverseEdits: entry.forwardEdits
|
|
137
|
+
});
|
|
119
138
|
this.#version = entry.versionBefore;
|
|
120
139
|
const selections = entry.selectionsBefore?.slice();
|
|
121
140
|
return [
|
|
@@ -130,6 +149,10 @@ var TextDocument = class TextDocument {
|
|
|
130
149
|
if (entry === void 0) return;
|
|
131
150
|
const change = this.#applyResolvedEditsToBuffer(entry.forwardEdits);
|
|
132
151
|
if (change === void 0) return;
|
|
152
|
+
setTextDocumentChangeTransaction(change, {
|
|
153
|
+
appliedEdits: entry.forwardEdits,
|
|
154
|
+
inverseEdits: entry.inverseEdits
|
|
155
|
+
});
|
|
133
156
|
this.#version = entry.versionAfter;
|
|
134
157
|
const selections = entry.selectionsAfter?.slice();
|
|
135
158
|
return [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textDocument.js","names":["#uri","#languageId","#version","#pieceTable","#editStack","#eol","#applyResolvedEdits","#sortAndValidateResolvedEdits","#resolveEdit","#normalizeResolvedEdit","#applyResolvedEditsToBuffer","#clampIndex","#isInsideSurrogatePair","#computeChangedLineRange"],"sources":["../../src/editor/textDocument.ts"],"sourcesContent":["import type {\n DiffLineAnnotation,\n EditorChange,\n EditorSelection,\n Position,\n Range,\n ResolvedTextEdit,\n TextEdit,\n} from '../types';\nimport { countLineBreaks } from '../utils/computeFileOffsets';\nimport {\n coalesceEditStackEntries,\n createEditStackEntry,\n EditStack,\n shouldCoalesceEditStackEntry,\n} from './editStack';\nimport { PieceTable } from './pieceTable';\nimport type { SearchParams } from './searchPanel';\n\nexport type { Position, Range, TextEdit } from '../types';\n\nexport interface TextDocumentChange {\n /** The edits that were applied to the text document. */\n readonly changes: EditorChange[];\n /** First line whose rendered content or tokenizer state may have changed. */\n readonly startLine: number;\n /** Character on the first changed line where the edit began. */\n readonly startCharacter: number;\n /** Character on the original last changed line where the edit ended. */\n readonly endCharacter: number;\n /** Last line whose rendered content may have changed after the edit. */\n readonly endLine: number;\n /** Whether the original edit range ended at the previous document EOF. */\n readonly endedAtDocumentEnd: boolean;\n /** Line count before the edit was applied. */\n readonly previousLineCount: number;\n /** Line count after the edit was applied. */\n readonly lineCount: number;\n /** Difference between the old and new line counts. */\n readonly lineDelta: number;\n /** Exact rendered line ranges touched by each edit after the edit was applied. */\n readonly changedLineRanges: readonly [startLine: number, endLine: number][];\n /** Per-edit rendered line ranges before adjacent ranges are coalesced. */\n readonly changedLineChanges?: readonly [\n startLine: number,\n endLine: number,\n lineDelta: number,\n startCharacter?: number,\n endCharacter?: number,\n endedAtDocumentEnd?: boolean,\n ][];\n}\n\n// Metadata-less replay results include the resolved edits so Editor can remap\n// its live selections without storing a snapshot on the history entry.\ntype TextDocumentHistoryResult<LAnnotation> = [\n change: TextDocumentChange,\n selections?: EditorSelection[],\n lineAnnotations?: DiffLineAnnotation<LAnnotation>[],\n selectionEdits?: ResolvedTextEdit[],\n];\n\n/**\n * A vscode-languageserver-textdocument compatible text document.\n */\nexport class TextDocument<LAnnotation> {\n #uri: string;\n #languageId: string;\n #version: number;\n #pieceTable: PieceTable;\n #editStack: EditStack<LAnnotation>;\n #eol: string;\n\n constructor(\n uri: string,\n text: string,\n languageId = 'text',\n version = 0,\n editStack: EditStack<LAnnotation> = new EditStack()\n ) {\n this.#uri = new URL(uri, 'file://').toString();\n this.#languageId = languageId;\n this.#version = version;\n this.#pieceTable = new PieceTable(text);\n this.#editStack = editStack;\n\n // The line ending the document uses, detected once from its first line. Lets\n // inserted or pasted text match the rest of the file instead of leaving\n // mixed endings behind and keeps that convention stable as the file is\n // edited. Defaults to Unix `\\n` when the initial text has no line break.\n const firstLineBreak = this.#pieceTable.getLineText(0, true);\n if (firstLineBreak.endsWith('\\r\\n')) {\n this.#eol = '\\r\\n';\n } else if (firstLineBreak.endsWith('\\r')) {\n this.#eol = '\\r';\n } else {\n this.#eol = '\\n';\n }\n }\n\n get uri(): string {\n return this.#uri;\n }\n\n get languageId(): string {\n return this.#languageId;\n }\n\n get version(): number {\n return this.#version;\n }\n\n get lineCount(): number {\n return this.#pieceTable.lineCount;\n }\n\n get eol(): string {\n return this.#eol;\n }\n\n get canUndo(): boolean {\n return this.#editStack.canUndo;\n }\n\n get canRedo(): boolean {\n return this.#editStack.canRedo;\n }\n\n positionAt(offset: number): Position {\n return this.normalizePosition(this.#pieceTable.positionAt(offset));\n }\n\n positionsAt(offsets: readonly number[]): Position[] {\n const positions = this.#pieceTable.positionsAt(offsets);\n for (let i = 0; i < positions.length; i++) {\n positions[i] = this.normalizePosition(positions[i]);\n }\n return positions;\n }\n\n offsetAt(position: Position): number {\n return this.#pieceTable.offsetAt(this.normalizePosition(position));\n }\n\n getText(range?: Range): string {\n if (range === undefined) {\n return this.#pieceTable.getText();\n }\n // Clamp the range to visible line content before extracting text. A\n // preserved vertical-move \"goal column\" can leave a selection focus whose\n // character overshoots a shorter line; without this, the piece table clamps\n // to the line's offset span (which includes the trailing line break) and\n // copy/cut would pull in that newline. Mirrors `offsetAt`, which normalizes\n // positions the same way.\n return this.#pieceTable.getText({\n start: this.normalizePosition(range.start),\n end: this.normalizePosition(range.end),\n });\n }\n\n getLineText(line: number, includeLineBreak?: boolean): string {\n return this.#pieceTable.getLineText(line, includeLineBreak);\n }\n\n // Rewrites every line break in `text` to the document's EOL. Clipboard text\n // can carry Windows (`\\r\\n`) or classic-Mac (`\\r`) breaks; inserting it\n // verbatim would leave mixed line endings in a file that uses one style.\n normalizeEol(text: string): string {\n return text.replace(/\\r\\n|\\r|\\n/g, this.eol);\n }\n\n getLineLength(line: number, includeLineBreak?: boolean): number {\n return this.#pieceTable.getLineLength(line, includeLineBreak);\n }\n\n charAt(offset: number): string;\n charAt(position: Position): string;\n charAt(positionOrOffset: Position | number): string {\n if (typeof positionOrOffset === 'number') {\n return this.#pieceTable.charAt(positionOrOffset);\n }\n return this.#pieceTable.charAt(this.offsetAt(positionOrOffset));\n }\n\n getTextSlice(start: number, end: number): string {\n return this.#pieceTable.getTextSlice(start, end);\n }\n\n findNextNonOverlappingSubstring(\n needle: string,\n occupied: readonly [start: number, end: number][]\n ): number | undefined {\n return this.#pieceTable.findNextNonOverlappingSubstring(needle, occupied);\n }\n\n search(searchParams: SearchParams): [start: number, end: number][] {\n return this.#pieceTable.search(searchParams);\n }\n\n applyEdits(\n edits: TextEdit[],\n updateHistory = true,\n selectionsBefore?: EditorSelection[],\n selectionsAfter?: EditorSelection[],\n undoBoundary = false\n ): TextDocumentChange | undefined {\n if (edits.length === 0) {\n return;\n }\n return this.#applyResolvedEdits(\n this.#sortAndValidateResolvedEdits(this.resolveEdits(edits)),\n updateHistory,\n selectionsBefore,\n selectionsAfter,\n undoBoundary\n );\n }\n\n // Converts line/character ranges to the exact UTF-16 offsets applyEdits\n // uses, including widening invalid boundaries so they cannot split a valid\n // surrogate pair. Editor caret remapping uses the same resolved geometry.\n resolveEdits(edits: readonly TextEdit[]): ResolvedTextEdit[] {\n return edits.map((edit) => this.#resolveEdit(edit));\n }\n\n applyResolvedEdits(\n edits: ResolvedTextEdit[],\n updateHistory = true,\n selectionsBefore?: EditorSelection[],\n selectionsAfter?: EditorSelection[],\n undoBoundary = false\n ): TextDocumentChange | undefined {\n if (edits.length === 0) {\n return undefined;\n }\n return this.#applyResolvedEdits(\n this.#sortAndValidateResolvedEdits(\n edits.map((edit) => this.#normalizeResolvedEdit(edit))\n ),\n updateHistory,\n selectionsBefore,\n selectionsAfter,\n undoBoundary\n );\n }\n\n // Every edit joins the undo timeline: an edit applied with\n // `updateHistory=false` affects the edit stack exactly as the identical\n // call with `updateHistory=true` and no selections or undo boundary would.\n // The flag only controls whether the caller's interaction metadata is\n // recorded on the entry; the entry itself is always pushed (clearing any\n // pending redo) and coalesces by the normal geometry rules. This keeps a\n // mixed tracked/untracked sequence equivalent to the all-tracked sequence —\n // undo-to-exhaustion restores the original text, redo-to-exhaustion the\n // final text — instead of leaving frozen entries whose offsets go stale.\n // Only history replay (undo/redo) writes to the buffer without recording.\n #applyResolvedEdits(\n resolvedEdits: ResolvedTextEdit[],\n updateHistory: boolean,\n selectionsBefore: EditorSelection[] | undefined,\n selectionsAfter: EditorSelection[] | undefined,\n undoBoundary: boolean\n ): TextDocumentChange {\n const entry = createEditStackEntry(\n this,\n resolvedEdits,\n this.#version,\n this.#version + 1,\n updateHistory ? selectionsBefore : undefined,\n updateHistory ? selectionsAfter : undefined\n );\n if (updateHistory && undoBoundary) {\n entry.undoBoundary = true;\n }\n const previousEntry = this.#editStack.peekUndoForCoalescing();\n const change = this.#applyResolvedEditsToBuffer(resolvedEdits);\n this.#version++;\n if (\n change.lineDelta === 0 &&\n shouldCoalesceEditStackEntry(previousEntry, entry)\n ) {\n this.#editStack.replaceLastUndo(\n coalesceEditStackEntries(previousEntry!, entry)\n );\n } else {\n this.#editStack.push(entry);\n }\n return change;\n }\n\n setLastUndoSelectionsAfter(selections: EditorSelection[]): void {\n this.#editStack.setLastUndoSelectionsAfter(selections);\n }\n\n setLastUndoLineAnnotations(\n lineAnnotationsBefore: DiffLineAnnotation<LAnnotation>[],\n lineAnnotationsAfter: DiffLineAnnotation<LAnnotation>[]\n ): void {\n this.#editStack.setLastUndoLineAnnotations(\n lineAnnotationsBefore,\n lineAnnotationsAfter\n );\n }\n\n undo(): TextDocumentHistoryResult<LAnnotation> | undefined {\n const entry = this.#editStack.popUndoToRedo();\n if (entry === undefined) {\n return undefined;\n }\n const change = this.#applyResolvedEditsToBuffer(entry.inverseEdits);\n if (change === undefined) {\n return undefined;\n }\n this.#version = entry.versionBefore;\n const selections = entry.selectionsBefore?.slice();\n return [\n change,\n selections,\n entry.lineAnnotationsBefore?.slice(),\n selections === undefined\n ? entry.inverseEdits.map((edit) => ({ ...edit }))\n : undefined,\n ];\n }\n\n redo(): TextDocumentHistoryResult<LAnnotation> | undefined {\n const entry = this.#editStack.popRedoToUndo();\n if (entry === undefined) {\n return undefined;\n }\n const change = this.#applyResolvedEditsToBuffer(entry.forwardEdits);\n if (change === undefined) {\n return undefined;\n }\n this.#version = entry.versionAfter;\n const selections = entry.selectionsAfter?.slice();\n return [\n change,\n selections,\n entry.lineAnnotationsAfter?.slice(),\n selections === undefined\n ? entry.forwardEdits.map((edit) => ({ ...edit }))\n : undefined,\n ];\n }\n\n normalizePosition(position: Position): Position {\n const line = TextDocument.#clampIndex(position.line, this.lineCount - 1);\n return {\n line,\n character: TextDocument.#clampIndex(\n position.character,\n this.getLineLength(line)\n ),\n };\n }\n\n // Math.min/max pass NaN through, and a fractional index breaks the\n // integer-keyed line-offset lookup — either way the resolved offset becomes\n // NaN and a degenerate edit range can swallow the whole document. Malformed\n // components clamp like any other out-of-range value: NaN and -Infinity act\n // as 0, fractions floor, +Infinity clamps to the max.\n static #clampIndex(value: number, max: number): number {\n if (Number.isNaN(value)) {\n return 0;\n }\n return Math.max(0, Math.min(Math.floor(value), max));\n }\n\n #resolveEdit(edit: TextEdit): ResolvedTextEdit {\n let start = this.offsetAt(edit.range.start);\n let end = this.offsetAt(edit.range.end);\n if (start > end) {\n const t = start;\n start = end;\n end = t;\n }\n return this.#normalizeResolvedEdit({\n start,\n end,\n text: edit.newText,\n });\n }\n\n // Snaps an insertion before a pair and widens replacement boundaries\n // outward, so every edit addresses whole UTF-16 surrogate pairs.\n #normalizeResolvedEdit(edit: ResolvedTextEdit): ResolvedTextEdit {\n let { start, end } = edit;\n const isInsertion = start === end;\n if (this.#isInsideSurrogatePair(start)) {\n start--;\n }\n if (isInsertion) {\n end = start;\n } else if (this.#isInsideSurrogatePair(end)) {\n end++;\n }\n return { start, end, text: edit.text };\n }\n\n // A UTF-16 offset is invalid when it sits between the high and low units of\n // one well-formed surrogate pair. Lone surrogate units remain addressable.\n #isInsideSurrogatePair(offset: number): boolean {\n const previous = this.#pieceTable.charAt(offset - 1).charCodeAt(0);\n const next = this.#pieceTable.charAt(offset).charCodeAt(0);\n return (\n previous >= 0xd800 &&\n previous <= 0xdbff &&\n next >= 0xdc00 &&\n next <= 0xdfff\n );\n }\n\n #sortAndValidateResolvedEdits(edits: ResolvedTextEdit[]): ResolvedTextEdit[] {\n // Put zero-width edits before ranges at the same start so validation and\n // application do not depend on the caller's batch order.\n const sortedEdits = [...edits].sort((a, b) => {\n const startDelta = a.start - b.start;\n return startDelta === 0 ? a.end - b.end : startDelta;\n });\n for (let i = 0; i < sortedEdits.length - 1; i++) {\n if (sortedEdits[i].end > sortedEdits[i + 1].start) {\n throw new Error('Overlapping text edits are not supported');\n }\n }\n return sortedEdits;\n }\n\n #applyResolvedEditsToBuffer(edits: ResolvedTextEdit[]): TextDocumentChange {\n const previousLineCount = this.#pieceTable.lineCount;\n const editPositions = this.positionsAt(\n edits.flatMap((edit) => [edit.start, edit.end])\n );\n const changedLineRange = this.#computeChangedLineRange(\n edits,\n editPositions\n );\n const startPosition = editPositions[0];\n const endPosition = editPositions[editPositions.length - 1];\n const endedAtDocumentEnd =\n endPosition.line === previousLineCount - 1 &&\n endPosition.character ===\n this.#pieceTable.getLineLength(endPosition.line);\n this.#pieceTable.applyEdits(edits);\n const lineCount = this.#pieceTable.lineCount;\n const change: TextDocumentChange = {\n changes: edits.map((edit, index) => ({\n ...edit,\n range: {\n start: editPositions[index * 2],\n end: editPositions[index * 2 + 1],\n },\n })),\n startLine: changedLineRange.startLine,\n startCharacter: startPosition.character,\n endCharacter: endPosition.character,\n endLine: Math.min(changedLineRange.endLine, Math.max(0, lineCount - 1)),\n endedAtDocumentEnd,\n previousLineCount,\n lineCount,\n lineDelta: lineCount - previousLineCount,\n changedLineRanges: changedLineRange.ranges,\n changedLineChanges: changedLineRange.changes,\n };\n return change;\n }\n\n #computeChangedLineRange(\n edits: ResolvedTextEdit[],\n editPositions: Position[]\n ): {\n startLine: number;\n endLine: number;\n ranges: [number, number][];\n changes: [\n startLine: number,\n endLine: number,\n lineDelta: number,\n startCharacter: number,\n endCharacter: number,\n endedAtDocumentEnd: boolean,\n ][];\n } {\n let startLine = Infinity;\n let endLine = 0;\n let lineDeltaBeforeEdit = 0;\n const ranges: [number, number][] = [];\n const changes: [\n startLine: number,\n endLine: number,\n lineDelta: number,\n startCharacter: number,\n endCharacter: number,\n endedAtDocumentEnd: boolean,\n ][] = [];\n const previousLastLine = this.#pieceTable.lineCount - 1;\n const previousLastLineLength =\n this.#pieceTable.getLineLength(previousLastLine);\n for (let i = 0; i < edits.length; i++) {\n const edit = edits[i];\n const editStart = editPositions[i * 2];\n const editEnd = editPositions[i * 2 + 1];\n const editStartLine = editStart.line;\n const editEndLine = editEnd.line;\n const insertedLineSpan = countLineBreaks(edit.text);\n const changedStartLine = editStartLine + lineDeltaBeforeEdit;\n const changedEndLine = changedStartLine + insertedLineSpan;\n const lineDelta = insertedLineSpan - (editEndLine - editStartLine);\n startLine = Math.min(startLine, editStartLine);\n endLine = Math.max(endLine, changedEndLine);\n const lastRange = ranges[ranges.length - 1];\n if (lastRange !== undefined && changedStartLine <= lastRange[1] + 1) {\n ranges[ranges.length - 1] = [\n lastRange[0],\n Math.max(lastRange[1], changedEndLine),\n ];\n } else {\n ranges.push([changedStartLine, changedEndLine]);\n }\n changes.push([\n changedStartLine,\n changedEndLine,\n lineDelta,\n editStart.character,\n editEnd.character,\n editEndLine === previousLastLine &&\n editEnd.character === previousLastLineLength,\n ]);\n lineDeltaBeforeEdit += lineDelta;\n }\n if (startLine === Infinity) {\n return {\n startLine: 0,\n endLine: 0,\n ranges: [[0, 0]],\n changes: [[0, 0, 0, 0, 0, false]],\n };\n }\n return { startLine, endLine, ranges, changes };\n }\n}\n"],"mappings":";;;;;;;AAiEA,IAAa,eAAb,MAAa,aAA0B;CACrC;CACA;CACA;CACA;CACA;CACA;CAEA,YACE,KACA,MACA,aAAa,QACb,UAAU,GACV,YAAoC,IAAI,UAAU,GAClD;EACA,KAAKA,OAAO,IAAI,IAAI,KAAK,SAAS,CAAC,CAAC,SAAS;EAC7C,KAAKC,cAAc;EACnB,KAAKC,WAAW;EAChB,KAAKC,cAAc,IAAI,WAAW,IAAI;EACtC,KAAKC,aAAa;EAMlB,MAAM,iBAAiB,KAAKD,YAAY,YAAY,GAAG,IAAI;EAC3D,IAAI,eAAe,SAAS,MAAM,GAChC,KAAKE,OAAO;OACP,IAAI,eAAe,SAAS,IAAI,GACrC,KAAKA,OAAO;OAEZ,KAAKA,OAAO;CAEhB;CAEA,IAAI,MAAc;EAChB,OAAO,KAAKL;CACd;CAEA,IAAI,aAAqB;EACvB,OAAO,KAAKC;CACd;CAEA,IAAI,UAA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AC;GAEhD,QAAQ,KAAK;IACX;IACA;IACA;IACA,UAAU;IACV,QAAQ;IACR,gBAAgB,oBACd,QAAQ,cAAc;GAC1B,CAAC;GACD,uBAAuB;EACzB;EACA,IAAI,cAAc,UAChB,OAAO;GACL,WAAW;GACX,SAAS;GACT,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC;GACf,SAAS,CAAC;IAAC;IAAG;IAAG;IAAG;IAAG;IAAG;GAAK,CAAC;EAClC;EAEF,OAAO;GAAE;GAAW;GAAS;GAAQ;EAAQ;CAC/C;AACF"}
|
|
1
|
+
{"version":3,"file":"textDocument.js","names":["#uri","#languageId","#version","#pieceTable","#editStack","#eol","#applyResolvedEdits","#sortAndValidateResolvedEdits","#resolveEdit","#normalizeResolvedEdit","#applyResolvedEditsToBuffer","#clampIndex","#isInsideSurrogatePair","#computeChangedLineRange"],"sources":["../../src/editor/textDocument.ts"],"sourcesContent":["import { countLineBreaks } from '../utils/computeFileOffsets';\nimport {\n coalesceEditStackEntries,\n createEditStackEntry,\n EditStack,\n shouldCoalesceEditStackEntry,\n} from './editStack';\nimport { PieceTable } from './pieceTable';\nimport type { SearchParams } from './searchPanel';\nimport { setTextDocumentChangeTransaction } from './textDocumentChangeTransaction';\nimport type {\n EditHistoryState,\n EditorChange,\n EditorLineAnnotation,\n EditorSelection,\n EditorType,\n Position,\n Range,\n ResolvedTextEdit,\n TextEdit,\n} from './types';\n\nexport type { Position, Range, TextEdit } from './types';\n\nexport interface TextDocumentChange {\n /** The edits that were applied to the text document. */\n readonly changes: EditorChange[];\n /** First line whose rendered content or tokenizer state may have changed. */\n readonly startLine: number;\n /** Character on the first changed line where the edit began. */\n readonly startCharacter: number;\n /** Character on the original last changed line where the edit ended. */\n readonly endCharacter: number;\n /** Last line whose rendered content may have changed after the edit. */\n readonly endLine: number;\n /** Whether the original edit range ended at the previous document EOF. */\n readonly endedAtDocumentEnd: boolean;\n /** Line count before the edit was applied. */\n readonly previousLineCount: number;\n /** Line count after the edit was applied. */\n readonly lineCount: number;\n /** Difference between the old and new line counts. */\n readonly lineDelta: number;\n /** Exact rendered line ranges touched by each edit after the edit was applied. */\n readonly changedLineRanges: readonly [startLine: number, endLine: number][];\n /** Per-edit rendered line ranges before adjacent ranges are coalesced. */\n readonly changedLineChanges?: readonly [\n startLine: number,\n endLine: number,\n lineDelta: number,\n startCharacter?: number,\n endCharacter?: number,\n endedAtDocumentEnd?: boolean,\n ][];\n}\n\n// Metadata-less replay results include the resolved edits so Editor can remap\n// its live selections without storing a snapshot on the history entry.\ntype TextDocumentHistoryResult<EType extends EditorType, LAnnotation> = [\n change: TextDocumentChange,\n selections?: EditorSelection[],\n lineAnnotations?: EditorLineAnnotation<EType, LAnnotation>[],\n selectionEdits?: ResolvedTextEdit[],\n];\n\n/**\n * A vscode-languageserver-textdocument compatible text document.\n */\nexport class TextDocument<\n EType extends EditorType = EditorType,\n LAnnotation = unknown,\n> {\n #uri: string;\n #languageId: string;\n #version: number;\n #pieceTable: PieceTable;\n #editStack: EditStack<EType, LAnnotation>;\n #eol: '\\n' | '\\r\\n' | '\\r';\n\n constructor(\n uri: string,\n text: string,\n languageId = 'text',\n version = 0,\n editStack: EditStack<EType, LAnnotation> = new EditStack(),\n eol?: '\\n' | '\\r\\n' | '\\r'\n ) {\n this.#uri = new URL(uri, 'file://').toString();\n this.#languageId = languageId;\n this.#version = version;\n this.#pieceTable = new PieceTable(text);\n this.#editStack = editStack;\n\n // The line ending the document uses, detected once from its first line. Lets\n // inserted or pasted text match the rest of the file instead of leaving\n // mixed endings behind and keeps that convention stable as the file is\n // edited. Defaults to Unix `\\n` when the initial text has no line break.\n if (eol != null) {\n this.#eol = eol;\n } else {\n const firstLineBreak = this.#pieceTable.getLineText(0, true);\n if (firstLineBreak.endsWith('\\r\\n')) {\n this.#eol = '\\r\\n';\n } else if (firstLineBreak.endsWith('\\r')) {\n this.#eol = '\\r';\n } else {\n this.#eol = '\\n';\n }\n }\n }\n\n get uri(): string {\n return this.#uri;\n }\n\n get languageId(): string {\n return this.#languageId;\n }\n\n get version(): number {\n return this.#version;\n }\n\n get lineCount(): number {\n return this.#pieceTable.lineCount;\n }\n\n get eol(): '\\n' | '\\r\\n' | '\\r' {\n return this.#eol;\n }\n\n get history(): EditHistoryState<EType, LAnnotation> {\n return this.#editStack.getLiveState();\n }\n\n get canUndo(): boolean {\n return this.#editStack.canUndo;\n }\n\n get canRedo(): boolean {\n return this.#editStack.canRedo;\n }\n\n /** Clear undo and redo history without changing the document contents. */\n clearHistory(): void {\n this.#editStack.clear();\n }\n\n positionAt(offset: number): Position {\n return this.normalizePosition(this.#pieceTable.positionAt(offset));\n }\n\n positionsAt(offsets: readonly number[]): Position[] {\n const positions = this.#pieceTable.positionsAt(offsets);\n for (let i = 0; i < positions.length; i++) {\n positions[i] = this.normalizePosition(positions[i]);\n }\n return positions;\n }\n\n offsetAt(position: Position): number {\n return this.#pieceTable.offsetAt(this.normalizePosition(position));\n }\n\n getText(range?: Range): string {\n if (range === undefined) {\n return this.#pieceTable.getText();\n }\n // Clamp the range to visible line content before extracting text. A\n // preserved vertical-move \"goal column\" can leave a selection focus whose\n // character overshoots a shorter line; without this, the piece table clamps\n // to the line's offset span (which includes the trailing line break) and\n // copy/cut would pull in that newline. Mirrors `offsetAt`, which normalizes\n // positions the same way.\n return this.#pieceTable.getText({\n start: this.normalizePosition(range.start),\n end: this.normalizePosition(range.end),\n });\n }\n\n getLineText(line: number, includeLineBreak?: boolean): string {\n return this.#pieceTable.getLineText(line, includeLineBreak);\n }\n\n // Rewrites every line break in `text` to the document's EOL. Clipboard text\n // can carry Windows (`\\r\\n`) or classic-Mac (`\\r`) breaks; inserting it\n // verbatim would leave mixed line endings in a file that uses one style.\n normalizeEol(text: string): string {\n return text.replace(/\\r\\n|\\r|\\n/g, this.eol);\n }\n\n getLineLength(line: number, includeLineBreak?: boolean): number {\n return this.#pieceTable.getLineLength(line, includeLineBreak);\n }\n\n charAt(offset: number): string;\n charAt(position: Position): string;\n charAt(positionOrOffset: Position | number): string {\n if (typeof positionOrOffset === 'number') {\n return this.#pieceTable.charAt(positionOrOffset);\n }\n return this.#pieceTable.charAt(this.offsetAt(positionOrOffset));\n }\n\n getTextSlice(start: number, end: number): string {\n return this.#pieceTable.getTextSlice(start, end);\n }\n\n findNextNonOverlappingSubstring(\n needle: string,\n occupied: readonly [start: number, end: number][]\n ): number | undefined {\n return this.#pieceTable.findNextNonOverlappingSubstring(needle, occupied);\n }\n\n search(searchParams: SearchParams): [start: number, end: number][] {\n return this.#pieceTable.search(searchParams);\n }\n\n applyEdits(\n edits: TextEdit[],\n updateHistory = true,\n selectionsBefore?: EditorSelection[],\n selectionsAfter?: EditorSelection[],\n undoBoundary = false\n ): TextDocumentChange | undefined {\n if (edits.length === 0) {\n return;\n }\n return this.#applyResolvedEdits(\n this.#sortAndValidateResolvedEdits(this.resolveEdits(edits)),\n updateHistory,\n selectionsBefore,\n selectionsAfter,\n undoBoundary\n );\n }\n\n // Converts line/character ranges to the exact UTF-16 offsets applyEdits\n // uses, including widening invalid boundaries so they cannot split a valid\n // surrogate pair. Editor caret remapping uses the same resolved geometry.\n resolveEdits(edits: readonly TextEdit[]): ResolvedTextEdit[] {\n return edits.map((edit) => this.#resolveEdit(edit));\n }\n\n applyResolvedEdits(\n edits: ResolvedTextEdit[],\n updateHistory = true,\n selectionsBefore?: EditorSelection[],\n selectionsAfter?: EditorSelection[],\n undoBoundary = false\n ): TextDocumentChange | undefined {\n if (edits.length === 0) {\n return undefined;\n }\n return this.#applyResolvedEdits(\n this.#sortAndValidateResolvedEdits(\n edits.map((edit) => this.#normalizeResolvedEdit(edit))\n ),\n updateHistory,\n selectionsBefore,\n selectionsAfter,\n undoBoundary\n );\n }\n\n // Every edit joins the undo timeline: an edit applied with\n // `updateHistory=false` affects the edit stack exactly as the identical\n // call with `updateHistory=true` and no selections or undo boundary would.\n // The flag only controls whether the caller's interaction metadata is\n // recorded on the entry; the entry itself is always pushed (clearing any\n // pending redo) and coalesces by the normal geometry rules. This keeps a\n // mixed tracked/untracked sequence equivalent to the all-tracked sequence —\n // undo-to-exhaustion restores the original text, redo-to-exhaustion the\n // final text — instead of leaving frozen entries whose offsets go stale.\n // Only history replay (undo/redo) writes to the buffer without recording.\n #applyResolvedEdits(\n resolvedEdits: ResolvedTextEdit[],\n updateHistory: boolean,\n selectionsBefore: EditorSelection[] | undefined,\n selectionsAfter: EditorSelection[] | undefined,\n undoBoundary: boolean\n ): TextDocumentChange {\n const entry = createEditStackEntry(\n this,\n resolvedEdits,\n this.#version,\n this.#version + 1,\n updateHistory ? selectionsBefore : undefined,\n updateHistory ? selectionsAfter : undefined\n );\n if (updateHistory && undoBoundary) {\n entry.undoBoundary = true;\n }\n const previousEntry = this.#editStack.peekUndoForCoalescing();\n const change = this.#applyResolvedEditsToBuffer(resolvedEdits);\n this.#version++;\n if (\n change.lineDelta === 0 &&\n shouldCoalesceEditStackEntry(previousEntry, entry)\n ) {\n this.#editStack.replaceLastUndo(\n coalesceEditStackEntries(previousEntry!, entry)\n );\n } else {\n this.#editStack.push(entry);\n }\n setTextDocumentChangeTransaction(change, {\n appliedEdits: entry.forwardEdits,\n inverseEdits: entry.inverseEdits,\n });\n return change;\n }\n\n setLastUndoSelectionsAfter(selections: EditorSelection[]): void {\n this.#editStack.setLastUndoSelectionsAfter(selections);\n }\n\n setLastUndoLineAnnotations(\n lineAnnotationsBefore: EditorLineAnnotation<EType, LAnnotation>[],\n lineAnnotationsAfter: EditorLineAnnotation<EType, LAnnotation>[]\n ): void {\n this.#editStack.setLastUndoLineAnnotations(\n lineAnnotationsBefore,\n lineAnnotationsAfter\n );\n }\n\n undo(): TextDocumentHistoryResult<EType, LAnnotation> | undefined {\n const entry = this.#editStack.popUndoToRedo();\n if (entry === undefined) {\n return undefined;\n }\n const change = this.#applyResolvedEditsToBuffer(entry.inverseEdits);\n if (change === undefined) {\n return undefined;\n }\n setTextDocumentChangeTransaction(change, {\n appliedEdits: entry.inverseEdits,\n inverseEdits: entry.forwardEdits,\n });\n this.#version = entry.versionBefore;\n const selections = entry.selectionsBefore?.slice();\n return [\n change,\n selections,\n entry.lineAnnotationsBefore?.slice(),\n selections === undefined\n ? entry.inverseEdits.map((edit) => ({ ...edit }))\n : undefined,\n ];\n }\n\n redo(): TextDocumentHistoryResult<EType, LAnnotation> | undefined {\n const entry = this.#editStack.popRedoToUndo();\n if (entry === undefined) {\n return undefined;\n }\n const change = this.#applyResolvedEditsToBuffer(entry.forwardEdits);\n if (change === undefined) {\n return undefined;\n }\n setTextDocumentChangeTransaction(change, {\n appliedEdits: entry.forwardEdits,\n inverseEdits: entry.inverseEdits,\n });\n this.#version = entry.versionAfter;\n const selections = entry.selectionsAfter?.slice();\n return [\n change,\n selections,\n entry.lineAnnotationsAfter?.slice(),\n selections === undefined\n ? entry.forwardEdits.map((edit) => ({ ...edit }))\n : undefined,\n ];\n }\n\n normalizePosition(position: Position): Position {\n const line = TextDocument.#clampIndex(position.line, this.lineCount - 1);\n return {\n line,\n character: TextDocument.#clampIndex(\n position.character,\n this.getLineLength(line)\n ),\n };\n }\n\n // Math.min/max pass NaN through, and a fractional index breaks the\n // integer-keyed line-offset lookup — either way the resolved offset becomes\n // NaN and a degenerate edit range can swallow the whole document. Malformed\n // components clamp like any other out-of-range value: NaN and -Infinity act\n // as 0, fractions floor, +Infinity clamps to the max.\n static #clampIndex(value: number, max: number): number {\n if (Number.isNaN(value)) {\n return 0;\n }\n return Math.max(0, Math.min(Math.floor(value), max));\n }\n\n #resolveEdit(edit: TextEdit): ResolvedTextEdit {\n let start = this.offsetAt(edit.range.start);\n let end = this.offsetAt(edit.range.end);\n if (start > end) {\n const t = start;\n start = end;\n end = t;\n }\n return this.#normalizeResolvedEdit({\n start,\n end,\n text: edit.newText,\n });\n }\n\n // Snaps an insertion before a pair and widens replacement boundaries\n // outward, so every edit addresses whole UTF-16 surrogate pairs.\n #normalizeResolvedEdit(edit: ResolvedTextEdit): ResolvedTextEdit {\n let { start, end } = edit;\n const isInsertion = start === end;\n if (this.#isInsideSurrogatePair(start)) {\n start--;\n }\n if (isInsertion) {\n end = start;\n } else if (this.#isInsideSurrogatePair(end)) {\n end++;\n }\n return { start, end, text: edit.text };\n }\n\n // A UTF-16 offset is invalid when it sits between the high and low units of\n // one well-formed surrogate pair. Lone surrogate units remain addressable.\n #isInsideSurrogatePair(offset: number): boolean {\n const previous = this.#pieceTable.charAt(offset - 1).charCodeAt(0);\n const next = this.#pieceTable.charAt(offset).charCodeAt(0);\n return (\n previous >= 0xd800 &&\n previous <= 0xdbff &&\n next >= 0xdc00 &&\n next <= 0xdfff\n );\n }\n\n #sortAndValidateResolvedEdits(edits: ResolvedTextEdit[]): ResolvedTextEdit[] {\n // Put zero-width edits before ranges at the same start so validation and\n // application do not depend on the caller's batch order.\n const sortedEdits = [...edits].sort((a, b) => {\n const startDelta = a.start - b.start;\n return startDelta === 0 ? a.end - b.end : startDelta;\n });\n for (let i = 0; i < sortedEdits.length - 1; i++) {\n if (sortedEdits[i].end > sortedEdits[i + 1].start) {\n throw new Error('Overlapping text edits are not supported');\n }\n }\n return sortedEdits;\n }\n\n #applyResolvedEditsToBuffer(edits: ResolvedTextEdit[]): TextDocumentChange {\n const previousLineCount = this.#pieceTable.lineCount;\n const editPositions = this.positionsAt(\n edits.flatMap((edit) => [edit.start, edit.end])\n );\n const changedLineRange = this.#computeChangedLineRange(\n edits,\n editPositions\n );\n const startPosition = editPositions[0];\n const endPosition = editPositions[editPositions.length - 1];\n const endedAtDocumentEnd =\n endPosition.line === previousLineCount - 1 &&\n endPosition.character ===\n this.#pieceTable.getLineLength(endPosition.line);\n this.#pieceTable.applyEdits(edits);\n const lineCount = this.#pieceTable.lineCount;\n const change: TextDocumentChange = {\n changes: edits.map((edit, index) => ({\n ...edit,\n range: {\n start: editPositions[index * 2],\n end: editPositions[index * 2 + 1],\n },\n })),\n startLine: changedLineRange.startLine,\n startCharacter: startPosition.character,\n endCharacter: endPosition.character,\n endLine: Math.min(changedLineRange.endLine, Math.max(0, lineCount - 1)),\n endedAtDocumentEnd,\n previousLineCount,\n lineCount,\n lineDelta: lineCount - previousLineCount,\n changedLineRanges: changedLineRange.ranges,\n changedLineChanges: changedLineRange.changes,\n };\n return change;\n }\n\n #computeChangedLineRange(\n edits: ResolvedTextEdit[],\n editPositions: Position[]\n ): {\n startLine: number;\n endLine: number;\n ranges: [number, number][];\n changes: [\n startLine: number,\n endLine: number,\n lineDelta: number,\n startCharacter: number,\n endCharacter: number,\n endedAtDocumentEnd: boolean,\n ][];\n } {\n let startLine = Infinity;\n let endLine = 0;\n let lineDeltaBeforeEdit = 0;\n const ranges: [number, number][] = [];\n const changes: [\n startLine: number,\n endLine: number,\n lineDelta: number,\n startCharacter: number,\n endCharacter: number,\n endedAtDocumentEnd: boolean,\n ][] = [];\n const previousLastLine = this.#pieceTable.lineCount - 1;\n const previousLastLineLength =\n this.#pieceTable.getLineLength(previousLastLine);\n for (let i = 0; i < edits.length; i++) {\n const edit = edits[i];\n const editStart = editPositions[i * 2];\n const editEnd = editPositions[i * 2 + 1];\n const editStartLine = editStart.line;\n const editEndLine = editEnd.line;\n const insertedLineSpan = countLineBreaks(edit.text);\n const changedStartLine = editStartLine + lineDeltaBeforeEdit;\n const changedEndLine = changedStartLine + insertedLineSpan;\n const lineDelta = insertedLineSpan - (editEndLine - editStartLine);\n startLine = Math.min(startLine, editStartLine);\n endLine = Math.max(endLine, changedEndLine);\n const lastRange = ranges[ranges.length - 1];\n if (lastRange !== undefined && changedStartLine <= lastRange[1] + 1) {\n ranges[ranges.length - 1] = [\n lastRange[0],\n Math.max(lastRange[1], changedEndLine),\n ];\n } else {\n ranges.push([changedStartLine, changedEndLine]);\n }\n changes.push([\n changedStartLine,\n changedEndLine,\n lineDelta,\n editStart.character,\n editEnd.character,\n editEndLine === previousLastLine &&\n editEnd.character === previousLastLineLength,\n ]);\n lineDeltaBeforeEdit += lineDelta;\n }\n if (startLine === Infinity) {\n return {\n startLine: 0,\n endLine: 0,\n ranges: [[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AAC;GACf,SAAS,CAAC;IAAC;IAAG;IAAG;IAAG;IAAG;IAAG;GAAK,CAAC;EAClC;EAEF,OAAO;GAAE;GAAW;GAAS;GAAQ;EAAQ;CAC/C;AACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ResolvedTextEdit } from "./types.js";
|
|
2
|
+
import { TextDocumentChange } from "./textDocument.js";
|
|
3
|
+
|
|
4
|
+
//#region src/editor/textDocumentChangeTransaction.d.ts
|
|
5
|
+
interface TextDocumentChangeTransaction {
|
|
6
|
+
/** Edits applied to the document state before this change. */
|
|
7
|
+
readonly appliedEdits: readonly ResolvedTextEdit[];
|
|
8
|
+
/** Edits that restore the document state before this change. */
|
|
9
|
+
readonly inverseEdits: readonly ResolvedTextEdit[];
|
|
10
|
+
}
|
|
11
|
+
declare function getTextDocumentChangeTransaction(change: TextDocumentChange): TextDocumentChangeTransaction | undefined;
|
|
12
|
+
declare function setTextDocumentChangeTransaction(change: TextDocumentChange, transaction: TextDocumentChangeTransaction): void;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { TextDocumentChangeTransaction, getTextDocumentChangeTransaction, setTextDocumentChangeTransaction };
|
|
15
|
+
//# sourceMappingURL=textDocumentChangeTransaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"textDocumentChangeTransaction.d.ts","names":[],"sources":["../../src/editor/textDocumentChangeTransaction.ts"],"mappings":";;;;UAIiB,6BAAA;;WAEN,YAAA,WAAuB,gBAAA;EAFY;EAAA,SAInC,YAAA,WAAuB,gBAAgB;AAAA;AAAA,iBAQlC,gCAAA,CACd,MAAA,EAAQ,kBAAA,GACP,6BAA6B;AAAA,iBAIhB,gCAAA,CACd,MAAA,EAAQ,kBAAA,EACR,WAAA,EAAa,6BAA6B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/editor/textDocumentChangeTransaction.ts
|
|
2
|
+
const transactions = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
function getTextDocumentChangeTransaction(change) {
|
|
4
|
+
return transactions.get(change);
|
|
5
|
+
}
|
|
6
|
+
function setTextDocumentChangeTransaction(change, transaction) {
|
|
7
|
+
transactions.set(change, transaction);
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { getTextDocumentChangeTransaction, setTextDocumentChangeTransaction };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=textDocumentChangeTransaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"textDocumentChangeTransaction.js","names":[],"sources":["../../src/editor/textDocumentChangeTransaction.ts"],"sourcesContent":["import type { TextDocumentChange } from './textDocument';\nimport type { ResolvedTextEdit } from './types';\n\n// Keeps prediction-only edit metadata off the public TextDocumentChange shape.\nexport interface TextDocumentChangeTransaction {\n /** Edits applied to the document state before this change. */\n readonly appliedEdits: readonly ResolvedTextEdit[];\n /** Edits that restore the document state before this change. */\n readonly inverseEdits: readonly ResolvedTextEdit[];\n}\n\nconst transactions = new WeakMap<\n TextDocumentChange,\n TextDocumentChangeTransaction\n>();\n\nexport function getTextDocumentChangeTransaction(\n change: TextDocumentChange\n): TextDocumentChangeTransaction | undefined {\n return transactions.get(change);\n}\n\nexport function setTextDocumentChangeTransaction(\n change: TextDocumentChange,\n transaction: TextDocumentChangeTransaction\n): void {\n transactions.set(change, transaction);\n}\n"],"mappings":";AAWA,MAAM,+BAAe,IAAI,QAGvB;AAEF,SAAgB,iCACd,QAC2C;CAC3C,OAAO,aAAa,IAAI,MAAM;AAChC;AAEA,SAAgB,iCACd,QACA,aACM;CACN,aAAa,IAAI,QAAQ,WAAW;AACtC"}
|
|
@@ -29,6 +29,11 @@ declare class Metrics {
|
|
|
29
29
|
remeasureCharacterWidth(): boolean;
|
|
30
30
|
/** measure the width of the text */
|
|
31
31
|
measureTextWidth(text: string): number;
|
|
32
|
+
/**
|
|
33
|
+
* Pixel width from a wrapped segment's start up to a character. Tabs advance
|
|
34
|
+
* from the segment start so their stops line up with the rendered text.
|
|
35
|
+
*/
|
|
36
|
+
segmentTextWidth(lineText: string, segmentStart: number, character: number): number;
|
|
32
37
|
/** measure the width of the text using the canvas measureText API */
|
|
33
38
|
canvasMeasureTextWidth(text: string): number;
|
|
34
39
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textMeasure.d.ts","names":[],"sources":["../../src/editor/textMeasure.ts"],"mappings":";cAUa,OAAA;EAAA;EAAO;EASlB,EAAA;EASsB;EAPtB,OAAA;EAFA;EAIA,UAAA;EAAA;EAEA,UAAA;EAGA;EAAA,IAAA,CAAK,IAAA,EAAM,WAAW;EAAjB
|
|
1
|
+
{"version":3,"file":"textMeasure.d.ts","names":[],"sources":["../../src/editor/textMeasure.ts"],"mappings":";cAUa,OAAA;EAAA;EAAO;EASlB,EAAA;EASsB;EAPtB,OAAA;EAFA;EAIA,UAAA;EAAA;EAEA,UAAA;EAGA;EAAA,IAAA,CAAK,IAAA,EAAM,WAAW;EAAjB;;;;;;;;;;;;;;AA4Mc;EA7InB,uBAAA;EAyJqC;EA1IrC,gBAAA,CAAiB,IAAA;EA0IiC;AAAA;AAiBpD;;EAjHE,gBAAA,CACE,QAAA,UACA,YAAA,UACA,SAAA;EA+GF;EA3FA,sBAAA,CAAuB,IAAA;EAyIT;;;;AACF;EA9HZ,mBAAA,CAAoB,IAAA;EAyJqB;;;AAE1B;;EA1Gf,mBAAA;AAAA;;iBAYc,uBAAA,CAAwB,IAAY;;iBAiBpC,+BAAA,CACd,IAAA,UACA,MAAc;;iBA6CA,4BAAA,CACd,IAAY;;;;;;iBA2BE,2BAAA,CACd,IAAA,UACA,OAAe"}
|
|
@@ -84,6 +84,16 @@ var Metrics = class {
|
|
|
84
84
|
if (runStart < text.length) width += this.#measureTextWidthWithoutTabs(text.slice(runStart));
|
|
85
85
|
return round(width);
|
|
86
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Pixel width from a wrapped segment's start up to a character. Tabs advance
|
|
89
|
+
* from the segment start so their stops line up with the rendered text.
|
|
90
|
+
*/
|
|
91
|
+
segmentTextWidth(lineText, segmentStart, character) {
|
|
92
|
+
if (character <= segmentStart) return 0;
|
|
93
|
+
const segmentText = lineText.slice(segmentStart, character);
|
|
94
|
+
const asciiColumns = getExpandedAsciiTextColumns(segmentText, this.tabSize);
|
|
95
|
+
return asciiColumns !== -1 ? asciiColumns * this.ch : this.measureTextWidth(segmentText);
|
|
96
|
+
}
|
|
87
97
|
#measureTextWidthWithoutTabs(text) {
|
|
88
98
|
if (needsDomTextMeasurement(text)) return this.domMeasureTextWidth(text);
|
|
89
99
|
return this.canvasMeasureTextWidth(text);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textMeasure.js","names":["#root","#canvasCtx","#font","#clearTextWidthCache","#measureTextWidthWithoutTabs","#textWidthCache"],"sources":["../../src/editor/textMeasure.ts"],"sourcesContent":["import { getGraphemeSegmenter, h, round } from './utils';\n\n// Upper bound on cached DOM text-width measurements. The cache only holds\n// non-ASCII runs (emoji, ZWJ sequences, variation selectors, combining marks),\n// so it stays small for ordinary code, but capping it prevents unbounded growth\n// on emoji-heavy documents. Past the cap the oldest entry is evicted.\nconst TEXT_WIDTH_CACHE_LIMIT = 4096;\n\nconst COMBINING_MARK_PATTERN = /\\p{Mark}/u;\n\nexport class Metrics {\n #root?: HTMLElement;\n #canvasCtx?: CanvasRenderingContext2D;\n #font?: string;\n\n // Memoizes domMeasureTextWidth() results\n #textWidthCache = new Map<string, number>();\n\n /** Width of the '0' character. */\n ch: number = -1;\n /** Size of a tab(\\t) character. */\n tabSize: number = 2;\n /** Height of the code line. */\n lineHeight: number = 20;\n /** Padding top of the root element. */\n paddingTop: number = 0;\n\n /** initialize the metrics */\n init(root: HTMLElement): void {\n if (\n this.#root === root &&\n this.#canvasCtx !== undefined &&\n this.ch !== -1\n ) {\n // already initialized\n return;\n }\n\n this.#root = root;\n this.#canvasCtx ??=\n document.createElement('canvas').getContext('2d') ?? undefined;\n if (this.#canvasCtx === undefined) {\n throw new Error('Could not get canvas context');\n }\n\n const parent = root.parentElement;\n if (parent !== null) {\n const { paddingTop } = getComputedStyle(parent);\n if (paddingTop.endsWith('px')) {\n this.paddingTop = parseFloat(paddingTop.slice(0, -2));\n }\n }\n\n const { fontSize, fontFamily, tabSize, lineHeight } =\n getComputedStyle(root);\n if (lineHeight.endsWith('px')) {\n this.lineHeight = parseFloat(lineHeight.slice(0, -2));\n } else if (fontSize.endsWith('px')) {\n this.lineHeight = round(\n parseFloat(fontSize.slice(0, -2)) * parseFloat(lineHeight)\n );\n }\n const font = fontSize + ' ' + fontFamily;\n if (this.#font !== font || this.ch === -1) {\n this.#font = font;\n this.#canvasCtx.font = font;\n this.ch = this.canvasMeasureTextWidth('0');\n // Cached DOM widths were measured against the previous font.\n this.clearTextWidthCache();\n }\n const nextTabSize = parseInt(tabSize, 10);\n if (!Number.isNaN(nextTabSize)) {\n this.tabSize = nextTabSize;\n }\n }\n\n /**\n * Re-measure the '0' character width against the font that is loaded right\n * now, returning true when measurement-dependent UI should refresh.\n *\n * A custom web font can finish loading after the editor first renders.\n * Until then canvas measureText reports the fallback font's width, and\n * getComputedStyle returns the same font-family string before and after the\n * file arrives, so init()'s font guard never re-measures on its own. Call\n * this once fonts have settled (e.g. on document.fonts.ready) to replace a\n * width measured against the fallback font with the real glyph width. Font\n * completion can also change DOM-measured emoji/ZWJ widths while leaving the\n * ASCII width unchanged, and the computed font string stays the same in both\n * cases. The boolean return lets the caller skip re-rendering when there is no\n * measured state to refresh.\n */\n remeasureCharacterWidth(): boolean {\n if (this.#canvasCtx === undefined || this.#font === undefined) {\n return false;\n }\n this.#canvasCtx.font = this.#font;\n const ch = this.canvasMeasureTextWidth('0');\n const characterWidthChanged = ch !== this.ch;\n if (characterWidthChanged) {\n this.ch = ch;\n }\n const textWidthCacheCleared = this.#clearTextWidthCache();\n return characterWidthChanged || textWidthCacheCleared;\n }\n\n /** measure the width of the text */\n measureTextWidth(text: string): number {\n if (!text.includes('\\t')) {\n return this.#measureTextWidthWithoutTabs(text);\n }\n if (this.#canvasCtx === undefined) {\n throw new Error('Metrics not initialized');\n }\n const asciiColumns = getExpandedAsciiTextColumns(text, this.tabSize);\n if (asciiColumns !== -1) {\n return asciiColumns * this.ch;\n }\n\n let width = 0;\n let runStart = 0;\n const tabStopWidth = this.tabSize * this.ch;\n for (let i = 0; i < text.length; i++) {\n if (text.charCodeAt(i) !== /* '\\t' */ 9) {\n continue;\n }\n\n if (i > runStart) {\n width += this.#measureTextWidthWithoutTabs(text.slice(runStart, i));\n }\n // CSS tab stops are pixel positions, so wide glyphs before a tab must\n // contribute their measured width rather than one logical column.\n if (tabStopWidth > 0) {\n const remainder = width % tabStopWidth;\n width += remainder === 0 ? tabStopWidth : tabStopWidth - remainder;\n }\n runStart = i + 1;\n }\n\n if (runStart < text.length) {\n width += this.#measureTextWidthWithoutTabs(text.slice(runStart));\n }\n return round(width);\n }\n\n #measureTextWidthWithoutTabs(text: string): number {\n if (needsDomTextMeasurement(text)) {\n return this.domMeasureTextWidth(text);\n }\n return this.canvasMeasureTextWidth(text);\n }\n\n /** measure the width of the text using the canvas measureText API */\n canvasMeasureTextWidth(text: string): number {\n if (this.#canvasCtx === undefined) {\n throw new Error('Metrics not initialized');\n }\n return round(this.#canvasCtx.measureText(text).width);\n }\n\n /**\n * measure the width of the text using the DOM\n * this is slow because it cause a reflow, use it for non-ascii text;\n * results are memoized per text so repeated measurements skip the reflow\n */\n domMeasureTextWidth(text: string): number {\n if (this.#root === undefined) {\n throw new Error('Metrics not initialized');\n }\n const cacheKey = text + '|' + this.#font;\n const cached = this.#textWidthCache.get(cacheKey);\n if (cached !== undefined) {\n return cached;\n }\n const measureEl = h(\n 'span',\n {\n style: {\n position: 'absolute',\n top: '0',\n left: '0',\n visibility: 'hidden',\n pointerEvents: 'none',\n whiteSpace: 'pre',\n font: 'inherit',\n },\n textContent: text,\n },\n this.#root\n );\n let width: number;\n try {\n // round() to match canvasMeasureTextWidth and ch; otherwise the DOM path\n // returns raw sub-pixel widths and caret/selection offsets drift between\n // ASCII and non-ASCII runs on the same line.\n width = round(measureEl.getBoundingClientRect().width);\n } finally {\n measureEl.remove();\n }\n if (this.#textWidthCache.size >= TEXT_WIDTH_CACHE_LIMIT) {\n const oldestKey = this.#textWidthCache.keys().next().value;\n if (oldestKey !== undefined) {\n this.#textWidthCache.delete(oldestKey);\n }\n }\n this.#textWidthCache.set(cacheKey, width);\n return width;\n }\n\n /**\n * discard memoized DOM text widths\n * call this when the inherited font may have changed without re-running\n * init(), e.g. on a layout reflow, so stale widths are not reused\n */\n clearTextWidthCache(): void {\n this.#clearTextWidthCache();\n }\n\n #clearTextWidthCache(): boolean {\n const hadCachedTextWidths = this.#textWidthCache.size > 0;\n this.#textWidthCache.clear();\n return hadCachedTextWidths;\n }\n}\n\n/** Check if the text needs DOM text measurement. */\nexport function needsDomTextMeasurement(text: string): boolean {\n for (let i = 0; i < text.length; i++) {\n const code = text.charCodeAt(i);\n if (\n (code >= 0xd800 && code <= 0xdfff) ||\n code === 0x200d ||\n code === 0xfe0e ||\n code === 0xfe0f ||\n (code > 0x7f && COMBINING_MARK_PATTERN.test(text.charAt(i)))\n ) {\n return true;\n }\n }\n return false;\n}\n\n/** snap the text offset to the Unicode boundary */\nexport function snapTextOffsetToUnicodeBoundary(\n text: string,\n offset: number\n): number {\n const boundedOffset = Math.max(0, Math.min(offset, text.length));\n if (\n boundedOffset === 0 ||\n boundedOffset === text.length ||\n !needsDomTextMeasurement(text)\n ) {\n return boundedOffset;\n }\n // Avoid measuring a caret position inside one visual emoji/grapheme.\n // Browser caret movement can report offsets around UTF-16 surrogate\n // pairs and emoji joiners; measuring a partial sequence gives a\n // replacement-glyph width.\n const segmenter = getGraphemeSegmenter();\n if (segmenter !== undefined) {\n for (const segment of segmenter.segment(text)) {\n const segmentStart = segment.index;\n const segmentEnd = segmentStart + segment.segment.length;\n if (boundedOffset > segmentStart && boundedOffset < segmentEnd) {\n return segmentEnd;\n }\n if (boundedOffset <= segmentStart) {\n break;\n }\n }\n return boundedOffset;\n }\n // Degraded path for engines lacking Intl.Segmenter: snap out of a\n // surrogate pair by stepping over code points.\n let segmentStart = 0;\n for (const codePoint of text) {\n const segmentEnd = segmentStart + codePoint.length;\n if (boundedOffset > segmentStart && boundedOffset < segmentEnd) {\n return segmentEnd;\n }\n if (boundedOffset <= segmentStart) {\n break;\n }\n segmentStart = segmentEnd;\n }\n return boundedOffset;\n}\n\n/** get the offsets of the Unicode grapheme clusters in the text */\nexport function getUnicodeMeasurementOffsets(\n text: string\n): number[] | undefined {\n if (!needsDomTextMeasurement(text)) {\n return undefined;\n }\n const offsets = [0];\n const segmenter = getGraphemeSegmenter();\n if (segmenter !== undefined) {\n for (const segment of segmenter.segment(text)) {\n offsets.push(segment.index + segment.segment.length);\n }\n return offsets;\n }\n // Degraded path for engines lacking Intl.Segmenter: step by code point.\n let offset = 0;\n for (const codePoint of text) {\n offset += codePoint.length;\n offsets.push(offset);\n }\n return offsets;\n}\n\n/**\n * Count the rendered columns of ASCII text, advancing each tab to the next\n * fixed tab stop (a multiple of tabSize) to match CSS `tab-size`. Returns -1\n * for non-ASCII text, which must be measured glyph-by-glyph instead.\n */\nexport function getExpandedAsciiTextColumns(\n text: string,\n tabSize: number\n): number {\n let columns = 0;\n for (let i = 0; i < text.length; i++) {\n const code = text.charCodeAt(i);\n if (code > 127) {\n return -1;\n }\n columns += code === /* '\\t' */ 9 ? tabSize - (columns % tabSize) : 1;\n }\n return columns;\n}\n"],"mappings":";;AAMA,MAAM,yBAAyB;AAE/B,MAAM,yBAAyB;AAE/B,IAAa,UAAb,MAAqB;CACnB;CACA;CACA;CAGA,kCAAkB,IAAI,IAAoB;;CAG1C,KAAa;;CAEb,UAAkB;;CAElB,aAAqB;;CAErB,aAAqB;;CAGrB,KAAK,MAAyB;EAC5B,IACE,KAAKA,UAAU,QACf,KAAKC,eAAe,KAAA,KACpB,KAAK,OAAO,IAGZ;EAGF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,IAAI,gBAAgB,gBAAgB,gBAAgB,YAClD,OAAO;GAET,IAAI,iBAAiB,cACnB;EAEJ;EACA,OAAO;CACT;CAGA,IAAI,eAAe;CACnB,KAAK,MAAM,aAAa,MAAM;EAC5B,MAAM,aAAa,eAAe,UAAU;EAC5C,IAAI,gBAAgB,gBAAgB,gBAAgB,YAClD,OAAO;EAET,IAAI,iBAAiB,cACnB;EAEF,eAAe;CACjB;CACA,OAAO;AACT;;AAGA,SAAgB,6BACd,MACsB;CACtB,IAAI,CAAC,wBAAwB,IAAI,GAC/B;CAEF,MAAM,UAAU,CAAC,CAAC;CAClB,MAAM,YAAY,qBAAqB;CACvC,IAAI,cAAc,KAAA,GAAW;EAC3B,KAAK,MAAM,WAAW,UAAU,QAAQ,IAAI,GAC1C,QAAQ,KAAK,QAAQ,QAAQ,QAAQ,QAAQ,MAAM;EAErD,OAAO;CACT;CAEA,IAAI,SAAS;CACb,KAAK,MAAM,aAAa,MAAM;EAC5B,UAAU,UAAU;EACpB,QAAQ,KAAK,MAAM;CACrB;CACA,OAAO;AACT;;;;;;AAOA,SAAgB,4BACd,MACA,SACQ;CACR,IAAI,UAAU;CACd,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACpC,MAAM,OAAO,KAAK,WAAW,CAAC;EAC9B,IAAI,OAAO,KACT,OAAO;EAET,WAAW,SAAoB,IAAI,UAAW,UAAU,UAAW;CACrE;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"textMeasure.js","names":["#root","#canvasCtx","#font","#clearTextWidthCache","#measureTextWidthWithoutTabs","#textWidthCache"],"sources":["../../src/editor/textMeasure.ts"],"sourcesContent":["import { getGraphemeSegmenter, h, round } from './utils';\n\n// Upper bound on cached DOM text-width measurements. The cache only holds\n// non-ASCII runs (emoji, ZWJ sequences, variation selectors, combining marks),\n// so it stays small for ordinary code, but capping it prevents unbounded growth\n// on emoji-heavy documents. Past the cap the oldest entry is evicted.\nconst TEXT_WIDTH_CACHE_LIMIT = 4096;\n\nconst COMBINING_MARK_PATTERN = /\\p{Mark}/u;\n\nexport class Metrics {\n #root?: HTMLElement;\n #canvasCtx?: CanvasRenderingContext2D;\n #font?: string;\n\n // Memoizes domMeasureTextWidth() results\n #textWidthCache = new Map<string, number>();\n\n /** Width of the '0' character. */\n ch: number = -1;\n /** Size of a tab(\\t) character. */\n tabSize: number = 2;\n /** Height of the code line. */\n lineHeight: number = 20;\n /** Padding top of the root element. */\n paddingTop: number = 0;\n\n /** initialize the metrics */\n init(root: HTMLElement): void {\n if (\n this.#root === root &&\n this.#canvasCtx !== undefined &&\n this.ch !== -1\n ) {\n // already initialized\n return;\n }\n\n this.#root = root;\n this.#canvasCtx ??=\n document.createElement('canvas').getContext('2d') ?? undefined;\n if (this.#canvasCtx === undefined) {\n throw new Error('Could not get canvas context');\n }\n\n const parent = root.parentElement;\n if (parent !== null) {\n const { paddingTop } = getComputedStyle(parent);\n if (paddingTop.endsWith('px')) {\n this.paddingTop = parseFloat(paddingTop.slice(0, -2));\n }\n }\n\n const { fontSize, fontFamily, tabSize, lineHeight } =\n getComputedStyle(root);\n if (lineHeight.endsWith('px')) {\n this.lineHeight = parseFloat(lineHeight.slice(0, -2));\n } else if (fontSize.endsWith('px')) {\n this.lineHeight = round(\n parseFloat(fontSize.slice(0, -2)) * parseFloat(lineHeight)\n );\n }\n const font = fontSize + ' ' + fontFamily;\n if (this.#font !== font || this.ch === -1) {\n this.#font = font;\n this.#canvasCtx.font = font;\n this.ch = this.canvasMeasureTextWidth('0');\n // Cached DOM widths were measured against the previous font.\n this.clearTextWidthCache();\n }\n const nextTabSize = parseInt(tabSize, 10);\n if (!Number.isNaN(nextTabSize)) {\n this.tabSize = nextTabSize;\n }\n }\n\n /**\n * Re-measure the '0' character width against the font that is loaded right\n * now, returning true when measurement-dependent UI should refresh.\n *\n * A custom web font can finish loading after the editor first renders.\n * Until then canvas measureText reports the fallback font's width, and\n * getComputedStyle returns the same font-family string before and after the\n * file arrives, so init()'s font guard never re-measures on its own. Call\n * this once fonts have settled (e.g. on document.fonts.ready) to replace a\n * width measured against the fallback font with the real glyph width. Font\n * completion can also change DOM-measured emoji/ZWJ widths while leaving the\n * ASCII width unchanged, and the computed font string stays the same in both\n * cases. The boolean return lets the caller skip re-rendering when there is no\n * measured state to refresh.\n */\n remeasureCharacterWidth(): boolean {\n if (this.#canvasCtx === undefined || this.#font === undefined) {\n return false;\n }\n this.#canvasCtx.font = this.#font;\n const ch = this.canvasMeasureTextWidth('0');\n const characterWidthChanged = ch !== this.ch;\n if (characterWidthChanged) {\n this.ch = ch;\n }\n const textWidthCacheCleared = this.#clearTextWidthCache();\n return characterWidthChanged || textWidthCacheCleared;\n }\n\n /** measure the width of the text */\n measureTextWidth(text: string): number {\n if (!text.includes('\\t')) {\n return this.#measureTextWidthWithoutTabs(text);\n }\n if (this.#canvasCtx === undefined) {\n throw new Error('Metrics not initialized');\n }\n const asciiColumns = getExpandedAsciiTextColumns(text, this.tabSize);\n if (asciiColumns !== -1) {\n return asciiColumns * this.ch;\n }\n\n let width = 0;\n let runStart = 0;\n const tabStopWidth = this.tabSize * this.ch;\n for (let i = 0; i < text.length; i++) {\n if (text.charCodeAt(i) !== /* '\\t' */ 9) {\n continue;\n }\n\n if (i > runStart) {\n width += this.#measureTextWidthWithoutTabs(text.slice(runStart, i));\n }\n // CSS tab stops are pixel positions, so wide glyphs before a tab must\n // contribute their measured width rather than one logical column.\n if (tabStopWidth > 0) {\n const remainder = width % tabStopWidth;\n width += remainder === 0 ? tabStopWidth : tabStopWidth - remainder;\n }\n runStart = i + 1;\n }\n\n if (runStart < text.length) {\n width += this.#measureTextWidthWithoutTabs(text.slice(runStart));\n }\n return round(width);\n }\n\n /**\n * Pixel width from a wrapped segment's start up to a character. Tabs advance\n * from the segment start so their stops line up with the rendered text.\n */\n segmentTextWidth(\n lineText: string,\n segmentStart: number,\n character: number\n ): number {\n if (character <= segmentStart) {\n return 0;\n }\n const segmentText = lineText.slice(segmentStart, character);\n const asciiColumns = getExpandedAsciiTextColumns(segmentText, this.tabSize);\n return asciiColumns !== -1\n ? asciiColumns * this.ch\n : this.measureTextWidth(segmentText);\n }\n\n #measureTextWidthWithoutTabs(text: string): number {\n if (needsDomTextMeasurement(text)) {\n return this.domMeasureTextWidth(text);\n }\n return this.canvasMeasureTextWidth(text);\n }\n\n /** measure the width of the text using the canvas measureText API */\n canvasMeasureTextWidth(text: string): number {\n if (this.#canvasCtx === undefined) {\n throw new Error('Metrics not initialized');\n }\n return round(this.#canvasCtx.measureText(text).width);\n }\n\n /**\n * measure the width of the text using the DOM\n * this is slow because it cause a reflow, use it for non-ascii text;\n * results are memoized per text so repeated measurements skip the reflow\n */\n domMeasureTextWidth(text: string): number {\n if (this.#root === undefined) {\n throw new Error('Metrics not initialized');\n }\n const cacheKey = text + '|' + this.#font;\n const cached = this.#textWidthCache.get(cacheKey);\n if (cached !== undefined) {\n return cached;\n }\n const measureEl = h(\n 'span',\n {\n style: {\n position: 'absolute',\n top: '0',\n left: '0',\n visibility: 'hidden',\n pointerEvents: 'none',\n whiteSpace: 'pre',\n font: 'inherit',\n },\n textContent: text,\n },\n this.#root\n );\n let width: number;\n try {\n // round() to match canvasMeasureTextWidth and ch; otherwise the DOM path\n // returns raw sub-pixel widths and caret/selection offsets drift between\n // ASCII and non-ASCII runs on the same line.\n width = round(measureEl.getBoundingClientRect().width);\n } finally {\n measureEl.remove();\n }\n if (this.#textWidthCache.size >= TEXT_WIDTH_CACHE_LIMIT) {\n const oldestKey = this.#textWidthCache.keys().next().value;\n if (oldestKey !== undefined) {\n this.#textWidthCache.delete(oldestKey);\n }\n }\n this.#textWidthCache.set(cacheKey, width);\n return width;\n }\n\n /**\n * discard memoized DOM text widths\n * call this when the inherited font may have changed without re-running\n * init(), e.g. on a layout reflow, so stale widths are not reused\n */\n clearTextWidthCache(): void {\n this.#clearTextWidthCache();\n }\n\n #clearTextWidthCache(): boolean {\n const hadCachedTextWidths = this.#textWidthCache.size > 0;\n this.#textWidthCache.clear();\n return hadCachedTextWidths;\n }\n}\n\n/** Check if the text needs DOM text measurement. */\nexport function needsDomTextMeasurement(text: string): boolean {\n for (let i = 0; i < text.length; i++) {\n const code = text.charCodeAt(i);\n if (\n (code >= 0xd800 && code <= 0xdfff) ||\n code === 0x200d ||\n code === 0xfe0e ||\n code === 0xfe0f ||\n (code > 0x7f && COMBINING_MARK_PATTERN.test(text.charAt(i)))\n ) {\n return true;\n }\n }\n return false;\n}\n\n/** snap the text offset to the Unicode boundary */\nexport function snapTextOffsetToUnicodeBoundary(\n text: string,\n offset: number\n): number {\n const boundedOffset = Math.max(0, Math.min(offset, text.length));\n if (\n boundedOffset === 0 ||\n boundedOffset === text.length ||\n !needsDomTextMeasurement(text)\n ) {\n return boundedOffset;\n }\n // Avoid measuring a caret position inside one visual emoji/grapheme.\n // Browser caret movement can report offsets around UTF-16 surrogate\n // pairs and emoji joiners; measuring a partial sequence gives a\n // replacement-glyph width.\n const segmenter = getGraphemeSegmenter();\n if (segmenter !== undefined) {\n for (const segment of segmenter.segment(text)) {\n const segmentStart = segment.index;\n const segmentEnd = segmentStart + segment.segment.length;\n if (boundedOffset > segmentStart && boundedOffset < segmentEnd) {\n return segmentEnd;\n }\n if (boundedOffset <= segmentStart) {\n break;\n }\n }\n return boundedOffset;\n }\n // Degraded path for engines lacking Intl.Segmenter: snap out of a\n // surrogate pair by stepping over code points.\n let segmentStart = 0;\n for (const codePoint of text) {\n const segmentEnd = segmentStart + codePoint.length;\n if (boundedOffset > segmentStart && boundedOffset < segmentEnd) {\n return segmentEnd;\n }\n if (boundedOffset <= segmentStart) {\n break;\n }\n segmentStart = segmentEnd;\n }\n return boundedOffset;\n}\n\n/** get the offsets of the Unicode grapheme clusters in the text */\nexport function getUnicodeMeasurementOffsets(\n text: string\n): number[] | undefined {\n if (!needsDomTextMeasurement(text)) {\n return undefined;\n }\n const offsets = [0];\n const segmenter = getGraphemeSegmenter();\n if (segmenter !== undefined) {\n for (const segment of segmenter.segment(text)) {\n offsets.push(segment.index + segment.segment.length);\n }\n return offsets;\n }\n // Degraded path for engines lacking Intl.Segmenter: step by code point.\n let offset = 0;\n for (const codePoint of text) {\n offset += codePoint.length;\n offsets.push(offset);\n }\n return offsets;\n}\n\n/**\n * Count the rendered columns of ASCII text, advancing each tab to the next\n * fixed tab stop (a multiple of tabSize) to match CSS `tab-size`. Returns -1\n * for non-ASCII text, which must be measured glyph-by-glyph instead.\n */\nexport function getExpandedAsciiTextColumns(\n text: string,\n tabSize: number\n): number {\n let columns = 0;\n for (let i = 0; i < text.length; i++) {\n const code = text.charCodeAt(i);\n if (code > 127) {\n return -1;\n }\n columns += code === /* '\\t' */ 9 ? tabSize - (columns % tabSize) : 1;\n }\n return columns;\n}\n"],"mappings":";;AAMA,MAAM,yBAAyB;AAE/B,MAAM,yBAAyB;AAE/B,IAAa,UAAb,MAAqB;CACnB;CACA;CACA;CAGA,kCAAkB,IAAI,IAAoB;;CAG1C,KAAa;;CAEb,UAAkB;;CAElB,aAAqB;;CAErB,aAAqB;;CAGrB,KAAK,MAAyB;EAC5B,IACE,KAAKA,UAAU,QACf,KAAKC,eAAe,KAAA,KACpB,KAAK,OAAO,IAGZ;EAGF,KAAKD,QAAQ;EACb,KAAKC,eACH,SAAS,cAAc,QAAQ,CAAC,CAAC,WAAW,IAAI,KAAK,KAAA;EACvD,IAAI,KAAKA,eAAe,KAAA,GACtB,MAAM,IAAI,MAAM,8BAA8B;EAGhD,MAAM,SAAS,KAAK;EACpB,IAAI,WAAW,MAAM;GACnB,MAAM,EAAE,eAAe,iBAAiB,MAAM;GAC9C,IAAI,WAAW,SAAS,IAAI,GAC1B,KAAK,aAAa,WAAW,WAAW,MAAM,GAAG,EAAE,CAAC;EAExD;EAEA,MAAM,EAAE,UAAU,YAAY,SAAS,eACrC,iBAAiB,IAAI;EACvB,IAAI,WAAW,SAAS,IAAI,GAC1B,KAAK,aAAa,WAAW,WAAW,MAAM,GAAG,EAAE,CAAC;OAC/C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ACjB;CACA,OAAO;AACT;;AAGA,SAAgB,6BACd,MACsB;CACtB,IAAI,CAAC,wBAAwB,IAAI,GAC/B;CAEF,MAAM,UAAU,CAAC,CAAC;CAClB,MAAM,YAAY,qBAAqB;CACvC,IAAI,cAAc,KAAA,GAAW;EAC3B,KAAK,MAAM,WAAW,UAAU,QAAQ,IAAI,GAC1C,QAAQ,KAAK,QAAQ,QAAQ,QAAQ,QAAQ,MAAM;EAErD,OAAO;CACT;CAEA,IAAI,SAAS;CACb,KAAK,MAAM,aAAa,MAAM;EAC5B,UAAU,UAAU;EACpB,QAAQ,KAAK,MAAM;CACrB;CACA,OAAO;AACT;;;;;;AAOA,SAAgB,4BACd,MACA,SACQ;CACR,IAAI,UAAU;CACd,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACpC,MAAM,OAAO,KAAK,WAAW,CAAC;EAC9B,IAAI,OAAO,KACT,OAAO;EAET,WAAW,SAAoB,IAAI,UAAW,UAAU,UAAW;CACrE;CACA,OAAO;AACT"}
|
|
@@ -4,7 +4,7 @@ import { TextDocument, TextDocumentChange } from "./textDocument.js";
|
|
|
4
4
|
//#region src/editor/tokenizer.d.ts
|
|
5
5
|
interface EditorTokenizerProps {
|
|
6
6
|
highlighter: DiffsHighlighter;
|
|
7
|
-
textDocument: TextDocument
|
|
7
|
+
textDocument: TextDocument;
|
|
8
8
|
codeOptions: BaseCodeOptions;
|
|
9
9
|
matchBrackets?: boolean;
|
|
10
10
|
setStyle: (style: string) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokenizer.d.ts","names":[],"sources":["../../src/editor/tokenizer.ts"],"mappings":";;;;UAqBiB,oBAAA;EACf,WAAA,EAAa,gBAAA;EACb,YAAA,EAAc,YAAA;EACd,WAAA,EAAa,eAAA;EACb,aAAA;EACA,QAAA,GAAW,KAAA;EACX,eAAA,GACE,KAAA,EAAO,GAAA,SAAY,KAAA,CAAM,gBAAA,IACzB,SAAA;EAKF,aAAA;EACA,OAAA;AAAA;;cAIW,eAAA;EAAA;MAyFP,SAAA;EAIJ,kCAAA,CACE,SAAA;EAsBF,WAAA;IACE,WAAA;IACA,WAAA;IACA,YAAA;IACA,aAAA;IACA,QAAA;IACA,eAAA;IACA,aAAA;IACA;EAAA,GACC,oBAAA;EAsHH,SAAA,CAAU,WAAA,EAAa,eAAA;EAyFvB,OAAA;EAUA,QAAA,CACE,MAAA,EAAQ,kBAAA,EACR,WAAA,GAAc,WAAA,EACd,gBAAA,aACC,GAAA,SAAY,KAAA,CAAM,gBAAA;
|
|
1
|
+
{"version":3,"file":"tokenizer.d.ts","names":[],"sources":["../../src/editor/tokenizer.ts"],"mappings":";;;;UAqBiB,oBAAA;EACf,WAAA,EAAa,gBAAA;EACb,YAAA,EAAc,YAAA;EACd,WAAA,EAAa,eAAA;EACb,aAAA;EACA,QAAA,GAAW,KAAA;EACX,eAAA,GACE,KAAA,EAAO,GAAA,SAAY,KAAA,CAAM,gBAAA,IACzB,SAAA;EAKF,aAAA;EACA,OAAA;AAAA;;cAIW,eAAA;EAAA;MAyFP,SAAA;EAIJ,kCAAA,CACE,SAAA;EAsBF,WAAA;IACE,WAAA;IACA,WAAA;IACA,YAAA;IACA,aAAA;IACA,QAAA;IACA,eAAA;IACA,aAAA;IACA;EAAA,GACC,oBAAA;EAsHH,SAAA,CAAU,WAAA,EAAa,eAAA;EAyFvB,OAAA;EAUA,QAAA,CACE,MAAA,EAAQ,kBAAA,EACR,WAAA,GAAc,WAAA,EACd,gBAAA,aACC,GAAA,SAAY,KAAA,CAAM,gBAAA;EA+OrB,kBAAA,CAAmB,WAAA,GAAc,WAAA;EAKjC,sBAAA;EAiBA,uBAAA;EAYA,wBAAA;AAAA;AAAA,iBAocc,gBAAA,CACd,MAAA,EAAQ,KAAA,CAAM,gBAAA,KACZ,WAAA"}
|
package/dist/editor/tokenizer.js
CHANGED
|
@@ -188,7 +188,6 @@ var EditorTokenizer = class {
|
|
|
188
188
|
this.#ensureGrammar();
|
|
189
189
|
this.#ensureActiveTheme();
|
|
190
190
|
if (this.#grammar === void 0 && !isGrammarlessLanguage(this.#textDocument.languageId)) throw new Error(`Grammar for language "${this.#textDocument.languageId}" not loaded`);
|
|
191
|
-
if (this.#matchBrackets) this.#bracketIgnoredRanges.length = Math.min(this.#bracketIgnoredRanges.length, change.startLine);
|
|
192
191
|
const { lineCount } = this.#textDocument;
|
|
193
192
|
const { startingLine = 0, totalLines = Infinity } = renderRange ?? {};
|
|
194
193
|
const renderRangeEndLine = totalLines === Infinity ? lineCount : Math.min(startingLine + totalLines, lineCount);
|
|
@@ -196,6 +195,7 @@ var EditorTokenizer = class {
|
|
|
196
195
|
const viewStart = Math.max(startingLine, dirtyStart);
|
|
197
196
|
const crossesRenderRangeEnd = renderRange !== void 0 && totalLines !== Infinity && change.lineDelta > 0 && dirtyStart < renderRangeEndLine && change.endLine >= renderRangeEndLine;
|
|
198
197
|
const canReuseCachedStates = change.lineDelta === 0 && (change.changedLineChanges?.every(([, , lineDelta]) => lineDelta === 0) ?? true);
|
|
198
|
+
if (this.#matchBrackets && !canReuseCachedStates) this.#bracketIgnoredRanges.length = Math.min(this.#bracketIgnoredRanges.length, change.startLine);
|
|
199
199
|
const canReuseShiftedStates = hostRealignsRows && change.lineDelta !== 0 && dirtyStart >= startingLine;
|
|
200
200
|
const canCacheTokenizedStates = canReuseCachedStates || renderRange === void 0 || dirtyStart >= viewStart;
|
|
201
201
|
const changedLineRanges = change.changedLineRanges ?? [[dirtyStart, change.endLine]];
|
|
@@ -285,9 +285,12 @@ var EditorTokenizer = class {
|
|
|
285
285
|
this.#comparisonLineChanges = [];
|
|
286
286
|
}
|
|
287
287
|
if (offscreenDirtyLines !== void 0 && offscreenDirtyLines.size > 0) this.#onDeferTokenize(offscreenDirtyLines, this.#themeType);
|
|
288
|
-
if (backgroundStartLine !== void 0)
|
|
289
|
-
|
|
288
|
+
if (backgroundStartLine !== void 0) {
|
|
289
|
+
if (this.#matchBrackets && canReuseCachedStates) this.#bracketIgnoredRanges.length = Math.min(this.#bracketIgnoredRanges.length, backgroundStartLine);
|
|
290
|
+
this.#scheduleBackgroundTokenize(backgroundStartLine, changedLineRanges, backgroundChangedRangeIndex);
|
|
291
|
+
} else if (!settled && line < lineCount) {
|
|
290
292
|
const backgroundLine = crossesRenderRangeEnd && dirtyStart >= viewStart ? renderRangeEndLine : dirtyStart < viewStart && !canReuseCachedStates ? dirtyStart : line;
|
|
293
|
+
if (this.#matchBrackets && canReuseCachedStates) this.#bracketIgnoredRanges.length = Math.min(this.#bracketIgnoredRanges.length, backgroundLine);
|
|
291
294
|
this.#scheduleBackgroundTokenize(backgroundLine, changedLineRanges, changedRangeIndex);
|
|
292
295
|
}
|
|
293
296
|
return dirtyLines;
|