monaco-editor11 1.0.9 → 1.1.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/index.d.ts +1 -1
- package/dist/monaco-editor11.es.js +11 -16
- package/dist/monaco-editor11.umd.js +1 -1
- package/package.json +2 -2
- package/dist/monaco.d.ts +0 -8
- package/dist/workers/common/initialize.js +0 -16
- package/dist/workers/common/workers.js +0 -141
- package/dist/workers/editor/common/abstractSyntaxTokenBackend.js +0 -128
- package/dist/workers/editor/common/abstractText.js +0 -89
- package/dist/workers/editor/common/ast.js +0 -485
- package/dist/workers/editor/common/autoIndent.js +0 -390
- package/dist/workers/editor/common/beforeEditPositionMapper.js +0 -110
- package/dist/workers/editor/common/bracketPairsImpl.js +0 -717
- package/dist/workers/editor/common/bracketPairsTree.js +0 -343
- package/dist/workers/editor/common/brackets.js +0 -108
- package/dist/workers/editor/common/characterClassifier.js +0 -59
- package/dist/workers/editor/common/characterPair.js +0 -40
- package/dist/workers/editor/common/colorizedBracketPairsDecorationProvider.js +0 -97
- package/dist/workers/editor/common/columnRange.js +0 -35
- package/dist/workers/editor/common/combineTextEditInfos.js +0 -124
- package/dist/workers/editor/common/common.js +0 -20
- package/dist/workers/editor/common/computeMovedLines.js +0 -249
- package/dist/workers/editor/common/concat23Trees.js +0 -192
- package/dist/workers/editor/common/contiguousMultilineTokens.js +0 -32
- package/dist/workers/editor/common/contiguousMultilineTokensBuilder.js +0 -23
- package/dist/workers/editor/common/contiguousTokensEditing.js +0 -128
- package/dist/workers/editor/common/contiguousTokensStore.js +0 -207
- package/dist/workers/editor/common/coordinatesConverter.js +0 -51
- package/dist/workers/editor/common/cursor.js +0 -899
- package/dist/workers/editor/common/cursorAtomicMoveOperations.js +0 -145
- package/dist/workers/editor/common/cursorCollection.js +0 -194
- package/dist/workers/editor/common/cursorColumnSelection.js +0 -93
- package/dist/workers/editor/common/cursorColumns.js +0 -112
- package/dist/workers/editor/common/cursorCommon.js +0 -250
- package/dist/workers/editor/common/cursorContext.js +0 -15
- package/dist/workers/editor/common/cursorDeleteOperations.js +0 -231
- package/dist/workers/editor/common/cursorMoveCommands.js +0 -676
- package/dist/workers/editor/common/cursorMoveOperations.js +0 -290
- package/dist/workers/editor/common/cursorTypeEditOperations.js +0 -968
- package/dist/workers/editor/common/cursorTypeOperations.js +0 -173
- package/dist/workers/editor/common/cursorUtils.js +0 -75
- package/dist/workers/editor/common/cursorWordOperations.js +0 -720
- package/dist/workers/editor/common/defaultDocumentColorsComputer.js +0 -138
- package/dist/workers/editor/common/defaultLinesDiffComputer.js +0 -188
- package/dist/workers/editor/common/diffAlgorithm.js +0 -139
- package/dist/workers/editor/common/diffEditor.js +0 -38
- package/dist/workers/editor/common/dynamicProgrammingDiffing.js +0 -101
- package/dist/workers/editor/common/edit.js +0 -183
- package/dist/workers/editor/common/editOperation.js +0 -36
- package/dist/workers/editor/common/editStack.js +0 -363
- package/dist/workers/editor/common/editorAction.js +0 -26
- package/dist/workers/editor/common/editorBaseApi.js +0 -43
- package/dist/workers/editor/common/editorColorRegistry.js +0 -102
- package/dist/workers/editor/common/editorCommon.js +0 -13
- package/dist/workers/editor/common/editorConfigurationSchema.js +0 -338
- package/dist/workers/editor/common/editorContextKeys.js +0 -84
- package/dist/workers/editor/common/editorFeatures.js +0 -17
- package/dist/workers/editor/common/editorOptions.js +0 -3440
- package/dist/workers/editor/common/editorTheme.js +0 -23
- package/dist/workers/editor/common/editorWebWorker.js +0 -299
- package/dist/workers/editor/common/editorWorker.js +0 -9
- package/dist/workers/editor/common/editorWorkerHost.js +0 -15
- package/dist/workers/editor/common/editorZoom.js +0 -26
- package/dist/workers/editor/common/electricCharacter.js +0 -55
- package/dist/workers/editor/common/encodedTokenAttributes.js +0 -79
- package/dist/workers/editor/common/enterAction.js +0 -53
- package/dist/workers/editor/common/eolCounter.js +0 -44
- package/dist/workers/editor/common/findSectionHeaders.js +0 -128
- package/dist/workers/editor/common/fixBrackets.js +0 -67
- package/dist/workers/editor/common/fixedArray.js +0 -70
- package/dist/workers/editor/common/fontInfo.js +0 -172
- package/dist/workers/editor/common/fontInfoFromSettings.js +0 -29
- package/dist/workers/editor/common/getIconClasses.js +0 -106
- package/dist/workers/editor/common/getPositionOffsetTransformerFromTextModel.js +0 -24
- package/dist/workers/editor/common/glyphLanesModel.js +0 -61
- package/dist/workers/editor/common/guidesTextModelPart.js +0 -405
- package/dist/workers/editor/common/heuristicSequenceOptimizations.js +0 -374
- package/dist/workers/editor/common/indentRules.js +0 -63
- package/dist/workers/editor/common/indentation.js +0 -39
- package/dist/workers/editor/common/indentationGuesser.js +0 -178
- package/dist/workers/editor/common/indentationLineProcessor.js +0 -193
- package/dist/workers/editor/common/inlineDecorations.js +0 -26
- package/dist/workers/editor/common/inplaceReplaceSupport.js +0 -87
- package/dist/workers/editor/common/inputMode.js +0 -22
- package/dist/workers/editor/common/intervalTree.js +0 -1002
- package/dist/workers/editor/common/language.js +0 -9
- package/dist/workers/editor/common/languageBracketsConfiguration.js +0 -133
- package/dist/workers/editor/common/languageConfiguration.js +0 -138
- package/dist/workers/editor/common/languageConfigurationRegistry.js +0 -361
- package/dist/workers/editor/common/languageFeatureDebounce.js +0 -137
- package/dist/workers/editor/common/languageFeatureRegistry.js +0 -180
- package/dist/workers/editor/common/languageFeatures.js +0 -9
- package/dist/workers/editor/common/languageFeaturesService.js +0 -47
- package/dist/workers/editor/common/languageSelector.js +0 -112
- package/dist/workers/editor/common/languageService.js +0 -92
- package/dist/workers/editor/common/languages.js +0 -522
- package/dist/workers/editor/common/languagesAssociations.js +0 -193
- package/dist/workers/editor/common/languagesRegistry.js +0 -237
- package/dist/workers/editor/common/legacyLinesDiffComputer.js +0 -468
- package/dist/workers/editor/common/length.js +0 -129
- package/dist/workers/editor/common/lineDecorations.js +0 -208
- package/dist/workers/editor/common/lineEdit.js +0 -75
- package/dist/workers/editor/common/lineHeights.js +0 -370
- package/dist/workers/editor/common/linePart.js +0 -25
- package/dist/workers/editor/common/lineRange.js +0 -312
- package/dist/workers/editor/common/lineSequence.js +0 -36
- package/dist/workers/editor/common/lineTokens.js +0 -405
- package/dist/workers/editor/common/linesDiffComputer.js +0 -29
- package/dist/workers/editor/common/linesDiffComputers.js +0 -13
- package/dist/workers/editor/common/linesLayout.js +0 -765
- package/dist/workers/editor/common/linesSliceCharSequence.js +0 -205
- package/dist/workers/editor/common/linkComputer.js +0 -269
- package/dist/workers/editor/common/markerDecorations.js +0 -9
- package/dist/workers/editor/common/markerDecorationsService.js +0 -248
- package/dist/workers/editor/common/minimapTokensColorTracker.js +0 -58
- package/dist/workers/editor/common/mirrorTextModel.js +0 -117
- package/dist/workers/editor/common/model.js +0 -9
- package/dist/workers/editor/common/modelLineProjection.js +0 -350
- package/dist/workers/editor/common/modelLineProjectionData.js +0 -297
- package/dist/workers/editor/common/modelService.js +0 -413
- package/dist/workers/editor/common/modesRegistry.js +0 -75
- package/dist/workers/editor/common/monospaceLineBreaksComputer.js +0 -473
- package/dist/workers/editor/common/myersDiffAlgorithm.js +0 -159
- package/dist/workers/editor/common/nodeReader.js +0 -127
- package/dist/workers/editor/common/nullTokenize.js +0 -29
- package/dist/workers/editor/common/offsetRange.js +0 -225
- package/dist/workers/editor/common/onEnter.js +0 -109
- package/dist/workers/editor/common/oneCursor.js +0 -117
- package/dist/workers/editor/common/overviewZoneManager.js +0 -176
- package/dist/workers/editor/common/parser.js +0 -121
- package/dist/workers/editor/common/pieceTreeBase.js +0 -1473
- package/dist/workers/editor/common/pieceTreeTextBuffer.js +0 -461
- package/dist/workers/editor/common/pieceTreeTextBufferBuilder.js +0 -140
- package/dist/workers/editor/common/point.js +0 -50
- package/dist/workers/editor/common/position.js +0 -142
- package/dist/workers/editor/common/positionToOffset.js +0 -17
- package/dist/workers/editor/common/positionToOffsetImpl.js +0 -98
- package/dist/workers/editor/common/prefixSumComputer.js +0 -226
- package/dist/workers/editor/common/range.js +0 -421
- package/dist/workers/editor/common/rangeMapping.js +0 -229
- package/dist/workers/editor/common/rangeSingleLine.js +0 -17
- package/dist/workers/editor/common/rbTreeBase.js +0 -362
- package/dist/workers/editor/common/rect.js +0 -163
- package/dist/workers/editor/common/replaceCommand.js +0 -158
- package/dist/workers/editor/common/resolverService.js +0 -5
- package/dist/workers/editor/common/rgba.js +0 -35
- package/dist/workers/editor/common/richEditBrackets.js +0 -356
- package/dist/workers/editor/common/selection.js +0 -145
- package/dist/workers/editor/common/semanticTokensDto.js +0 -82
- package/dist/workers/editor/common/semanticTokensProviderStyling.js +0 -263
- package/dist/workers/editor/common/semanticTokensStyling.js +0 -9
- package/dist/workers/editor/common/semanticTokensStylingService.js +0 -47
- package/dist/workers/editor/common/shiftCommand.js +0 -241
- package/dist/workers/editor/common/smallImmutableSet.js +0 -108
- package/dist/workers/editor/common/sparseMultilineTokens.js +0 -548
- package/dist/workers/editor/common/sparseTokensStore.js +0 -210
- package/dist/workers/editor/common/standaloneEnums.js +0 -1017
- package/dist/workers/editor/common/standaloneStrings.js +0 -42
- package/dist/workers/editor/common/stringBuilder.js +0 -122
- package/dist/workers/editor/common/stringEdit.js +0 -165
- package/dist/workers/editor/common/supports.js +0 -58
- package/dist/workers/editor/common/surroundSelectionCommand.js +0 -44
- package/dist/workers/editor/common/textChange.js +0 -248
- package/dist/workers/editor/common/textEdit.js +0 -269
- package/dist/workers/editor/common/textLength.js +0 -87
- package/dist/workers/editor/common/textModel.js +0 -2031
- package/dist/workers/editor/common/textModelBracketPairs.js +0 -45
- package/dist/workers/editor/common/textModelDefaults.js +0 -18
- package/dist/workers/editor/common/textModelEditSource.js +0 -166
- package/dist/workers/editor/common/textModelEvents.js +0 -216
- package/dist/workers/editor/common/textModelGuides.js +0 -40
- package/dist/workers/editor/common/textModelPart.js +0 -23
- package/dist/workers/editor/common/textModelSearch.js +0 -455
- package/dist/workers/editor/common/textModelStringEdit.js +0 -11
- package/dist/workers/editor/common/textModelSync.impl.js +0 -307
- package/dist/workers/editor/common/textModelText.js +0 -26
- package/dist/workers/editor/common/textModelTokens.js +0 -436
- package/dist/workers/editor/common/textResourceConfiguration.js +0 -6
- package/dist/workers/editor/common/textToHtmlTokenizer.js +0 -139
- package/dist/workers/editor/common/tokenStore.js +0 -407
- package/dist/workers/editor/common/tokenWithTextArray.js +0 -73
- package/dist/workers/editor/common/tokenization.js +0 -287
- package/dist/workers/editor/common/tokenizationRegistry.js +0 -123
- package/dist/workers/editor/common/tokenizationTextModelPart.js +0 -275
- package/dist/workers/editor/common/tokenizer.js +0 -301
- package/dist/workers/editor/common/tokenizerSyntaxTokenBackend.js +0 -261
- package/dist/workers/editor/common/treeSitterLibraryService.js +0 -9
- package/dist/workers/editor/common/treeSitterSyntaxTokenBackend.js +0 -167
- package/dist/workers/editor/common/treeSitterThemeService.js +0 -9
- package/dist/workers/editor/common/treeSitterTokenizationImpl.js +0 -713
- package/dist/workers/editor/common/treeSitterTree.js +0 -395
- package/dist/workers/editor/common/treeViewsDnd.js +0 -24
- package/dist/workers/editor/common/treeViewsDndService.js +0 -12
- package/dist/workers/editor/common/trimTrailingWhitespaceCommand.js +0 -98
- package/dist/workers/editor/common/unicodeTextModelHighlighter.js +0 -188
- package/dist/workers/editor/common/utils.js +0 -62
- package/dist/workers/editor/common/viewContext.js +0 -22
- package/dist/workers/editor/common/viewEventHandler.js +0 -186
- package/dist/workers/editor/common/viewEvents.js +0 -180
- package/dist/workers/editor/common/viewLayout.js +0 -368
- package/dist/workers/editor/common/viewLineRenderer.js +0 -948
- package/dist/workers/editor/common/viewLinesViewportData.js +0 -30
- package/dist/workers/editor/common/viewModel.js +0 -98
- package/dist/workers/editor/common/viewModelDecoration.js +0 -55
- package/dist/workers/editor/common/viewModelDecorations.js +0 -132
- package/dist/workers/editor/common/viewModelEventDispatcher.js +0 -398
- package/dist/workers/editor/common/viewModelImpl.js +0 -1163
- package/dist/workers/editor/common/viewModelLines.js +0 -938
- package/dist/workers/editor/common/wordCharacterClassifier.js +0 -87
- package/dist/workers/editor/common/wordHelper.js +0 -127
- package/dist/workers/language/cssMode.js +0 -198
- package/dist/workers/language/cssWorker.js +0 -183
- package/dist/workers/language/htmlMode.js +0 -213
- package/dist/workers/language/htmlWorker.js +0 -126
- package/dist/workers/language/jsonMode.js +0 -224
- package/dist/workers/language/jsonWorker.js +0 -187
- package/dist/workers/language/languageFeatures.js +0 -1009
- package/dist/workers/language/lib.index.js +0 -103
- package/dist/workers/language/lib.js +0 -1107
- package/dist/workers/language/lspLanguageFeatures.js +0 -716
- package/dist/workers/language/monaco.contribution.js +0 -144
- package/dist/workers/language/tokenization.js +0 -189
- package/dist/workers/language/tsMode.js +0 -212
- package/dist/workers/language/tsWorker.js +0 -352
- package/dist/workers/language/typescriptServices.js +0 -210154
- package/dist/workers/language/typescriptServicesMetadata.js +0 -3
- package/dist/workers/language/workerManager.js +0 -65
- /package/dist/workers/{language/css.worker.js → css.worker.js} +0 -0
- /package/dist/workers/{editor/editor.worker.js → editor.worker.js} +0 -0
- /package/dist/workers/{language/html.worker.js → html.worker.js} +0 -0
- /package/dist/workers/{language/json.worker.js → json.worker.js} +0 -0
- /package/dist/workers/{language/ts.worker.js → ts.worker.js} +0 -0
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { localize } from '../../nls.js';
|
|
2
|
-
|
|
3
|
-
/*---------------------------------------------------------------------------------------------
|
|
4
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
5
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
6
|
-
*--------------------------------------------------------------------------------------------*/
|
|
7
|
-
var InspectTokensNLS;
|
|
8
|
-
(function (InspectTokensNLS) {
|
|
9
|
-
InspectTokensNLS.inspectTokensAction = localize(786, "Developer: Inspect Tokens");
|
|
10
|
-
})(InspectTokensNLS || (InspectTokensNLS = {}));
|
|
11
|
-
var GoToLineNLS;
|
|
12
|
-
(function (GoToLineNLS) {
|
|
13
|
-
GoToLineNLS.gotoLineActionLabel = localize(787, "Go to Line/Column...");
|
|
14
|
-
})(GoToLineNLS || (GoToLineNLS = {}));
|
|
15
|
-
var QuickHelpNLS;
|
|
16
|
-
(function (QuickHelpNLS) {
|
|
17
|
-
QuickHelpNLS.helpQuickAccessActionLabel = localize(788, "Show all Quick Access Providers");
|
|
18
|
-
})(QuickHelpNLS || (QuickHelpNLS = {}));
|
|
19
|
-
var QuickCommandNLS;
|
|
20
|
-
(function (QuickCommandNLS) {
|
|
21
|
-
QuickCommandNLS.quickCommandActionLabel = localize(789, "Command Palette");
|
|
22
|
-
QuickCommandNLS.quickCommandHelp = localize(790, "Show And Run Commands");
|
|
23
|
-
})(QuickCommandNLS || (QuickCommandNLS = {}));
|
|
24
|
-
var QuickOutlineNLS;
|
|
25
|
-
(function (QuickOutlineNLS) {
|
|
26
|
-
QuickOutlineNLS.quickOutlineActionLabel = localize(791, "Go to Symbol...");
|
|
27
|
-
QuickOutlineNLS.quickOutlineByCategoryActionLabel = localize(792, "Go to Symbol by Category...");
|
|
28
|
-
})(QuickOutlineNLS || (QuickOutlineNLS = {}));
|
|
29
|
-
var StandaloneCodeEditorNLS;
|
|
30
|
-
(function (StandaloneCodeEditorNLS) {
|
|
31
|
-
StandaloneCodeEditorNLS.editorViewAccessibleLabel = localize(793, "Editor content");
|
|
32
|
-
})(StandaloneCodeEditorNLS || (StandaloneCodeEditorNLS = {}));
|
|
33
|
-
var ToggleHighContrastNLS;
|
|
34
|
-
(function (ToggleHighContrastNLS) {
|
|
35
|
-
ToggleHighContrastNLS.toggleHighContrast = localize(794, "Toggle High Contrast Theme");
|
|
36
|
-
})(ToggleHighContrastNLS || (ToggleHighContrastNLS = {}));
|
|
37
|
-
var StandaloneServicesNLS;
|
|
38
|
-
(function (StandaloneServicesNLS) {
|
|
39
|
-
StandaloneServicesNLS.bulkEditServiceSummary = localize(795, "Made {0} edits in {1} files");
|
|
40
|
-
})(StandaloneServicesNLS || (StandaloneServicesNLS = {}));
|
|
41
|
-
|
|
42
|
-
export { GoToLineNLS, InspectTokensNLS, QuickCommandNLS, QuickHelpNLS, QuickOutlineNLS, StandaloneCodeEditorNLS, StandaloneServicesNLS, ToggleHighContrastNLS };
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { isHighSurrogate } from '../../../base/common/strings.js';
|
|
2
|
-
import { isLittleEndian } from '../../../base/common/platform.js';
|
|
3
|
-
import { readUInt16LE } from '../../../base/common/buffer.js';
|
|
4
|
-
|
|
5
|
-
/*---------------------------------------------------------------------------------------------
|
|
6
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
7
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
8
|
-
*--------------------------------------------------------------------------------------------*/
|
|
9
|
-
let _utf16LE_TextDecoder;
|
|
10
|
-
function getUTF16LE_TextDecoder() {
|
|
11
|
-
if (!_utf16LE_TextDecoder) {
|
|
12
|
-
_utf16LE_TextDecoder = new TextDecoder('UTF-16LE');
|
|
13
|
-
}
|
|
14
|
-
return _utf16LE_TextDecoder;
|
|
15
|
-
}
|
|
16
|
-
let _utf16BE_TextDecoder;
|
|
17
|
-
function getUTF16BE_TextDecoder() {
|
|
18
|
-
if (!_utf16BE_TextDecoder) {
|
|
19
|
-
_utf16BE_TextDecoder = new TextDecoder('UTF-16BE');
|
|
20
|
-
}
|
|
21
|
-
return _utf16BE_TextDecoder;
|
|
22
|
-
}
|
|
23
|
-
let _platformTextDecoder;
|
|
24
|
-
function getPlatformTextDecoder() {
|
|
25
|
-
if (!_platformTextDecoder) {
|
|
26
|
-
_platformTextDecoder = isLittleEndian() ? getUTF16LE_TextDecoder() : getUTF16BE_TextDecoder();
|
|
27
|
-
}
|
|
28
|
-
return _platformTextDecoder;
|
|
29
|
-
}
|
|
30
|
-
function decodeUTF16LE(source, offset, len) {
|
|
31
|
-
const view = new Uint16Array(source.buffer, offset, len);
|
|
32
|
-
if (len > 0 && (view[0] === 0xFEFF || view[0] === 0xFFFE)) {
|
|
33
|
-
// UTF16 sometimes starts with a BOM https://de.wikipedia.org/wiki/Byte_Order_Mark
|
|
34
|
-
// It looks like TextDecoder.decode will eat up a leading BOM (0xFEFF or 0xFFFE)
|
|
35
|
-
// We don't want that behavior because we know the string is UTF16LE and the BOM should be maintained
|
|
36
|
-
// So we use the manual decoder
|
|
37
|
-
return compatDecodeUTF16LE(source, offset, len);
|
|
38
|
-
}
|
|
39
|
-
return getUTF16LE_TextDecoder().decode(view);
|
|
40
|
-
}
|
|
41
|
-
function compatDecodeUTF16LE(source, offset, len) {
|
|
42
|
-
const result = [];
|
|
43
|
-
let resultLen = 0;
|
|
44
|
-
for (let i = 0; i < len; i++) {
|
|
45
|
-
const charCode = readUInt16LE(source, offset);
|
|
46
|
-
offset += 2;
|
|
47
|
-
result[resultLen++] = String.fromCharCode(charCode);
|
|
48
|
-
}
|
|
49
|
-
return result.join('');
|
|
50
|
-
}
|
|
51
|
-
class StringBuilder {
|
|
52
|
-
constructor(capacity) {
|
|
53
|
-
this._capacity = capacity | 0;
|
|
54
|
-
this._buffer = new Uint16Array(this._capacity);
|
|
55
|
-
this._completedStrings = null;
|
|
56
|
-
this._bufferLength = 0;
|
|
57
|
-
}
|
|
58
|
-
reset() {
|
|
59
|
-
this._completedStrings = null;
|
|
60
|
-
this._bufferLength = 0;
|
|
61
|
-
}
|
|
62
|
-
build() {
|
|
63
|
-
if (this._completedStrings !== null) {
|
|
64
|
-
this._flushBuffer();
|
|
65
|
-
return this._completedStrings.join('');
|
|
66
|
-
}
|
|
67
|
-
return this._buildBuffer();
|
|
68
|
-
}
|
|
69
|
-
_buildBuffer() {
|
|
70
|
-
if (this._bufferLength === 0) {
|
|
71
|
-
return '';
|
|
72
|
-
}
|
|
73
|
-
const view = new Uint16Array(this._buffer.buffer, 0, this._bufferLength);
|
|
74
|
-
return getPlatformTextDecoder().decode(view);
|
|
75
|
-
}
|
|
76
|
-
_flushBuffer() {
|
|
77
|
-
const bufferString = this._buildBuffer();
|
|
78
|
-
this._bufferLength = 0;
|
|
79
|
-
if (this._completedStrings === null) {
|
|
80
|
-
this._completedStrings = [bufferString];
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
this._completedStrings[this._completedStrings.length] = bufferString;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Append a char code (<2^16)
|
|
88
|
-
*/
|
|
89
|
-
appendCharCode(charCode) {
|
|
90
|
-
const remainingSpace = this._capacity - this._bufferLength;
|
|
91
|
-
if (remainingSpace <= 1) {
|
|
92
|
-
if (remainingSpace === 0 || isHighSurrogate(charCode)) {
|
|
93
|
-
this._flushBuffer();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
this._buffer[this._bufferLength++] = charCode;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Append an ASCII char code (<2^8)
|
|
100
|
-
*/
|
|
101
|
-
appendASCIICharCode(charCode) {
|
|
102
|
-
if (this._bufferLength === this._capacity) {
|
|
103
|
-
// buffer is full
|
|
104
|
-
this._flushBuffer();
|
|
105
|
-
}
|
|
106
|
-
this._buffer[this._bufferLength++] = charCode;
|
|
107
|
-
}
|
|
108
|
-
appendString(str) {
|
|
109
|
-
const strLen = str.length;
|
|
110
|
-
if (this._bufferLength + strLen >= this._capacity) {
|
|
111
|
-
// This string does not fit in the remaining buffer space
|
|
112
|
-
this._flushBuffer();
|
|
113
|
-
this._completedStrings[this._completedStrings.length] = str;
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
for (let i = 0; i < strLen; i++) {
|
|
117
|
-
this._buffer[this._bufferLength++] = str.charCodeAt(i);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export { StringBuilder, decodeUTF16LE, getPlatformTextDecoder };
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import { commonPrefixLength, commonSuffixLength } from '../../../../base/common/strings.js';
|
|
2
|
-
import { OffsetRange } from '../ranges/offsetRange.js';
|
|
3
|
-
import { BaseEdit, BaseReplacement } from './edit.js';
|
|
4
|
-
|
|
5
|
-
/*---------------------------------------------------------------------------------------------
|
|
6
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
7
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
8
|
-
*--------------------------------------------------------------------------------------------*/
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
-
class BaseStringEdit extends BaseEdit {
|
|
11
|
-
apply(base) {
|
|
12
|
-
const resultText = [];
|
|
13
|
-
let pos = 0;
|
|
14
|
-
for (const edit of this.replacements) {
|
|
15
|
-
resultText.push(base.substring(pos, edit.replaceRange.start));
|
|
16
|
-
resultText.push(edit.newText);
|
|
17
|
-
pos = edit.replaceRange.endExclusive;
|
|
18
|
-
}
|
|
19
|
-
resultText.push(base.substring(pos));
|
|
20
|
-
return resultText.join('');
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
-
class BaseStringReplacement extends BaseReplacement {
|
|
25
|
-
constructor(range, newText) {
|
|
26
|
-
super(range);
|
|
27
|
-
this.newText = newText;
|
|
28
|
-
}
|
|
29
|
-
getNewLength() { return this.newText.length; }
|
|
30
|
-
toString() {
|
|
31
|
-
return `${this.replaceRange} -> ${JSON.stringify(this.newText)}`;
|
|
32
|
-
}
|
|
33
|
-
replace(str) {
|
|
34
|
-
return str.substring(0, this.replaceRange.start) + this.newText + str.substring(this.replaceRange.endExclusive);
|
|
35
|
-
}
|
|
36
|
-
removeCommonSuffixPrefix(originalText) {
|
|
37
|
-
const oldText = originalText.substring(this.replaceRange.start, this.replaceRange.endExclusive);
|
|
38
|
-
const prefixLen = commonPrefixLength(oldText, this.newText);
|
|
39
|
-
const suffixLen = Math.min(oldText.length - prefixLen, this.newText.length - prefixLen, commonSuffixLength(oldText, this.newText));
|
|
40
|
-
const replaceRange = new OffsetRange(this.replaceRange.start + prefixLen, this.replaceRange.endExclusive - suffixLen);
|
|
41
|
-
const newText = this.newText.substring(prefixLen, this.newText.length - suffixLen);
|
|
42
|
-
return new StringReplacement(replaceRange, newText);
|
|
43
|
-
}
|
|
44
|
-
removeCommonSuffixAndPrefix(source) {
|
|
45
|
-
return this.removeCommonSuffix(source).removeCommonPrefix(source);
|
|
46
|
-
}
|
|
47
|
-
removeCommonPrefix(source) {
|
|
48
|
-
const oldText = this.replaceRange.substring(source);
|
|
49
|
-
const prefixLen = commonPrefixLength(oldText, this.newText);
|
|
50
|
-
if (prefixLen === 0) {
|
|
51
|
-
return this;
|
|
52
|
-
}
|
|
53
|
-
return this.slice(this.replaceRange.deltaStart(prefixLen), new OffsetRange(prefixLen, this.newText.length));
|
|
54
|
-
}
|
|
55
|
-
removeCommonSuffix(source) {
|
|
56
|
-
const oldText = this.replaceRange.substring(source);
|
|
57
|
-
const suffixLen = commonSuffixLength(oldText, this.newText);
|
|
58
|
-
if (suffixLen === 0) {
|
|
59
|
-
return this;
|
|
60
|
-
}
|
|
61
|
-
return this.slice(this.replaceRange.deltaEnd(-suffixLen), new OffsetRange(0, this.newText.length - suffixLen));
|
|
62
|
-
}
|
|
63
|
-
toJson() {
|
|
64
|
-
return ({
|
|
65
|
-
txt: this.newText,
|
|
66
|
-
pos: this.replaceRange.start,
|
|
67
|
-
len: this.replaceRange.length,
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Represents a set of replacements to a string.
|
|
73
|
-
* All these replacements are applied at once.
|
|
74
|
-
*/
|
|
75
|
-
class StringEdit extends BaseStringEdit {
|
|
76
|
-
static { this.empty = new StringEdit([]); }
|
|
77
|
-
static compose(edits) {
|
|
78
|
-
if (edits.length === 0) {
|
|
79
|
-
return StringEdit.empty;
|
|
80
|
-
}
|
|
81
|
-
let result = edits[0];
|
|
82
|
-
for (let i = 1; i < edits.length; i++) {
|
|
83
|
-
result = result.compose(edits[i]);
|
|
84
|
-
}
|
|
85
|
-
return result;
|
|
86
|
-
}
|
|
87
|
-
constructor(replacements) {
|
|
88
|
-
super(replacements);
|
|
89
|
-
}
|
|
90
|
-
_createNew(replacements) {
|
|
91
|
-
return new StringEdit(replacements);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
class StringReplacement extends BaseStringReplacement {
|
|
95
|
-
static insert(offset, text) {
|
|
96
|
-
return new StringReplacement(OffsetRange.emptyAt(offset), text);
|
|
97
|
-
}
|
|
98
|
-
static replace(range, text) {
|
|
99
|
-
return new StringReplacement(range, text);
|
|
100
|
-
}
|
|
101
|
-
equals(other) {
|
|
102
|
-
return this.replaceRange.equals(other.replaceRange) && this.newText === other.newText;
|
|
103
|
-
}
|
|
104
|
-
tryJoinTouching(other) {
|
|
105
|
-
return new StringReplacement(this.replaceRange.joinRightTouching(other.replaceRange), this.newText + other.newText);
|
|
106
|
-
}
|
|
107
|
-
slice(range, rangeInReplacement) {
|
|
108
|
-
return new StringReplacement(range, rangeInReplacement ? rangeInReplacement.substring(this.newText) : this.newText);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
function applyEditsToRanges(sortedRanges, edit) {
|
|
112
|
-
sortedRanges = sortedRanges.slice();
|
|
113
|
-
// treat edits as deletion of the replace range and then as insertion that extends the first range
|
|
114
|
-
const result = [];
|
|
115
|
-
let offset = 0;
|
|
116
|
-
for (const e of edit.replacements) {
|
|
117
|
-
while (true) {
|
|
118
|
-
// ranges before the current edit
|
|
119
|
-
const r = sortedRanges[0];
|
|
120
|
-
if (!r || r.endExclusive >= e.replaceRange.start) {
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
sortedRanges.shift();
|
|
124
|
-
result.push(r.delta(offset));
|
|
125
|
-
}
|
|
126
|
-
const intersecting = [];
|
|
127
|
-
while (true) {
|
|
128
|
-
const r = sortedRanges[0];
|
|
129
|
-
if (!r || !r.intersectsOrTouches(e.replaceRange)) {
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
sortedRanges.shift();
|
|
133
|
-
intersecting.push(r);
|
|
134
|
-
}
|
|
135
|
-
for (let i = intersecting.length - 1; i >= 0; i--) {
|
|
136
|
-
let r = intersecting[i];
|
|
137
|
-
const overlap = r.intersect(e.replaceRange).length;
|
|
138
|
-
r = r.deltaEnd(-overlap + (i === 0 ? e.newText.length : 0));
|
|
139
|
-
const rangeAheadOfReplaceRange = r.start - e.replaceRange.start;
|
|
140
|
-
if (rangeAheadOfReplaceRange > 0) {
|
|
141
|
-
r = r.delta(-rangeAheadOfReplaceRange);
|
|
142
|
-
}
|
|
143
|
-
if (i !== 0) {
|
|
144
|
-
r = r.delta(e.newText.length);
|
|
145
|
-
}
|
|
146
|
-
// We already took our offset into account.
|
|
147
|
-
// Because we add r back to the queue (which then adds offset again),
|
|
148
|
-
// we have to remove it here.
|
|
149
|
-
r = r.delta(-(e.newText.length - e.replaceRange.length));
|
|
150
|
-
sortedRanges.unshift(r);
|
|
151
|
-
}
|
|
152
|
-
offset += e.newText.length - e.replaceRange.length;
|
|
153
|
-
}
|
|
154
|
-
while (true) {
|
|
155
|
-
const r = sortedRanges[0];
|
|
156
|
-
if (!r) {
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
sortedRanges.shift();
|
|
160
|
-
result.push(r.delta(offset));
|
|
161
|
-
}
|
|
162
|
-
return result;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export { BaseStringEdit, BaseStringReplacement, StringEdit, StringReplacement, applyEditsToRanges };
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/*---------------------------------------------------------------------------------------------
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
-
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
function createScopedLineTokens(context, offset) {
|
|
6
|
-
const tokenCount = context.getCount();
|
|
7
|
-
const tokenIndex = context.findTokenIndexAtOffset(offset);
|
|
8
|
-
const desiredLanguageId = context.getLanguageId(tokenIndex);
|
|
9
|
-
let lastTokenIndex = tokenIndex;
|
|
10
|
-
while (lastTokenIndex + 1 < tokenCount && context.getLanguageId(lastTokenIndex + 1) === desiredLanguageId) {
|
|
11
|
-
lastTokenIndex++;
|
|
12
|
-
}
|
|
13
|
-
let firstTokenIndex = tokenIndex;
|
|
14
|
-
while (firstTokenIndex > 0 && context.getLanguageId(firstTokenIndex - 1) === desiredLanguageId) {
|
|
15
|
-
firstTokenIndex--;
|
|
16
|
-
}
|
|
17
|
-
return new ScopedLineTokens(context, desiredLanguageId, firstTokenIndex, lastTokenIndex + 1, context.getStartOffset(firstTokenIndex), context.getEndOffset(lastTokenIndex));
|
|
18
|
-
}
|
|
19
|
-
class ScopedLineTokens {
|
|
20
|
-
constructor(actual, languageId, firstTokenIndex, lastTokenIndex, firstCharOffset, lastCharOffset) {
|
|
21
|
-
this._scopedLineTokensBrand = undefined;
|
|
22
|
-
this._actual = actual;
|
|
23
|
-
this.languageId = languageId;
|
|
24
|
-
this._firstTokenIndex = firstTokenIndex;
|
|
25
|
-
this._lastTokenIndex = lastTokenIndex;
|
|
26
|
-
this.firstCharOffset = firstCharOffset;
|
|
27
|
-
this._lastCharOffset = lastCharOffset;
|
|
28
|
-
this.languageIdCodec = actual.languageIdCodec;
|
|
29
|
-
}
|
|
30
|
-
getLineContent() {
|
|
31
|
-
const actualLineContent = this._actual.getLineContent();
|
|
32
|
-
return actualLineContent.substring(this.firstCharOffset, this._lastCharOffset);
|
|
33
|
-
}
|
|
34
|
-
getLineLength() {
|
|
35
|
-
return this._lastCharOffset - this.firstCharOffset;
|
|
36
|
-
}
|
|
37
|
-
getActualLineContentBefore(offset) {
|
|
38
|
-
const actualLineContent = this._actual.getLineContent();
|
|
39
|
-
return actualLineContent.substring(0, this.firstCharOffset + offset);
|
|
40
|
-
}
|
|
41
|
-
getTokenCount() {
|
|
42
|
-
return this._lastTokenIndex - this._firstTokenIndex;
|
|
43
|
-
}
|
|
44
|
-
findTokenIndexAtOffset(offset) {
|
|
45
|
-
return this._actual.findTokenIndexAtOffset(offset + this.firstCharOffset) - this._firstTokenIndex;
|
|
46
|
-
}
|
|
47
|
-
getStandardTokenType(tokenIndex) {
|
|
48
|
-
return this._actual.getStandardTokenType(tokenIndex + this._firstTokenIndex);
|
|
49
|
-
}
|
|
50
|
-
toIViewLineTokens() {
|
|
51
|
-
return this._actual.sliceAndInflate(this.firstCharOffset, this._lastCharOffset, 0);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
function ignoreBracketsInToken(standardTokenType) {
|
|
55
|
-
return (standardTokenType & 3 /* IgnoreBracketsInTokens.value */) !== 0;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export { ScopedLineTokens, createScopedLineTokens, ignoreBracketsInToken };
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Range } from '../core/range.js';
|
|
2
|
-
import { Selection } from '../core/selection.js';
|
|
3
|
-
|
|
4
|
-
/*---------------------------------------------------------------------------------------------
|
|
5
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
6
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
7
|
-
*--------------------------------------------------------------------------------------------*/
|
|
8
|
-
class SurroundSelectionCommand {
|
|
9
|
-
constructor(range, charBeforeSelection, charAfterSelection) {
|
|
10
|
-
this._range = range;
|
|
11
|
-
this._charBeforeSelection = charBeforeSelection;
|
|
12
|
-
this._charAfterSelection = charAfterSelection;
|
|
13
|
-
}
|
|
14
|
-
getEditOperations(model, builder) {
|
|
15
|
-
builder.addTrackedEditOperation(new Range(this._range.startLineNumber, this._range.startColumn, this._range.startLineNumber, this._range.startColumn), this._charBeforeSelection);
|
|
16
|
-
builder.addTrackedEditOperation(new Range(this._range.endLineNumber, this._range.endColumn, this._range.endLineNumber, this._range.endColumn), this._charAfterSelection || null); // addTrackedEditOperation() ignores us if the text == ''. Causing a chain of errors in computeCursorState()
|
|
17
|
-
}
|
|
18
|
-
computeCursorState(model, helper) {
|
|
19
|
-
const inverseEditOperations = helper.getInverseEditOperations();
|
|
20
|
-
const firstOperationRange = inverseEditOperations[0].range;
|
|
21
|
-
const secondOperationRange = inverseEditOperations[1].range;
|
|
22
|
-
return new Selection(firstOperationRange.endLineNumber, firstOperationRange.endColumn, secondOperationRange.endLineNumber, secondOperationRange.endColumn - this._charAfterSelection.length);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* A surround selection command that runs after composition finished.
|
|
27
|
-
*/
|
|
28
|
-
class CompositionSurroundSelectionCommand {
|
|
29
|
-
constructor(_position, _text, _charAfter) {
|
|
30
|
-
this._position = _position;
|
|
31
|
-
this._text = _text;
|
|
32
|
-
this._charAfter = _charAfter;
|
|
33
|
-
}
|
|
34
|
-
getEditOperations(model, builder) {
|
|
35
|
-
builder.addTrackedEditOperation(new Range(this._position.lineNumber, this._position.column, this._position.lineNumber, this._position.column), this._text + this._charAfter);
|
|
36
|
-
}
|
|
37
|
-
computeCursorState(model, helper) {
|
|
38
|
-
const inverseEditOperations = helper.getInverseEditOperations();
|
|
39
|
-
const opRange = inverseEditOperations[0].range;
|
|
40
|
-
return new Selection(opRange.endLineNumber, opRange.startColumn, opRange.endLineNumber, opRange.endColumn - this._charAfter.length);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export { CompositionSurroundSelectionCommand, SurroundSelectionCommand };
|
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
import { writeUInt32BE, writeUInt16LE, readUInt32BE } from '../../../base/common/buffer.js';
|
|
2
|
-
import { decodeUTF16LE } from './stringBuilder.js';
|
|
3
|
-
|
|
4
|
-
/*---------------------------------------------------------------------------------------------
|
|
5
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
6
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
7
|
-
*--------------------------------------------------------------------------------------------*/
|
|
8
|
-
function escapeNewLine(str) {
|
|
9
|
-
return (str
|
|
10
|
-
.replace(/\n/g, '\\n')
|
|
11
|
-
.replace(/\r/g, '\\r'));
|
|
12
|
-
}
|
|
13
|
-
class TextChange {
|
|
14
|
-
get oldLength() {
|
|
15
|
-
return this.oldText.length;
|
|
16
|
-
}
|
|
17
|
-
get oldEnd() {
|
|
18
|
-
return this.oldPosition + this.oldText.length;
|
|
19
|
-
}
|
|
20
|
-
get newLength() {
|
|
21
|
-
return this.newText.length;
|
|
22
|
-
}
|
|
23
|
-
get newEnd() {
|
|
24
|
-
return this.newPosition + this.newText.length;
|
|
25
|
-
}
|
|
26
|
-
constructor(oldPosition, oldText, newPosition, newText) {
|
|
27
|
-
this.oldPosition = oldPosition;
|
|
28
|
-
this.oldText = oldText;
|
|
29
|
-
this.newPosition = newPosition;
|
|
30
|
-
this.newText = newText;
|
|
31
|
-
}
|
|
32
|
-
toString() {
|
|
33
|
-
if (this.oldText.length === 0) {
|
|
34
|
-
return `(insert@${this.oldPosition} "${escapeNewLine(this.newText)}")`;
|
|
35
|
-
}
|
|
36
|
-
if (this.newText.length === 0) {
|
|
37
|
-
return `(delete@${this.oldPosition} "${escapeNewLine(this.oldText)}")`;
|
|
38
|
-
}
|
|
39
|
-
return `(replace@${this.oldPosition} "${escapeNewLine(this.oldText)}" with "${escapeNewLine(this.newText)}")`;
|
|
40
|
-
}
|
|
41
|
-
static _writeStringSize(str) {
|
|
42
|
-
return (4 + 2 * str.length);
|
|
43
|
-
}
|
|
44
|
-
static _writeString(b, str, offset) {
|
|
45
|
-
const len = str.length;
|
|
46
|
-
writeUInt32BE(b, len, offset);
|
|
47
|
-
offset += 4;
|
|
48
|
-
for (let i = 0; i < len; i++) {
|
|
49
|
-
writeUInt16LE(b, str.charCodeAt(i), offset);
|
|
50
|
-
offset += 2;
|
|
51
|
-
}
|
|
52
|
-
return offset;
|
|
53
|
-
}
|
|
54
|
-
static _readString(b, offset) {
|
|
55
|
-
const len = readUInt32BE(b, offset);
|
|
56
|
-
offset += 4;
|
|
57
|
-
return decodeUTF16LE(b, offset, len);
|
|
58
|
-
}
|
|
59
|
-
writeSize() {
|
|
60
|
-
return (4 // oldPosition
|
|
61
|
-
+ 4 // newPosition
|
|
62
|
-
+ TextChange._writeStringSize(this.oldText)
|
|
63
|
-
+ TextChange._writeStringSize(this.newText));
|
|
64
|
-
}
|
|
65
|
-
write(b, offset) {
|
|
66
|
-
writeUInt32BE(b, this.oldPosition, offset);
|
|
67
|
-
offset += 4;
|
|
68
|
-
writeUInt32BE(b, this.newPosition, offset);
|
|
69
|
-
offset += 4;
|
|
70
|
-
offset = TextChange._writeString(b, this.oldText, offset);
|
|
71
|
-
offset = TextChange._writeString(b, this.newText, offset);
|
|
72
|
-
return offset;
|
|
73
|
-
}
|
|
74
|
-
static read(b, offset, dest) {
|
|
75
|
-
const oldPosition = readUInt32BE(b, offset);
|
|
76
|
-
offset += 4;
|
|
77
|
-
const newPosition = readUInt32BE(b, offset);
|
|
78
|
-
offset += 4;
|
|
79
|
-
const oldText = TextChange._readString(b, offset);
|
|
80
|
-
offset += TextChange._writeStringSize(oldText);
|
|
81
|
-
const newText = TextChange._readString(b, offset);
|
|
82
|
-
offset += TextChange._writeStringSize(newText);
|
|
83
|
-
dest.push(new TextChange(oldPosition, oldText, newPosition, newText));
|
|
84
|
-
return offset;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
function compressConsecutiveTextChanges(prevEdits, currEdits) {
|
|
88
|
-
if (prevEdits === null || prevEdits.length === 0) {
|
|
89
|
-
return currEdits;
|
|
90
|
-
}
|
|
91
|
-
const compressor = new TextChangeCompressor(prevEdits, currEdits);
|
|
92
|
-
return compressor.compress();
|
|
93
|
-
}
|
|
94
|
-
class TextChangeCompressor {
|
|
95
|
-
constructor(prevEdits, currEdits) {
|
|
96
|
-
this._prevEdits = prevEdits;
|
|
97
|
-
this._currEdits = currEdits;
|
|
98
|
-
this._result = [];
|
|
99
|
-
this._resultLen = 0;
|
|
100
|
-
this._prevLen = this._prevEdits.length;
|
|
101
|
-
this._prevDeltaOffset = 0;
|
|
102
|
-
this._currLen = this._currEdits.length;
|
|
103
|
-
this._currDeltaOffset = 0;
|
|
104
|
-
}
|
|
105
|
-
compress() {
|
|
106
|
-
let prevIndex = 0;
|
|
107
|
-
let currIndex = 0;
|
|
108
|
-
let prevEdit = this._getPrev(prevIndex);
|
|
109
|
-
let currEdit = this._getCurr(currIndex);
|
|
110
|
-
while (prevIndex < this._prevLen || currIndex < this._currLen) {
|
|
111
|
-
if (prevEdit === null) {
|
|
112
|
-
this._acceptCurr(currEdit);
|
|
113
|
-
currEdit = this._getCurr(++currIndex);
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
if (currEdit === null) {
|
|
117
|
-
this._acceptPrev(prevEdit);
|
|
118
|
-
prevEdit = this._getPrev(++prevIndex);
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
if (currEdit.oldEnd <= prevEdit.newPosition) {
|
|
122
|
-
this._acceptCurr(currEdit);
|
|
123
|
-
currEdit = this._getCurr(++currIndex);
|
|
124
|
-
continue;
|
|
125
|
-
}
|
|
126
|
-
if (prevEdit.newEnd <= currEdit.oldPosition) {
|
|
127
|
-
this._acceptPrev(prevEdit);
|
|
128
|
-
prevEdit = this._getPrev(++prevIndex);
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
if (currEdit.oldPosition < prevEdit.newPosition) {
|
|
132
|
-
const [e1, e2] = TextChangeCompressor._splitCurr(currEdit, prevEdit.newPosition - currEdit.oldPosition);
|
|
133
|
-
this._acceptCurr(e1);
|
|
134
|
-
currEdit = e2;
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
if (prevEdit.newPosition < currEdit.oldPosition) {
|
|
138
|
-
const [e1, e2] = TextChangeCompressor._splitPrev(prevEdit, currEdit.oldPosition - prevEdit.newPosition);
|
|
139
|
-
this._acceptPrev(e1);
|
|
140
|
-
prevEdit = e2;
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
// At this point, currEdit.oldPosition === prevEdit.newPosition
|
|
144
|
-
let mergePrev;
|
|
145
|
-
let mergeCurr;
|
|
146
|
-
if (currEdit.oldEnd === prevEdit.newEnd) {
|
|
147
|
-
mergePrev = prevEdit;
|
|
148
|
-
mergeCurr = currEdit;
|
|
149
|
-
prevEdit = this._getPrev(++prevIndex);
|
|
150
|
-
currEdit = this._getCurr(++currIndex);
|
|
151
|
-
}
|
|
152
|
-
else if (currEdit.oldEnd < prevEdit.newEnd) {
|
|
153
|
-
const [e1, e2] = TextChangeCompressor._splitPrev(prevEdit, currEdit.oldLength);
|
|
154
|
-
mergePrev = e1;
|
|
155
|
-
mergeCurr = currEdit;
|
|
156
|
-
prevEdit = e2;
|
|
157
|
-
currEdit = this._getCurr(++currIndex);
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
const [e1, e2] = TextChangeCompressor._splitCurr(currEdit, prevEdit.newLength);
|
|
161
|
-
mergePrev = prevEdit;
|
|
162
|
-
mergeCurr = e1;
|
|
163
|
-
prevEdit = this._getPrev(++prevIndex);
|
|
164
|
-
currEdit = e2;
|
|
165
|
-
}
|
|
166
|
-
this._result[this._resultLen++] = new TextChange(mergePrev.oldPosition, mergePrev.oldText, mergeCurr.newPosition, mergeCurr.newText);
|
|
167
|
-
this._prevDeltaOffset += mergePrev.newLength - mergePrev.oldLength;
|
|
168
|
-
this._currDeltaOffset += mergeCurr.newLength - mergeCurr.oldLength;
|
|
169
|
-
}
|
|
170
|
-
const merged = TextChangeCompressor._merge(this._result);
|
|
171
|
-
const cleaned = TextChangeCompressor._removeNoOps(merged);
|
|
172
|
-
return cleaned;
|
|
173
|
-
}
|
|
174
|
-
_acceptCurr(currEdit) {
|
|
175
|
-
this._result[this._resultLen++] = TextChangeCompressor._rebaseCurr(this._prevDeltaOffset, currEdit);
|
|
176
|
-
this._currDeltaOffset += currEdit.newLength - currEdit.oldLength;
|
|
177
|
-
}
|
|
178
|
-
_getCurr(currIndex) {
|
|
179
|
-
return (currIndex < this._currLen ? this._currEdits[currIndex] : null);
|
|
180
|
-
}
|
|
181
|
-
_acceptPrev(prevEdit) {
|
|
182
|
-
this._result[this._resultLen++] = TextChangeCompressor._rebasePrev(this._currDeltaOffset, prevEdit);
|
|
183
|
-
this._prevDeltaOffset += prevEdit.newLength - prevEdit.oldLength;
|
|
184
|
-
}
|
|
185
|
-
_getPrev(prevIndex) {
|
|
186
|
-
return (prevIndex < this._prevLen ? this._prevEdits[prevIndex] : null);
|
|
187
|
-
}
|
|
188
|
-
static _rebaseCurr(prevDeltaOffset, currEdit) {
|
|
189
|
-
return new TextChange(currEdit.oldPosition - prevDeltaOffset, currEdit.oldText, currEdit.newPosition, currEdit.newText);
|
|
190
|
-
}
|
|
191
|
-
static _rebasePrev(currDeltaOffset, prevEdit) {
|
|
192
|
-
return new TextChange(prevEdit.oldPosition, prevEdit.oldText, prevEdit.newPosition + currDeltaOffset, prevEdit.newText);
|
|
193
|
-
}
|
|
194
|
-
static _splitPrev(edit, offset) {
|
|
195
|
-
const preText = edit.newText.substr(0, offset);
|
|
196
|
-
const postText = edit.newText.substr(offset);
|
|
197
|
-
return [
|
|
198
|
-
new TextChange(edit.oldPosition, edit.oldText, edit.newPosition, preText),
|
|
199
|
-
new TextChange(edit.oldEnd, '', edit.newPosition + offset, postText)
|
|
200
|
-
];
|
|
201
|
-
}
|
|
202
|
-
static _splitCurr(edit, offset) {
|
|
203
|
-
const preText = edit.oldText.substr(0, offset);
|
|
204
|
-
const postText = edit.oldText.substr(offset);
|
|
205
|
-
return [
|
|
206
|
-
new TextChange(edit.oldPosition, preText, edit.newPosition, edit.newText),
|
|
207
|
-
new TextChange(edit.oldPosition + offset, postText, edit.newEnd, '')
|
|
208
|
-
];
|
|
209
|
-
}
|
|
210
|
-
static _merge(edits) {
|
|
211
|
-
if (edits.length === 0) {
|
|
212
|
-
return edits;
|
|
213
|
-
}
|
|
214
|
-
const result = [];
|
|
215
|
-
let resultLen = 0;
|
|
216
|
-
let prev = edits[0];
|
|
217
|
-
for (let i = 1; i < edits.length; i++) {
|
|
218
|
-
const curr = edits[i];
|
|
219
|
-
if (prev.oldEnd === curr.oldPosition) {
|
|
220
|
-
// Merge into `prev`
|
|
221
|
-
prev = new TextChange(prev.oldPosition, prev.oldText + curr.oldText, prev.newPosition, prev.newText + curr.newText);
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
result[resultLen++] = prev;
|
|
225
|
-
prev = curr;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
result[resultLen++] = prev;
|
|
229
|
-
return result;
|
|
230
|
-
}
|
|
231
|
-
static _removeNoOps(edits) {
|
|
232
|
-
if (edits.length === 0) {
|
|
233
|
-
return edits;
|
|
234
|
-
}
|
|
235
|
-
const result = [];
|
|
236
|
-
let resultLen = 0;
|
|
237
|
-
for (let i = 0; i < edits.length; i++) {
|
|
238
|
-
const edit = edits[i];
|
|
239
|
-
if (edit.oldText === edit.newText) {
|
|
240
|
-
continue;
|
|
241
|
-
}
|
|
242
|
-
result[resultLen++] = edit;
|
|
243
|
-
}
|
|
244
|
-
return result;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
export { TextChange, compressConsecutiveTextChanges };
|