monaco-editor11 1.0.9 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/monaco-editor11.es.js +12 -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,269 +0,0 @@
|
|
|
1
|
-
import { compareBy } from '../../../../base/common/arrays.js';
|
|
2
|
-
import { assertFn, checkAdjacentItems } from '../../../../base/common/assert.js';
|
|
3
|
-
import { BugIndicatingError } from '../../../../base/common/errors.js';
|
|
4
|
-
import { commonPrefixLength, commonSuffixLength } from '../../../../base/common/strings.js';
|
|
5
|
-
import { Position } from '../position.js';
|
|
6
|
-
import { Range } from '../range.js';
|
|
7
|
-
import { TextLength } from '../text/textLength.js';
|
|
8
|
-
import { StringText } from '../text/abstractText.js';
|
|
9
|
-
|
|
10
|
-
/*---------------------------------------------------------------------------------------------
|
|
11
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
12
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
13
|
-
*--------------------------------------------------------------------------------------------*/
|
|
14
|
-
class TextEdit {
|
|
15
|
-
static fromStringEdit(edit, initialState) {
|
|
16
|
-
const edits = edit.replacements.map(e => TextReplacement.fromStringReplacement(e, initialState));
|
|
17
|
-
return new TextEdit(edits);
|
|
18
|
-
}
|
|
19
|
-
static fromParallelReplacementsUnsorted(replacements) {
|
|
20
|
-
const r = replacements.slice().sort(compareBy(i => i.range, Range.compareRangesUsingStarts));
|
|
21
|
-
return new TextEdit(r);
|
|
22
|
-
}
|
|
23
|
-
constructor(replacements) {
|
|
24
|
-
this.replacements = replacements;
|
|
25
|
-
assertFn(() => checkAdjacentItems(replacements, (a, b) => a.range.getEndPosition().isBeforeOrEqual(b.range.getStartPosition())));
|
|
26
|
-
}
|
|
27
|
-
mapPosition(position) {
|
|
28
|
-
let lineDelta = 0;
|
|
29
|
-
let curLine = 0;
|
|
30
|
-
let columnDeltaInCurLine = 0;
|
|
31
|
-
for (const replacement of this.replacements) {
|
|
32
|
-
const start = replacement.range.getStartPosition();
|
|
33
|
-
if (position.isBeforeOrEqual(start)) {
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
const end = replacement.range.getEndPosition();
|
|
37
|
-
const len = TextLength.ofText(replacement.text);
|
|
38
|
-
if (position.isBefore(end)) {
|
|
39
|
-
const startPos = new Position(start.lineNumber + lineDelta, start.column + (start.lineNumber + lineDelta === curLine ? columnDeltaInCurLine : 0));
|
|
40
|
-
const endPos = len.addToPosition(startPos);
|
|
41
|
-
return rangeFromPositions(startPos, endPos);
|
|
42
|
-
}
|
|
43
|
-
if (start.lineNumber + lineDelta !== curLine) {
|
|
44
|
-
columnDeltaInCurLine = 0;
|
|
45
|
-
}
|
|
46
|
-
lineDelta += len.lineCount - (replacement.range.endLineNumber - replacement.range.startLineNumber);
|
|
47
|
-
if (len.lineCount === 0) {
|
|
48
|
-
if (end.lineNumber !== start.lineNumber) {
|
|
49
|
-
columnDeltaInCurLine += len.columnCount - (end.column - 1);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
columnDeltaInCurLine += len.columnCount - (end.column - start.column);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
columnDeltaInCurLine = len.columnCount;
|
|
57
|
-
}
|
|
58
|
-
curLine = end.lineNumber + lineDelta;
|
|
59
|
-
}
|
|
60
|
-
return new Position(position.lineNumber + lineDelta, position.column + (position.lineNumber + lineDelta === curLine ? columnDeltaInCurLine : 0));
|
|
61
|
-
}
|
|
62
|
-
mapRange(range) {
|
|
63
|
-
function getStart(p) {
|
|
64
|
-
return p instanceof Position ? p : p.getStartPosition();
|
|
65
|
-
}
|
|
66
|
-
function getEnd(p) {
|
|
67
|
-
return p instanceof Position ? p : p.getEndPosition();
|
|
68
|
-
}
|
|
69
|
-
const start = getStart(this.mapPosition(range.getStartPosition()));
|
|
70
|
-
const end = getEnd(this.mapPosition(range.getEndPosition()));
|
|
71
|
-
return rangeFromPositions(start, end);
|
|
72
|
-
}
|
|
73
|
-
apply(text) {
|
|
74
|
-
let result = '';
|
|
75
|
-
let lastEditEnd = new Position(1, 1);
|
|
76
|
-
for (const replacement of this.replacements) {
|
|
77
|
-
const editRange = replacement.range;
|
|
78
|
-
const editStart = editRange.getStartPosition();
|
|
79
|
-
const editEnd = editRange.getEndPosition();
|
|
80
|
-
const r = rangeFromPositions(lastEditEnd, editStart);
|
|
81
|
-
if (!r.isEmpty()) {
|
|
82
|
-
result += text.getValueOfRange(r);
|
|
83
|
-
}
|
|
84
|
-
result += replacement.text;
|
|
85
|
-
lastEditEnd = editEnd;
|
|
86
|
-
}
|
|
87
|
-
const r = rangeFromPositions(lastEditEnd, text.endPositionExclusive);
|
|
88
|
-
if (!r.isEmpty()) {
|
|
89
|
-
result += text.getValueOfRange(r);
|
|
90
|
-
}
|
|
91
|
-
return result;
|
|
92
|
-
}
|
|
93
|
-
applyToString(str) {
|
|
94
|
-
const strText = new StringText(str);
|
|
95
|
-
return this.apply(strText);
|
|
96
|
-
}
|
|
97
|
-
getNewRanges() {
|
|
98
|
-
const newRanges = [];
|
|
99
|
-
let previousEditEndLineNumber = 0;
|
|
100
|
-
let lineOffset = 0;
|
|
101
|
-
let columnOffset = 0;
|
|
102
|
-
for (const replacement of this.replacements) {
|
|
103
|
-
const textLength = TextLength.ofText(replacement.text);
|
|
104
|
-
const newRangeStart = Position.lift({
|
|
105
|
-
lineNumber: replacement.range.startLineNumber + lineOffset,
|
|
106
|
-
column: replacement.range.startColumn + (replacement.range.startLineNumber === previousEditEndLineNumber ? columnOffset : 0)
|
|
107
|
-
});
|
|
108
|
-
const newRange = textLength.createRange(newRangeStart);
|
|
109
|
-
newRanges.push(newRange);
|
|
110
|
-
lineOffset = newRange.endLineNumber - replacement.range.endLineNumber;
|
|
111
|
-
columnOffset = newRange.endColumn - replacement.range.endColumn;
|
|
112
|
-
previousEditEndLineNumber = replacement.range.endLineNumber;
|
|
113
|
-
}
|
|
114
|
-
return newRanges;
|
|
115
|
-
}
|
|
116
|
-
toReplacement(text) {
|
|
117
|
-
if (this.replacements.length === 0) {
|
|
118
|
-
throw new BugIndicatingError();
|
|
119
|
-
}
|
|
120
|
-
if (this.replacements.length === 1) {
|
|
121
|
-
return this.replacements[0];
|
|
122
|
-
}
|
|
123
|
-
const startPos = this.replacements[0].range.getStartPosition();
|
|
124
|
-
const endPos = this.replacements[this.replacements.length - 1].range.getEndPosition();
|
|
125
|
-
let newText = '';
|
|
126
|
-
for (let i = 0; i < this.replacements.length; i++) {
|
|
127
|
-
const curEdit = this.replacements[i];
|
|
128
|
-
newText += curEdit.text;
|
|
129
|
-
if (i < this.replacements.length - 1) {
|
|
130
|
-
const nextEdit = this.replacements[i + 1];
|
|
131
|
-
const gapRange = Range.fromPositions(curEdit.range.getEndPosition(), nextEdit.range.getStartPosition());
|
|
132
|
-
const gapText = text.getValueOfRange(gapRange);
|
|
133
|
-
newText += gapText;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return new TextReplacement(Range.fromPositions(startPos, endPos), newText);
|
|
137
|
-
}
|
|
138
|
-
toString(text) {
|
|
139
|
-
if (text === undefined) {
|
|
140
|
-
return this.replacements.map(edit => edit.toString()).join('\n');
|
|
141
|
-
}
|
|
142
|
-
if (typeof text === 'string') {
|
|
143
|
-
return this.toString(new StringText(text));
|
|
144
|
-
}
|
|
145
|
-
if (this.replacements.length === 0) {
|
|
146
|
-
return '';
|
|
147
|
-
}
|
|
148
|
-
return this.replacements.map(r => {
|
|
149
|
-
const maxLength = 10;
|
|
150
|
-
const originalText = text.getValueOfRange(r.range);
|
|
151
|
-
// Get text before the edit
|
|
152
|
-
const beforeRange = Range.fromPositions(new Position(Math.max(1, r.range.startLineNumber - 1), 1), r.range.getStartPosition());
|
|
153
|
-
let beforeText = text.getValueOfRange(beforeRange);
|
|
154
|
-
if (beforeText.length > maxLength) {
|
|
155
|
-
beforeText = '...' + beforeText.substring(beforeText.length - maxLength);
|
|
156
|
-
}
|
|
157
|
-
// Get text after the edit
|
|
158
|
-
const afterRange = Range.fromPositions(r.range.getEndPosition(), new Position(r.range.endLineNumber + 1, 1));
|
|
159
|
-
let afterText = text.getValueOfRange(afterRange);
|
|
160
|
-
if (afterText.length > maxLength) {
|
|
161
|
-
afterText = afterText.substring(0, maxLength) + '...';
|
|
162
|
-
}
|
|
163
|
-
// Format the replaced text
|
|
164
|
-
let replacedText = originalText;
|
|
165
|
-
if (replacedText.length > maxLength) {
|
|
166
|
-
const halfMax = Math.floor(maxLength / 2);
|
|
167
|
-
replacedText = replacedText.substring(0, halfMax) + '...' +
|
|
168
|
-
replacedText.substring(replacedText.length - halfMax);
|
|
169
|
-
}
|
|
170
|
-
// Format the new text
|
|
171
|
-
let newText = r.text;
|
|
172
|
-
if (newText.length > maxLength) {
|
|
173
|
-
const halfMax = Math.floor(maxLength / 2);
|
|
174
|
-
newText = newText.substring(0, halfMax) + '...' +
|
|
175
|
-
newText.substring(newText.length - halfMax);
|
|
176
|
-
}
|
|
177
|
-
if (replacedText.length === 0) {
|
|
178
|
-
// allow-any-unicode-next-line
|
|
179
|
-
return `${beforeText}❰${newText}❱${afterText}`;
|
|
180
|
-
}
|
|
181
|
-
// allow-any-unicode-next-line
|
|
182
|
-
return `${beforeText}❰${replacedText}↦${newText}❱${afterText}`;
|
|
183
|
-
}).join('\n');
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
class TextReplacement {
|
|
187
|
-
static joinReplacements(replacements, initialValue) {
|
|
188
|
-
if (replacements.length === 0) {
|
|
189
|
-
throw new BugIndicatingError();
|
|
190
|
-
}
|
|
191
|
-
if (replacements.length === 1) {
|
|
192
|
-
return replacements[0];
|
|
193
|
-
}
|
|
194
|
-
const startPos = replacements[0].range.getStartPosition();
|
|
195
|
-
const endPos = replacements[replacements.length - 1].range.getEndPosition();
|
|
196
|
-
let newText = '';
|
|
197
|
-
for (let i = 0; i < replacements.length; i++) {
|
|
198
|
-
const curEdit = replacements[i];
|
|
199
|
-
newText += curEdit.text;
|
|
200
|
-
if (i < replacements.length - 1) {
|
|
201
|
-
const nextEdit = replacements[i + 1];
|
|
202
|
-
const gapRange = Range.fromPositions(curEdit.range.getEndPosition(), nextEdit.range.getStartPosition());
|
|
203
|
-
const gapText = initialValue.getValueOfRange(gapRange);
|
|
204
|
-
newText += gapText;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
return new TextReplacement(Range.fromPositions(startPos, endPos), newText);
|
|
208
|
-
}
|
|
209
|
-
static fromStringReplacement(replacement, initialState) {
|
|
210
|
-
return new TextReplacement(initialState.getTransformer().getRange(replacement.replaceRange), replacement.newText);
|
|
211
|
-
}
|
|
212
|
-
static delete(range) {
|
|
213
|
-
return new TextReplacement(range, '');
|
|
214
|
-
}
|
|
215
|
-
constructor(range, text) {
|
|
216
|
-
this.range = range;
|
|
217
|
-
this.text = text;
|
|
218
|
-
}
|
|
219
|
-
get isEmpty() {
|
|
220
|
-
return this.range.isEmpty() && this.text.length === 0;
|
|
221
|
-
}
|
|
222
|
-
static equals(first, second) {
|
|
223
|
-
return first.range.equalsRange(second.range) && first.text === second.text;
|
|
224
|
-
}
|
|
225
|
-
equals(other) {
|
|
226
|
-
return TextReplacement.equals(this, other);
|
|
227
|
-
}
|
|
228
|
-
removeCommonPrefixAndSuffix(text) {
|
|
229
|
-
const prefix = this.removeCommonPrefix(text);
|
|
230
|
-
const suffix = prefix.removeCommonSuffix(text);
|
|
231
|
-
return suffix;
|
|
232
|
-
}
|
|
233
|
-
removeCommonPrefix(text) {
|
|
234
|
-
const normalizedOriginalText = text.getValueOfRange(this.range).replaceAll('\r\n', '\n');
|
|
235
|
-
const normalizedModifiedText = this.text.replaceAll('\r\n', '\n');
|
|
236
|
-
const commonPrefixLen = commonPrefixLength(normalizedOriginalText, normalizedModifiedText);
|
|
237
|
-
const start = TextLength.ofText(normalizedOriginalText.substring(0, commonPrefixLen))
|
|
238
|
-
.addToPosition(this.range.getStartPosition());
|
|
239
|
-
const newText = normalizedModifiedText.substring(commonPrefixLen);
|
|
240
|
-
const range = Range.fromPositions(start, this.range.getEndPosition());
|
|
241
|
-
return new TextReplacement(range, newText);
|
|
242
|
-
}
|
|
243
|
-
removeCommonSuffix(text) {
|
|
244
|
-
const normalizedOriginalText = text.getValueOfRange(this.range).replaceAll('\r\n', '\n');
|
|
245
|
-
const normalizedModifiedText = this.text.replaceAll('\r\n', '\n');
|
|
246
|
-
const commonSuffixLen = commonSuffixLength(normalizedOriginalText, normalizedModifiedText);
|
|
247
|
-
const end = TextLength.ofText(normalizedOriginalText.substring(0, normalizedOriginalText.length - commonSuffixLen))
|
|
248
|
-
.addToPosition(this.range.getStartPosition());
|
|
249
|
-
const newText = normalizedModifiedText.substring(0, normalizedModifiedText.length - commonSuffixLen);
|
|
250
|
-
const range = Range.fromPositions(this.range.getStartPosition(), end);
|
|
251
|
-
return new TextReplacement(range, newText);
|
|
252
|
-
}
|
|
253
|
-
toString() {
|
|
254
|
-
const start = this.range.getStartPosition();
|
|
255
|
-
const end = this.range.getEndPosition();
|
|
256
|
-
return `(${start.lineNumber},${start.column} -> ${end.lineNumber},${end.column}): "${this.text}"`;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
function rangeFromPositions(start, end) {
|
|
260
|
-
if (start.lineNumber === end.lineNumber && start.column === Number.MAX_SAFE_INTEGER) {
|
|
261
|
-
return Range.fromPositions(end, end);
|
|
262
|
-
}
|
|
263
|
-
else if (!start.isBeforeOrEqual(end)) {
|
|
264
|
-
throw new BugIndicatingError('start must be before end');
|
|
265
|
-
}
|
|
266
|
-
return new Range(start.lineNumber, start.column, end.lineNumber, end.column);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
export { TextEdit, TextReplacement };
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { LineRange } from '../ranges/lineRange.js';
|
|
2
|
-
import { Position } from '../position.js';
|
|
3
|
-
import { Range } from '../range.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
|
-
/**
|
|
10
|
-
* Represents a non-negative length of text in terms of line and column count.
|
|
11
|
-
*/
|
|
12
|
-
class TextLength {
|
|
13
|
-
static { this.zero = new TextLength(0, 0); }
|
|
14
|
-
static betweenPositions(position1, position2) {
|
|
15
|
-
if (position1.lineNumber === position2.lineNumber) {
|
|
16
|
-
return new TextLength(0, position2.column - position1.column);
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
return new TextLength(position2.lineNumber - position1.lineNumber, position2.column - 1);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
static fromPosition(pos) {
|
|
23
|
-
return new TextLength(pos.lineNumber - 1, pos.column - 1);
|
|
24
|
-
}
|
|
25
|
-
static ofRange(range) {
|
|
26
|
-
return TextLength.betweenPositions(range.getStartPosition(), range.getEndPosition());
|
|
27
|
-
}
|
|
28
|
-
static ofText(text) {
|
|
29
|
-
let line = 0;
|
|
30
|
-
let column = 0;
|
|
31
|
-
for (const c of text) {
|
|
32
|
-
if (c === '\n') {
|
|
33
|
-
line++;
|
|
34
|
-
column = 0;
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
column++;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return new TextLength(line, column);
|
|
41
|
-
}
|
|
42
|
-
constructor(lineCount, columnCount) {
|
|
43
|
-
this.lineCount = lineCount;
|
|
44
|
-
this.columnCount = columnCount;
|
|
45
|
-
}
|
|
46
|
-
isGreaterThanOrEqualTo(other) {
|
|
47
|
-
if (this.lineCount !== other.lineCount) {
|
|
48
|
-
return this.lineCount > other.lineCount;
|
|
49
|
-
}
|
|
50
|
-
return this.columnCount >= other.columnCount;
|
|
51
|
-
}
|
|
52
|
-
add(other) {
|
|
53
|
-
if (other.lineCount === 0) {
|
|
54
|
-
return new TextLength(this.lineCount, this.columnCount + other.columnCount);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
return new TextLength(this.lineCount + other.lineCount, other.columnCount);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
createRange(startPosition) {
|
|
61
|
-
if (this.lineCount === 0) {
|
|
62
|
-
return new Range(startPosition.lineNumber, startPosition.column, startPosition.lineNumber, startPosition.column + this.columnCount);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
return new Range(startPosition.lineNumber, startPosition.column, startPosition.lineNumber + this.lineCount, this.columnCount + 1);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
toRange() {
|
|
69
|
-
return new Range(1, 1, this.lineCount + 1, this.columnCount + 1);
|
|
70
|
-
}
|
|
71
|
-
toLineRange() {
|
|
72
|
-
return LineRange.ofLength(1, this.lineCount + 1);
|
|
73
|
-
}
|
|
74
|
-
addToPosition(position) {
|
|
75
|
-
if (this.lineCount === 0) {
|
|
76
|
-
return new Position(position.lineNumber, position.column + this.columnCount);
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
return new Position(position.lineNumber + this.lineCount, this.columnCount + 1);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
toString() {
|
|
83
|
-
return `${this.lineCount},${this.columnCount}`;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export { TextLength };
|