monaco-editor11 1.0.7 → 1.0.9
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/assets/css.worker-C7FogG4G.js +93 -0
- package/dist/assets/editor.worker-iXcRX1Tq.js +26 -0
- package/dist/assets/html.worker-C8VxctEJ.js +470 -0
- package/dist/assets/json.worker-CMC9kgPL.js +58 -0
- package/dist/assets/ts.worker-CtTJ3hNN.js +67731 -0
- package/dist/index.d.ts +0 -6
- package/dist/monaco-editor11.es.js +49 -78
- package/dist/monaco-editor11.umd.js +1 -50
- package/dist/monaco.d.ts +8 -0
- package/dist/workers/common/initialize.js +16 -0
- package/dist/workers/common/workers.js +141 -0
- package/dist/workers/editor/common/abstractSyntaxTokenBackend.js +128 -0
- package/dist/workers/editor/common/abstractText.js +89 -0
- package/dist/workers/editor/common/ast.js +485 -0
- package/dist/workers/editor/common/autoIndent.js +390 -0
- package/dist/workers/editor/common/beforeEditPositionMapper.js +110 -0
- package/dist/workers/editor/common/bracketPairsImpl.js +717 -0
- package/dist/workers/editor/common/bracketPairsTree.js +343 -0
- package/dist/workers/editor/common/brackets.js +108 -0
- package/dist/workers/editor/common/characterClassifier.js +59 -0
- package/dist/workers/editor/common/characterPair.js +40 -0
- package/dist/workers/editor/common/colorizedBracketPairsDecorationProvider.js +97 -0
- package/dist/workers/editor/common/columnRange.js +35 -0
- package/dist/workers/editor/common/combineTextEditInfos.js +124 -0
- package/dist/workers/editor/common/common.js +20 -0
- package/dist/workers/editor/common/computeMovedLines.js +249 -0
- package/dist/workers/editor/common/concat23Trees.js +192 -0
- package/dist/workers/editor/common/contiguousMultilineTokens.js +32 -0
- package/dist/workers/editor/common/contiguousMultilineTokensBuilder.js +23 -0
- package/dist/workers/editor/common/contiguousTokensEditing.js +128 -0
- package/dist/workers/editor/common/contiguousTokensStore.js +207 -0
- package/dist/workers/editor/common/coordinatesConverter.js +51 -0
- package/dist/workers/editor/common/cursor.js +899 -0
- package/dist/workers/editor/common/cursorAtomicMoveOperations.js +145 -0
- package/dist/workers/editor/common/cursorCollection.js +194 -0
- package/dist/workers/editor/common/cursorColumnSelection.js +93 -0
- package/dist/workers/editor/common/cursorColumns.js +112 -0
- package/dist/workers/editor/common/cursorCommon.js +250 -0
- package/dist/workers/editor/common/cursorContext.js +15 -0
- package/dist/workers/editor/common/cursorDeleteOperations.js +231 -0
- package/dist/workers/editor/common/cursorMoveCommands.js +676 -0
- package/dist/workers/editor/common/cursorMoveOperations.js +290 -0
- package/dist/workers/editor/common/cursorTypeEditOperations.js +968 -0
- package/dist/workers/editor/common/cursorTypeOperations.js +173 -0
- package/dist/workers/editor/common/cursorUtils.js +75 -0
- package/dist/workers/editor/common/cursorWordOperations.js +720 -0
- package/dist/workers/editor/common/defaultDocumentColorsComputer.js +138 -0
- package/dist/workers/editor/common/defaultLinesDiffComputer.js +188 -0
- package/dist/workers/editor/common/diffAlgorithm.js +139 -0
- package/dist/workers/editor/common/diffEditor.js +38 -0
- package/dist/workers/editor/common/dynamicProgrammingDiffing.js +101 -0
- package/dist/workers/editor/common/edit.js +183 -0
- package/dist/workers/editor/common/editOperation.js +36 -0
- package/dist/workers/editor/common/editStack.js +363 -0
- package/dist/workers/editor/common/editorAction.js +26 -0
- package/dist/workers/editor/common/editorBaseApi.js +43 -0
- package/dist/workers/editor/common/editorColorRegistry.js +102 -0
- package/dist/workers/editor/common/editorCommon.js +13 -0
- package/dist/workers/editor/common/editorConfigurationSchema.js +338 -0
- package/dist/workers/editor/common/editorContextKeys.js +84 -0
- package/dist/workers/editor/common/editorFeatures.js +17 -0
- package/dist/workers/editor/common/editorOptions.js +3440 -0
- package/dist/workers/editor/common/editorTheme.js +23 -0
- package/dist/workers/editor/common/editorWebWorker.js +299 -0
- package/dist/workers/editor/common/editorWorker.js +9 -0
- package/dist/workers/editor/common/editorWorkerHost.js +15 -0
- package/dist/workers/editor/common/editorZoom.js +26 -0
- package/dist/workers/editor/common/electricCharacter.js +55 -0
- package/dist/workers/editor/common/encodedTokenAttributes.js +79 -0
- package/dist/workers/editor/common/enterAction.js +53 -0
- package/dist/workers/editor/common/eolCounter.js +44 -0
- package/dist/workers/editor/common/findSectionHeaders.js +128 -0
- package/dist/workers/editor/common/fixBrackets.js +67 -0
- package/dist/workers/editor/common/fixedArray.js +70 -0
- package/dist/workers/editor/common/fontInfo.js +172 -0
- package/dist/workers/editor/common/fontInfoFromSettings.js +29 -0
- package/dist/workers/editor/common/getIconClasses.js +106 -0
- package/dist/workers/editor/common/getPositionOffsetTransformerFromTextModel.js +24 -0
- package/dist/workers/editor/common/glyphLanesModel.js +61 -0
- package/dist/workers/editor/common/guidesTextModelPart.js +405 -0
- package/dist/workers/editor/common/heuristicSequenceOptimizations.js +374 -0
- package/dist/workers/editor/common/indentRules.js +63 -0
- package/dist/workers/editor/common/indentation.js +39 -0
- package/dist/workers/editor/common/indentationGuesser.js +178 -0
- package/dist/workers/editor/common/indentationLineProcessor.js +193 -0
- package/dist/workers/editor/common/inlineDecorations.js +26 -0
- package/dist/workers/editor/common/inplaceReplaceSupport.js +87 -0
- package/dist/workers/editor/common/inputMode.js +22 -0
- package/dist/workers/editor/common/intervalTree.js +1002 -0
- package/dist/workers/editor/common/language.js +9 -0
- package/dist/workers/editor/common/languageBracketsConfiguration.js +133 -0
- package/dist/workers/editor/common/languageConfiguration.js +138 -0
- package/dist/workers/editor/common/languageConfigurationRegistry.js +361 -0
- package/dist/workers/editor/common/languageFeatureDebounce.js +137 -0
- package/dist/workers/editor/common/languageFeatureRegistry.js +180 -0
- package/dist/workers/editor/common/languageFeatures.js +9 -0
- package/dist/workers/editor/common/languageFeaturesService.js +47 -0
- package/dist/workers/editor/common/languageSelector.js +112 -0
- package/dist/workers/editor/common/languageService.js +92 -0
- package/dist/workers/editor/common/languages.js +522 -0
- package/dist/workers/editor/common/languagesAssociations.js +193 -0
- package/dist/workers/editor/common/languagesRegistry.js +237 -0
- package/dist/workers/editor/common/legacyLinesDiffComputer.js +468 -0
- package/dist/workers/editor/common/length.js +129 -0
- package/dist/workers/editor/common/lineDecorations.js +208 -0
- package/dist/workers/editor/common/lineEdit.js +75 -0
- package/dist/workers/editor/common/lineHeights.js +370 -0
- package/dist/workers/editor/common/linePart.js +25 -0
- package/dist/workers/editor/common/lineRange.js +312 -0
- package/dist/workers/editor/common/lineSequence.js +36 -0
- package/dist/workers/editor/common/lineTokens.js +405 -0
- package/dist/workers/editor/common/linesDiffComputer.js +29 -0
- package/dist/workers/editor/common/linesDiffComputers.js +13 -0
- package/dist/workers/editor/common/linesLayout.js +765 -0
- package/dist/workers/editor/common/linesSliceCharSequence.js +205 -0
- package/dist/workers/editor/common/linkComputer.js +269 -0
- package/dist/workers/editor/common/markerDecorations.js +9 -0
- package/dist/workers/editor/common/markerDecorationsService.js +248 -0
- package/dist/workers/editor/common/minimapTokensColorTracker.js +58 -0
- package/dist/workers/editor/common/mirrorTextModel.js +117 -0
- package/dist/workers/editor/common/model.js +9 -0
- package/dist/workers/editor/common/modelLineProjection.js +350 -0
- package/dist/workers/editor/common/modelLineProjectionData.js +297 -0
- package/dist/workers/editor/common/modelService.js +413 -0
- package/dist/workers/editor/common/modesRegistry.js +75 -0
- package/dist/workers/editor/common/monospaceLineBreaksComputer.js +473 -0
- package/dist/workers/editor/common/myersDiffAlgorithm.js +159 -0
- package/dist/workers/editor/common/nodeReader.js +127 -0
- package/dist/workers/editor/common/nullTokenize.js +29 -0
- package/dist/workers/editor/common/offsetRange.js +225 -0
- package/dist/workers/editor/common/onEnter.js +109 -0
- package/dist/workers/editor/common/oneCursor.js +117 -0
- package/dist/workers/editor/common/overviewZoneManager.js +176 -0
- package/dist/workers/editor/common/parser.js +121 -0
- package/dist/workers/editor/common/pieceTreeBase.js +1473 -0
- package/dist/workers/editor/common/pieceTreeTextBuffer.js +461 -0
- package/dist/workers/editor/common/pieceTreeTextBufferBuilder.js +140 -0
- package/dist/workers/editor/common/point.js +50 -0
- package/dist/workers/editor/common/position.js +142 -0
- package/dist/workers/editor/common/positionToOffset.js +17 -0
- package/dist/workers/editor/common/positionToOffsetImpl.js +98 -0
- package/dist/workers/editor/common/prefixSumComputer.js +226 -0
- package/dist/workers/editor/common/range.js +421 -0
- package/dist/workers/editor/common/rangeMapping.js +229 -0
- package/dist/workers/editor/common/rangeSingleLine.js +17 -0
- package/dist/workers/editor/common/rbTreeBase.js +362 -0
- package/dist/workers/editor/common/rect.js +163 -0
- package/dist/workers/editor/common/replaceCommand.js +158 -0
- package/dist/workers/editor/common/resolverService.js +5 -0
- package/dist/workers/editor/common/rgba.js +35 -0
- package/dist/workers/editor/common/richEditBrackets.js +356 -0
- package/dist/workers/editor/common/selection.js +145 -0
- package/dist/workers/editor/common/semanticTokensDto.js +82 -0
- package/dist/workers/editor/common/semanticTokensProviderStyling.js +263 -0
- package/dist/workers/editor/common/semanticTokensStyling.js +9 -0
- package/dist/workers/editor/common/semanticTokensStylingService.js +47 -0
- package/dist/workers/editor/common/shiftCommand.js +241 -0
- package/dist/workers/editor/common/smallImmutableSet.js +108 -0
- package/dist/workers/editor/common/sparseMultilineTokens.js +548 -0
- package/dist/workers/editor/common/sparseTokensStore.js +210 -0
- package/dist/workers/editor/common/standaloneEnums.js +1017 -0
- package/dist/workers/editor/common/standaloneStrings.js +42 -0
- package/dist/workers/editor/common/stringBuilder.js +122 -0
- package/dist/workers/editor/common/stringEdit.js +165 -0
- package/dist/workers/editor/common/supports.js +58 -0
- package/dist/workers/editor/common/surroundSelectionCommand.js +44 -0
- package/dist/workers/editor/common/textChange.js +248 -0
- package/dist/workers/editor/common/textEdit.js +269 -0
- package/dist/workers/editor/common/textLength.js +87 -0
- package/dist/workers/editor/common/textModel.js +2031 -0
- package/dist/workers/editor/common/textModelBracketPairs.js +45 -0
- package/dist/workers/editor/common/textModelDefaults.js +18 -0
- package/dist/workers/editor/common/textModelEditSource.js +166 -0
- package/dist/workers/editor/common/textModelEvents.js +216 -0
- package/dist/workers/editor/common/textModelGuides.js +40 -0
- package/dist/workers/editor/common/textModelPart.js +23 -0
- package/dist/workers/editor/common/textModelSearch.js +455 -0
- package/dist/workers/editor/common/textModelStringEdit.js +11 -0
- package/dist/workers/editor/common/textModelSync.impl.js +307 -0
- package/dist/workers/editor/common/textModelText.js +26 -0
- package/dist/workers/editor/common/textModelTokens.js +436 -0
- package/dist/workers/editor/common/textResourceConfiguration.js +6 -0
- package/dist/workers/editor/common/textToHtmlTokenizer.js +139 -0
- package/dist/workers/editor/common/tokenStore.js +407 -0
- package/dist/workers/editor/common/tokenWithTextArray.js +73 -0
- package/dist/workers/editor/common/tokenization.js +287 -0
- package/dist/workers/editor/common/tokenizationRegistry.js +123 -0
- package/dist/workers/editor/common/tokenizationTextModelPart.js +275 -0
- package/dist/workers/editor/common/tokenizer.js +301 -0
- package/dist/workers/editor/common/tokenizerSyntaxTokenBackend.js +261 -0
- package/dist/workers/editor/common/treeSitterLibraryService.js +9 -0
- package/dist/workers/editor/common/treeSitterSyntaxTokenBackend.js +167 -0
- package/dist/workers/editor/common/treeSitterThemeService.js +9 -0
- package/dist/workers/editor/common/treeSitterTokenizationImpl.js +713 -0
- package/dist/workers/editor/common/treeSitterTree.js +395 -0
- package/dist/workers/editor/common/treeViewsDnd.js +24 -0
- package/dist/workers/editor/common/treeViewsDndService.js +12 -0
- package/dist/workers/editor/common/trimTrailingWhitespaceCommand.js +98 -0
- package/dist/workers/editor/common/unicodeTextModelHighlighter.js +188 -0
- package/dist/workers/editor/common/utils.js +62 -0
- package/dist/workers/editor/common/viewContext.js +22 -0
- package/dist/workers/editor/common/viewEventHandler.js +186 -0
- package/dist/workers/editor/common/viewEvents.js +180 -0
- package/dist/workers/editor/common/viewLayout.js +368 -0
- package/dist/workers/editor/common/viewLineRenderer.js +948 -0
- package/dist/workers/editor/common/viewLinesViewportData.js +30 -0
- package/dist/workers/editor/common/viewModel.js +98 -0
- package/dist/workers/editor/common/viewModelDecoration.js +55 -0
- package/dist/workers/editor/common/viewModelDecorations.js +132 -0
- package/dist/workers/editor/common/viewModelEventDispatcher.js +398 -0
- package/dist/workers/editor/common/viewModelImpl.js +1163 -0
- package/dist/workers/editor/common/viewModelLines.js +938 -0
- package/dist/workers/editor/common/wordCharacterClassifier.js +87 -0
- package/dist/workers/editor/common/wordHelper.js +127 -0
- package/dist/workers/editor/editor.worker.js +11 -0
- package/dist/workers/language/css.worker.js +8 -0
- package/dist/workers/language/cssMode.js +198 -0
- package/dist/workers/language/cssWorker.js +183 -0
- package/dist/workers/language/html.worker.js +8 -0
- package/dist/workers/language/htmlMode.js +213 -0
- package/dist/workers/language/htmlWorker.js +126 -0
- package/dist/workers/language/json.worker.js +8 -0
- package/dist/workers/language/jsonMode.js +224 -0
- package/dist/workers/language/jsonWorker.js +187 -0
- package/dist/workers/language/languageFeatures.js +1009 -0
- package/dist/workers/language/lib.index.js +103 -0
- package/dist/workers/language/lib.js +1107 -0
- package/dist/workers/language/lspLanguageFeatures.js +716 -0
- package/dist/workers/language/monaco.contribution.js +144 -0
- package/dist/workers/language/tokenization.js +189 -0
- package/dist/workers/language/ts.worker.js +14 -0
- package/dist/workers/language/tsMode.js +212 -0
- package/dist/workers/language/tsWorker.js +352 -0
- package/dist/workers/language/typescriptServices.js +210154 -0
- package/dist/workers/language/typescriptServicesMetadata.js +3 -0
- package/dist/workers/language/workerManager.js +65 -0
- package/package.json +3 -2
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
import { Emitter } from '../../../../base/common/event.js';
|
|
2
|
+
import { isHighSurrogate, firstNonWhitespaceIndex, lastNonWhitespaceIndex, isBasicASCII, containsRTL, containsUnusualLineTerminators } from '../../../../base/common/strings.js';
|
|
3
|
+
import { Range } from '../../core/range.js';
|
|
4
|
+
import { ApplyEditsResult } from '../../model.js';
|
|
5
|
+
import { PieceTreeBase } from './pieceTreeBase.js';
|
|
6
|
+
import { countEOL } from '../../core/misc/eolCounter.js';
|
|
7
|
+
import { TextChange } from '../../core/textChange.js';
|
|
8
|
+
import { Disposable } from '../../../../base/common/lifecycle.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 PieceTreeTextBuffer extends Disposable {
|
|
15
|
+
constructor(chunks, BOM, eol, containsRTL, containsUnusualLineTerminators, isBasicASCII, eolNormalized) {
|
|
16
|
+
super();
|
|
17
|
+
this._onDidChangeContent = this._register(new Emitter());
|
|
18
|
+
this._BOM = BOM;
|
|
19
|
+
this._mightContainNonBasicASCII = !isBasicASCII;
|
|
20
|
+
this._mightContainRTL = containsRTL;
|
|
21
|
+
this._mightContainUnusualLineTerminators = containsUnusualLineTerminators;
|
|
22
|
+
this._pieceTree = new PieceTreeBase(chunks, eol, eolNormalized);
|
|
23
|
+
}
|
|
24
|
+
mightContainRTL() {
|
|
25
|
+
return this._mightContainRTL;
|
|
26
|
+
}
|
|
27
|
+
mightContainUnusualLineTerminators() {
|
|
28
|
+
return this._mightContainUnusualLineTerminators;
|
|
29
|
+
}
|
|
30
|
+
resetMightContainUnusualLineTerminators() {
|
|
31
|
+
this._mightContainUnusualLineTerminators = false;
|
|
32
|
+
}
|
|
33
|
+
mightContainNonBasicASCII() {
|
|
34
|
+
return this._mightContainNonBasicASCII;
|
|
35
|
+
}
|
|
36
|
+
getBOM() {
|
|
37
|
+
return this._BOM;
|
|
38
|
+
}
|
|
39
|
+
getEOL() {
|
|
40
|
+
return this._pieceTree.getEOL();
|
|
41
|
+
}
|
|
42
|
+
createSnapshot(preserveBOM) {
|
|
43
|
+
return this._pieceTree.createSnapshot(preserveBOM ? this._BOM : '');
|
|
44
|
+
}
|
|
45
|
+
getOffsetAt(lineNumber, column) {
|
|
46
|
+
return this._pieceTree.getOffsetAt(lineNumber, column);
|
|
47
|
+
}
|
|
48
|
+
getPositionAt(offset) {
|
|
49
|
+
return this._pieceTree.getPositionAt(offset);
|
|
50
|
+
}
|
|
51
|
+
getRangeAt(start, length) {
|
|
52
|
+
const end = start + length;
|
|
53
|
+
const startPosition = this.getPositionAt(start);
|
|
54
|
+
const endPosition = this.getPositionAt(end);
|
|
55
|
+
return new Range(startPosition.lineNumber, startPosition.column, endPosition.lineNumber, endPosition.column);
|
|
56
|
+
}
|
|
57
|
+
getValueInRange(range, eol = 0 /* EndOfLinePreference.TextDefined */) {
|
|
58
|
+
if (range.isEmpty()) {
|
|
59
|
+
return '';
|
|
60
|
+
}
|
|
61
|
+
const lineEnding = this._getEndOfLine(eol);
|
|
62
|
+
return this._pieceTree.getValueInRange(range, lineEnding);
|
|
63
|
+
}
|
|
64
|
+
getValueLengthInRange(range, eol = 0 /* EndOfLinePreference.TextDefined */) {
|
|
65
|
+
if (range.isEmpty()) {
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
68
|
+
if (range.startLineNumber === range.endLineNumber) {
|
|
69
|
+
return (range.endColumn - range.startColumn);
|
|
70
|
+
}
|
|
71
|
+
const startOffset = this.getOffsetAt(range.startLineNumber, range.startColumn);
|
|
72
|
+
const endOffset = this.getOffsetAt(range.endLineNumber, range.endColumn);
|
|
73
|
+
// offsets use the text EOL, so we need to compensate for length differences
|
|
74
|
+
// if the requested EOL doesn't match the text EOL
|
|
75
|
+
let eolOffsetCompensation = 0;
|
|
76
|
+
const desiredEOL = this._getEndOfLine(eol);
|
|
77
|
+
const actualEOL = this.getEOL();
|
|
78
|
+
if (desiredEOL.length !== actualEOL.length) {
|
|
79
|
+
const delta = desiredEOL.length - actualEOL.length;
|
|
80
|
+
const eolCount = range.endLineNumber - range.startLineNumber;
|
|
81
|
+
eolOffsetCompensation = delta * eolCount;
|
|
82
|
+
}
|
|
83
|
+
return endOffset - startOffset + eolOffsetCompensation;
|
|
84
|
+
}
|
|
85
|
+
getCharacterCountInRange(range, eol = 0 /* EndOfLinePreference.TextDefined */) {
|
|
86
|
+
if (this._mightContainNonBasicASCII) {
|
|
87
|
+
// we must count by iterating
|
|
88
|
+
let result = 0;
|
|
89
|
+
const fromLineNumber = range.startLineNumber;
|
|
90
|
+
const toLineNumber = range.endLineNumber;
|
|
91
|
+
for (let lineNumber = fromLineNumber; lineNumber <= toLineNumber; lineNumber++) {
|
|
92
|
+
const lineContent = this.getLineContent(lineNumber);
|
|
93
|
+
const fromOffset = (lineNumber === fromLineNumber ? range.startColumn - 1 : 0);
|
|
94
|
+
const toOffset = (lineNumber === toLineNumber ? range.endColumn - 1 : lineContent.length);
|
|
95
|
+
for (let offset = fromOffset; offset < toOffset; offset++) {
|
|
96
|
+
if (isHighSurrogate(lineContent.charCodeAt(offset))) {
|
|
97
|
+
result = result + 1;
|
|
98
|
+
offset = offset + 1;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
result = result + 1;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
result += this._getEndOfLine(eol).length * (toLineNumber - fromLineNumber);
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
return this.getValueLengthInRange(range, eol);
|
|
109
|
+
}
|
|
110
|
+
getNearestChunk(offset) {
|
|
111
|
+
return this._pieceTree.getNearestChunk(offset);
|
|
112
|
+
}
|
|
113
|
+
getLength() {
|
|
114
|
+
return this._pieceTree.getLength();
|
|
115
|
+
}
|
|
116
|
+
getLineCount() {
|
|
117
|
+
return this._pieceTree.getLineCount();
|
|
118
|
+
}
|
|
119
|
+
getLinesContent() {
|
|
120
|
+
return this._pieceTree.getLinesContent();
|
|
121
|
+
}
|
|
122
|
+
getLineContent(lineNumber) {
|
|
123
|
+
return this._pieceTree.getLineContent(lineNumber);
|
|
124
|
+
}
|
|
125
|
+
getLineCharCode(lineNumber, index) {
|
|
126
|
+
return this._pieceTree.getLineCharCode(lineNumber, index);
|
|
127
|
+
}
|
|
128
|
+
getLineLength(lineNumber) {
|
|
129
|
+
return this._pieceTree.getLineLength(lineNumber);
|
|
130
|
+
}
|
|
131
|
+
getLineFirstNonWhitespaceColumn(lineNumber) {
|
|
132
|
+
const result = firstNonWhitespaceIndex(this.getLineContent(lineNumber));
|
|
133
|
+
if (result === -1) {
|
|
134
|
+
return 0;
|
|
135
|
+
}
|
|
136
|
+
return result + 1;
|
|
137
|
+
}
|
|
138
|
+
getLineLastNonWhitespaceColumn(lineNumber) {
|
|
139
|
+
const result = lastNonWhitespaceIndex(this.getLineContent(lineNumber));
|
|
140
|
+
if (result === -1) {
|
|
141
|
+
return 0;
|
|
142
|
+
}
|
|
143
|
+
return result + 2;
|
|
144
|
+
}
|
|
145
|
+
_getEndOfLine(eol) {
|
|
146
|
+
switch (eol) {
|
|
147
|
+
case 1 /* EndOfLinePreference.LF */:
|
|
148
|
+
return '\n';
|
|
149
|
+
case 2 /* EndOfLinePreference.CRLF */:
|
|
150
|
+
return '\r\n';
|
|
151
|
+
case 0 /* EndOfLinePreference.TextDefined */:
|
|
152
|
+
return this.getEOL();
|
|
153
|
+
default:
|
|
154
|
+
throw new Error('Unknown EOL preference');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
setEOL(newEOL) {
|
|
158
|
+
this._pieceTree.setEOL(newEOL);
|
|
159
|
+
}
|
|
160
|
+
applyEdits(rawOperations, recordTrimAutoWhitespace, computeUndoEdits) {
|
|
161
|
+
let mightContainRTL = this._mightContainRTL;
|
|
162
|
+
let mightContainUnusualLineTerminators = this._mightContainUnusualLineTerminators;
|
|
163
|
+
let mightContainNonBasicASCII = this._mightContainNonBasicASCII;
|
|
164
|
+
let canReduceOperations = true;
|
|
165
|
+
let operations = [];
|
|
166
|
+
for (let i = 0; i < rawOperations.length; i++) {
|
|
167
|
+
const op = rawOperations[i];
|
|
168
|
+
if (canReduceOperations && op._isTracked) {
|
|
169
|
+
canReduceOperations = false;
|
|
170
|
+
}
|
|
171
|
+
const validatedRange = op.range;
|
|
172
|
+
if (op.text) {
|
|
173
|
+
let textMightContainNonBasicASCII = true;
|
|
174
|
+
if (!mightContainNonBasicASCII) {
|
|
175
|
+
textMightContainNonBasicASCII = !isBasicASCII(op.text);
|
|
176
|
+
mightContainNonBasicASCII = textMightContainNonBasicASCII;
|
|
177
|
+
}
|
|
178
|
+
if (!mightContainRTL && textMightContainNonBasicASCII) {
|
|
179
|
+
// check if the new inserted text contains RTL
|
|
180
|
+
mightContainRTL = containsRTL(op.text);
|
|
181
|
+
}
|
|
182
|
+
if (!mightContainUnusualLineTerminators && textMightContainNonBasicASCII) {
|
|
183
|
+
// check if the new inserted text contains unusual line terminators
|
|
184
|
+
mightContainUnusualLineTerminators = containsUnusualLineTerminators(op.text);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
let validText = '';
|
|
188
|
+
let eolCount = 0;
|
|
189
|
+
let firstLineLength = 0;
|
|
190
|
+
let lastLineLength = 0;
|
|
191
|
+
if (op.text) {
|
|
192
|
+
let strEOL;
|
|
193
|
+
[eolCount, firstLineLength, lastLineLength, strEOL] = countEOL(op.text);
|
|
194
|
+
const bufferEOL = this.getEOL();
|
|
195
|
+
const expectedStrEOL = (bufferEOL === '\r\n' ? 2 /* StringEOL.CRLF */ : 1 /* StringEOL.LF */);
|
|
196
|
+
if (strEOL === 0 /* StringEOL.Unknown */ || strEOL === expectedStrEOL) {
|
|
197
|
+
validText = op.text;
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
validText = op.text.replace(/\r\n|\r|\n/g, bufferEOL);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
operations[i] = {
|
|
204
|
+
sortIndex: i,
|
|
205
|
+
identifier: op.identifier || null,
|
|
206
|
+
range: validatedRange,
|
|
207
|
+
rangeOffset: this.getOffsetAt(validatedRange.startLineNumber, validatedRange.startColumn),
|
|
208
|
+
rangeLength: this.getValueLengthInRange(validatedRange),
|
|
209
|
+
text: validText,
|
|
210
|
+
eolCount: eolCount,
|
|
211
|
+
firstLineLength: firstLineLength,
|
|
212
|
+
lastLineLength: lastLineLength,
|
|
213
|
+
forceMoveMarkers: Boolean(op.forceMoveMarkers),
|
|
214
|
+
isAutoWhitespaceEdit: op.isAutoWhitespaceEdit || false
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
// Sort operations ascending
|
|
218
|
+
operations.sort(PieceTreeTextBuffer._sortOpsAscending);
|
|
219
|
+
let hasTouchingRanges = false;
|
|
220
|
+
for (let i = 0, count = operations.length - 1; i < count; i++) {
|
|
221
|
+
const rangeEnd = operations[i].range.getEndPosition();
|
|
222
|
+
const nextRangeStart = operations[i + 1].range.getStartPosition();
|
|
223
|
+
if (nextRangeStart.isBeforeOrEqual(rangeEnd)) {
|
|
224
|
+
if (nextRangeStart.isBefore(rangeEnd)) {
|
|
225
|
+
// overlapping ranges
|
|
226
|
+
throw new Error('Overlapping ranges are not allowed!');
|
|
227
|
+
}
|
|
228
|
+
hasTouchingRanges = true;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (canReduceOperations) {
|
|
232
|
+
operations = this._reduceOperations(operations);
|
|
233
|
+
}
|
|
234
|
+
// Delta encode operations
|
|
235
|
+
const reverseRanges = (computeUndoEdits || recordTrimAutoWhitespace ? PieceTreeTextBuffer._getInverseEditRanges(operations) : []);
|
|
236
|
+
const newTrimAutoWhitespaceCandidates = [];
|
|
237
|
+
if (recordTrimAutoWhitespace) {
|
|
238
|
+
for (let i = 0; i < operations.length; i++) {
|
|
239
|
+
const op = operations[i];
|
|
240
|
+
const reverseRange = reverseRanges[i];
|
|
241
|
+
if (op.isAutoWhitespaceEdit && op.range.isEmpty()) {
|
|
242
|
+
// Record already the future line numbers that might be auto whitespace removal candidates on next edit
|
|
243
|
+
for (let lineNumber = reverseRange.startLineNumber; lineNumber <= reverseRange.endLineNumber; lineNumber++) {
|
|
244
|
+
let currentLineContent = '';
|
|
245
|
+
if (lineNumber === reverseRange.startLineNumber) {
|
|
246
|
+
currentLineContent = this.getLineContent(op.range.startLineNumber);
|
|
247
|
+
if (firstNonWhitespaceIndex(currentLineContent) !== -1) {
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
newTrimAutoWhitespaceCandidates.push({ lineNumber: lineNumber, oldContent: currentLineContent });
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
let reverseOperations = null;
|
|
257
|
+
if (computeUndoEdits) {
|
|
258
|
+
let reverseRangeDeltaOffset = 0;
|
|
259
|
+
reverseOperations = [];
|
|
260
|
+
for (let i = 0; i < operations.length; i++) {
|
|
261
|
+
const op = operations[i];
|
|
262
|
+
const reverseRange = reverseRanges[i];
|
|
263
|
+
const bufferText = this.getValueInRange(op.range);
|
|
264
|
+
const reverseRangeOffset = op.rangeOffset + reverseRangeDeltaOffset;
|
|
265
|
+
reverseRangeDeltaOffset += (op.text.length - bufferText.length);
|
|
266
|
+
reverseOperations[i] = {
|
|
267
|
+
sortIndex: op.sortIndex,
|
|
268
|
+
identifier: op.identifier,
|
|
269
|
+
range: reverseRange,
|
|
270
|
+
text: bufferText,
|
|
271
|
+
textChange: new TextChange(op.rangeOffset, bufferText, reverseRangeOffset, op.text)
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
// Can only sort reverse operations when the order is not significant
|
|
275
|
+
if (!hasTouchingRanges) {
|
|
276
|
+
reverseOperations.sort((a, b) => a.sortIndex - b.sortIndex);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
this._mightContainRTL = mightContainRTL;
|
|
280
|
+
this._mightContainUnusualLineTerminators = mightContainUnusualLineTerminators;
|
|
281
|
+
this._mightContainNonBasicASCII = mightContainNonBasicASCII;
|
|
282
|
+
const contentChanges = this._doApplyEdits(operations);
|
|
283
|
+
let trimAutoWhitespaceLineNumbers = null;
|
|
284
|
+
if (recordTrimAutoWhitespace && newTrimAutoWhitespaceCandidates.length > 0) {
|
|
285
|
+
// sort line numbers auto whitespace removal candidates for next edit descending
|
|
286
|
+
newTrimAutoWhitespaceCandidates.sort((a, b) => b.lineNumber - a.lineNumber);
|
|
287
|
+
trimAutoWhitespaceLineNumbers = [];
|
|
288
|
+
for (let i = 0, len = newTrimAutoWhitespaceCandidates.length; i < len; i++) {
|
|
289
|
+
const lineNumber = newTrimAutoWhitespaceCandidates[i].lineNumber;
|
|
290
|
+
if (i > 0 && newTrimAutoWhitespaceCandidates[i - 1].lineNumber === lineNumber) {
|
|
291
|
+
// Do not have the same line number twice
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
const prevContent = newTrimAutoWhitespaceCandidates[i].oldContent;
|
|
295
|
+
const lineContent = this.getLineContent(lineNumber);
|
|
296
|
+
if (lineContent.length === 0 || lineContent === prevContent || firstNonWhitespaceIndex(lineContent) !== -1) {
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
trimAutoWhitespaceLineNumbers.push(lineNumber);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
this._onDidChangeContent.fire();
|
|
303
|
+
return new ApplyEditsResult(reverseOperations, contentChanges, trimAutoWhitespaceLineNumbers);
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Transform operations such that they represent the same logic edit,
|
|
307
|
+
* but that they also do not cause OOM crashes.
|
|
308
|
+
*/
|
|
309
|
+
_reduceOperations(operations) {
|
|
310
|
+
if (operations.length < 1000) {
|
|
311
|
+
// We know from empirical testing that a thousand edits work fine regardless of their shape.
|
|
312
|
+
return operations;
|
|
313
|
+
}
|
|
314
|
+
// At one point, due to how events are emitted and how each operation is handled,
|
|
315
|
+
// some operations can trigger a high amount of temporary string allocations,
|
|
316
|
+
// that will immediately get edited again.
|
|
317
|
+
// e.g. a formatter inserting ridiculous ammounts of \n on a model with a single line
|
|
318
|
+
// Therefore, the strategy is to collapse all the operations into a huge single edit operation
|
|
319
|
+
return [this._toSingleEditOperation(operations)];
|
|
320
|
+
}
|
|
321
|
+
_toSingleEditOperation(operations) {
|
|
322
|
+
let forceMoveMarkers = false;
|
|
323
|
+
const firstEditRange = operations[0].range;
|
|
324
|
+
const lastEditRange = operations[operations.length - 1].range;
|
|
325
|
+
const entireEditRange = new Range(firstEditRange.startLineNumber, firstEditRange.startColumn, lastEditRange.endLineNumber, lastEditRange.endColumn);
|
|
326
|
+
let lastEndLineNumber = firstEditRange.startLineNumber;
|
|
327
|
+
let lastEndColumn = firstEditRange.startColumn;
|
|
328
|
+
const result = [];
|
|
329
|
+
for (let i = 0, len = operations.length; i < len; i++) {
|
|
330
|
+
const operation = operations[i];
|
|
331
|
+
const range = operation.range;
|
|
332
|
+
forceMoveMarkers = forceMoveMarkers || operation.forceMoveMarkers;
|
|
333
|
+
// (1) -- Push old text
|
|
334
|
+
result.push(this.getValueInRange(new Range(lastEndLineNumber, lastEndColumn, range.startLineNumber, range.startColumn)));
|
|
335
|
+
// (2) -- Push new text
|
|
336
|
+
if (operation.text.length > 0) {
|
|
337
|
+
result.push(operation.text);
|
|
338
|
+
}
|
|
339
|
+
lastEndLineNumber = range.endLineNumber;
|
|
340
|
+
lastEndColumn = range.endColumn;
|
|
341
|
+
}
|
|
342
|
+
const text = result.join('');
|
|
343
|
+
const [eolCount, firstLineLength, lastLineLength] = countEOL(text);
|
|
344
|
+
return {
|
|
345
|
+
sortIndex: 0,
|
|
346
|
+
identifier: operations[0].identifier,
|
|
347
|
+
range: entireEditRange,
|
|
348
|
+
rangeOffset: this.getOffsetAt(entireEditRange.startLineNumber, entireEditRange.startColumn),
|
|
349
|
+
rangeLength: this.getValueLengthInRange(entireEditRange, 0 /* EndOfLinePreference.TextDefined */),
|
|
350
|
+
text: text,
|
|
351
|
+
eolCount: eolCount,
|
|
352
|
+
firstLineLength: firstLineLength,
|
|
353
|
+
lastLineLength: lastLineLength,
|
|
354
|
+
forceMoveMarkers: forceMoveMarkers,
|
|
355
|
+
isAutoWhitespaceEdit: false
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
_doApplyEdits(operations) {
|
|
359
|
+
operations.sort(PieceTreeTextBuffer._sortOpsDescending);
|
|
360
|
+
const contentChanges = [];
|
|
361
|
+
// operations are from bottom to top
|
|
362
|
+
for (let i = 0; i < operations.length; i++) {
|
|
363
|
+
const op = operations[i];
|
|
364
|
+
const startLineNumber = op.range.startLineNumber;
|
|
365
|
+
const startColumn = op.range.startColumn;
|
|
366
|
+
const endLineNumber = op.range.endLineNumber;
|
|
367
|
+
const endColumn = op.range.endColumn;
|
|
368
|
+
if (startLineNumber === endLineNumber && startColumn === endColumn && op.text.length === 0) {
|
|
369
|
+
// no-op
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
if (op.text) {
|
|
373
|
+
// replacement
|
|
374
|
+
this._pieceTree.delete(op.rangeOffset, op.rangeLength);
|
|
375
|
+
this._pieceTree.insert(op.rangeOffset, op.text, true);
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
// deletion
|
|
379
|
+
this._pieceTree.delete(op.rangeOffset, op.rangeLength);
|
|
380
|
+
}
|
|
381
|
+
const contentChangeRange = new Range(startLineNumber, startColumn, endLineNumber, endColumn);
|
|
382
|
+
contentChanges.push({
|
|
383
|
+
range: contentChangeRange,
|
|
384
|
+
rangeLength: op.rangeLength,
|
|
385
|
+
text: op.text,
|
|
386
|
+
rangeOffset: op.rangeOffset,
|
|
387
|
+
forceMoveMarkers: op.forceMoveMarkers
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
return contentChanges;
|
|
391
|
+
}
|
|
392
|
+
findMatchesLineByLine(searchRange, searchData, captureMatches, limitResultCount) {
|
|
393
|
+
return this._pieceTree.findMatchesLineByLine(searchRange, searchData, captureMatches, limitResultCount);
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Assumes `operations` are validated and sorted ascending
|
|
397
|
+
*/
|
|
398
|
+
static _getInverseEditRanges(operations) {
|
|
399
|
+
const result = [];
|
|
400
|
+
let prevOpEndLineNumber = 0;
|
|
401
|
+
let prevOpEndColumn = 0;
|
|
402
|
+
let prevOp = null;
|
|
403
|
+
for (let i = 0, len = operations.length; i < len; i++) {
|
|
404
|
+
const op = operations[i];
|
|
405
|
+
let startLineNumber;
|
|
406
|
+
let startColumn;
|
|
407
|
+
if (prevOp) {
|
|
408
|
+
if (prevOp.range.endLineNumber === op.range.startLineNumber) {
|
|
409
|
+
startLineNumber = prevOpEndLineNumber;
|
|
410
|
+
startColumn = prevOpEndColumn + (op.range.startColumn - prevOp.range.endColumn);
|
|
411
|
+
}
|
|
412
|
+
else {
|
|
413
|
+
startLineNumber = prevOpEndLineNumber + (op.range.startLineNumber - prevOp.range.endLineNumber);
|
|
414
|
+
startColumn = op.range.startColumn;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
startLineNumber = op.range.startLineNumber;
|
|
419
|
+
startColumn = op.range.startColumn;
|
|
420
|
+
}
|
|
421
|
+
let resultRange;
|
|
422
|
+
if (op.text.length > 0) {
|
|
423
|
+
// the operation inserts something
|
|
424
|
+
const lineCount = op.eolCount + 1;
|
|
425
|
+
if (lineCount === 1) {
|
|
426
|
+
// single line insert
|
|
427
|
+
resultRange = new Range(startLineNumber, startColumn, startLineNumber, startColumn + op.firstLineLength);
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
// multi line insert
|
|
431
|
+
resultRange = new Range(startLineNumber, startColumn, startLineNumber + lineCount - 1, op.lastLineLength + 1);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
else {
|
|
435
|
+
// There is nothing to insert
|
|
436
|
+
resultRange = new Range(startLineNumber, startColumn, startLineNumber, startColumn);
|
|
437
|
+
}
|
|
438
|
+
prevOpEndLineNumber = resultRange.endLineNumber;
|
|
439
|
+
prevOpEndColumn = resultRange.endColumn;
|
|
440
|
+
result.push(resultRange);
|
|
441
|
+
prevOp = op;
|
|
442
|
+
}
|
|
443
|
+
return result;
|
|
444
|
+
}
|
|
445
|
+
static _sortOpsAscending(a, b) {
|
|
446
|
+
const r = Range.compareRangesUsingEnds(a.range, b.range);
|
|
447
|
+
if (r === 0) {
|
|
448
|
+
return a.sortIndex - b.sortIndex;
|
|
449
|
+
}
|
|
450
|
+
return r;
|
|
451
|
+
}
|
|
452
|
+
static _sortOpsDescending(a, b) {
|
|
453
|
+
const r = Range.compareRangesUsingEnds(a.range, b.range);
|
|
454
|
+
if (r === 0) {
|
|
455
|
+
return b.sortIndex - a.sortIndex;
|
|
456
|
+
}
|
|
457
|
+
return -r;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
export { PieceTreeTextBuffer };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { startsWithUTF8BOM, UTF8_BOM_CHARACTER, containsRTL, containsUnusualLineTerminators } from '../../../../base/common/strings.js';
|
|
2
|
+
import { createLineStarts, StringBuffer, createLineStartsFast } from './pieceTreeBase.js';
|
|
3
|
+
import { PieceTreeTextBuffer } from './pieceTreeTextBuffer.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
|
+
class PieceTreeTextBufferFactory {
|
|
10
|
+
constructor(_chunks, _bom, _cr, _lf, _crlf, _containsRTL, _containsUnusualLineTerminators, _isBasicASCII, _normalizeEOL) {
|
|
11
|
+
this._chunks = _chunks;
|
|
12
|
+
this._bom = _bom;
|
|
13
|
+
this._cr = _cr;
|
|
14
|
+
this._lf = _lf;
|
|
15
|
+
this._crlf = _crlf;
|
|
16
|
+
this._containsRTL = _containsRTL;
|
|
17
|
+
this._containsUnusualLineTerminators = _containsUnusualLineTerminators;
|
|
18
|
+
this._isBasicASCII = _isBasicASCII;
|
|
19
|
+
this._normalizeEOL = _normalizeEOL;
|
|
20
|
+
}
|
|
21
|
+
_getEOL(defaultEOL) {
|
|
22
|
+
const totalEOLCount = this._cr + this._lf + this._crlf;
|
|
23
|
+
const totalCRCount = this._cr + this._crlf;
|
|
24
|
+
if (totalEOLCount === 0) {
|
|
25
|
+
// This is an empty file or a file with precisely one line
|
|
26
|
+
return (defaultEOL === 1 /* DefaultEndOfLine.LF */ ? '\n' : '\r\n');
|
|
27
|
+
}
|
|
28
|
+
if (totalCRCount > totalEOLCount / 2) {
|
|
29
|
+
// More than half of the file contains \r\n ending lines
|
|
30
|
+
return '\r\n';
|
|
31
|
+
}
|
|
32
|
+
// At least one line more ends in \n
|
|
33
|
+
return '\n';
|
|
34
|
+
}
|
|
35
|
+
create(defaultEOL) {
|
|
36
|
+
const eol = this._getEOL(defaultEOL);
|
|
37
|
+
const chunks = this._chunks;
|
|
38
|
+
if (this._normalizeEOL &&
|
|
39
|
+
((eol === '\r\n' && (this._cr > 0 || this._lf > 0))
|
|
40
|
+
|| (eol === '\n' && (this._cr > 0 || this._crlf > 0)))) {
|
|
41
|
+
// Normalize pieces
|
|
42
|
+
for (let i = 0, len = chunks.length; i < len; i++) {
|
|
43
|
+
const str = chunks[i].buffer.replace(/\r\n|\r|\n/g, eol);
|
|
44
|
+
const newLineStart = createLineStartsFast(str);
|
|
45
|
+
chunks[i] = new StringBuffer(str, newLineStart);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const textBuffer = new PieceTreeTextBuffer(chunks, this._bom, eol, this._containsRTL, this._containsUnusualLineTerminators, this._isBasicASCII, this._normalizeEOL);
|
|
49
|
+
return { textBuffer: textBuffer, disposable: textBuffer };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
class PieceTreeTextBufferBuilder {
|
|
53
|
+
constructor() {
|
|
54
|
+
this.chunks = [];
|
|
55
|
+
this.BOM = '';
|
|
56
|
+
this._hasPreviousChar = false;
|
|
57
|
+
this._previousChar = 0;
|
|
58
|
+
this._tmpLineStarts = [];
|
|
59
|
+
this.cr = 0;
|
|
60
|
+
this.lf = 0;
|
|
61
|
+
this.crlf = 0;
|
|
62
|
+
this.containsRTL = false;
|
|
63
|
+
this.containsUnusualLineTerminators = false;
|
|
64
|
+
this.isBasicASCII = true;
|
|
65
|
+
}
|
|
66
|
+
acceptChunk(chunk) {
|
|
67
|
+
if (chunk.length === 0) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (this.chunks.length === 0) {
|
|
71
|
+
if (startsWithUTF8BOM(chunk)) {
|
|
72
|
+
this.BOM = UTF8_BOM_CHARACTER;
|
|
73
|
+
chunk = chunk.substr(1);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const lastChar = chunk.charCodeAt(chunk.length - 1);
|
|
77
|
+
if (lastChar === 13 /* CharCode.CarriageReturn */ || (lastChar >= 0xD800 && lastChar <= 0xDBFF)) {
|
|
78
|
+
// last character is \r or a high surrogate => keep it back
|
|
79
|
+
this._acceptChunk1(chunk.substr(0, chunk.length - 1), false);
|
|
80
|
+
this._hasPreviousChar = true;
|
|
81
|
+
this._previousChar = lastChar;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
this._acceptChunk1(chunk, false);
|
|
85
|
+
this._hasPreviousChar = false;
|
|
86
|
+
this._previousChar = lastChar;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
_acceptChunk1(chunk, allowEmptyStrings) {
|
|
90
|
+
if (!allowEmptyStrings && chunk.length === 0) {
|
|
91
|
+
// Nothing to do
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (this._hasPreviousChar) {
|
|
95
|
+
this._acceptChunk2(String.fromCharCode(this._previousChar) + chunk);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
this._acceptChunk2(chunk);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
_acceptChunk2(chunk) {
|
|
102
|
+
const lineStarts = createLineStarts(this._tmpLineStarts, chunk);
|
|
103
|
+
this.chunks.push(new StringBuffer(chunk, lineStarts.lineStarts));
|
|
104
|
+
this.cr += lineStarts.cr;
|
|
105
|
+
this.lf += lineStarts.lf;
|
|
106
|
+
this.crlf += lineStarts.crlf;
|
|
107
|
+
if (!lineStarts.isBasicASCII) {
|
|
108
|
+
// this chunk contains non basic ASCII characters
|
|
109
|
+
this.isBasicASCII = false;
|
|
110
|
+
if (!this.containsRTL) {
|
|
111
|
+
this.containsRTL = containsRTL(chunk);
|
|
112
|
+
}
|
|
113
|
+
if (!this.containsUnusualLineTerminators) {
|
|
114
|
+
this.containsUnusualLineTerminators = containsUnusualLineTerminators(chunk);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
finish(normalizeEOL = true) {
|
|
119
|
+
this._finish();
|
|
120
|
+
return new PieceTreeTextBufferFactory(this.chunks, this.BOM, this.cr, this.lf, this.crlf, this.containsRTL, this.containsUnusualLineTerminators, this.isBasicASCII, normalizeEOL);
|
|
121
|
+
}
|
|
122
|
+
_finish() {
|
|
123
|
+
if (this.chunks.length === 0) {
|
|
124
|
+
this._acceptChunk1('', true);
|
|
125
|
+
}
|
|
126
|
+
if (this._hasPreviousChar) {
|
|
127
|
+
this._hasPreviousChar = false;
|
|
128
|
+
// recreate last chunk
|
|
129
|
+
const lastChunk = this.chunks[this.chunks.length - 1];
|
|
130
|
+
lastChunk.buffer += String.fromCharCode(this._previousChar);
|
|
131
|
+
const newLineStarts = createLineStartsFast(lastChunk.buffer);
|
|
132
|
+
lastChunk.lineStarts = newLineStarts;
|
|
133
|
+
if (this._previousChar === 13 /* CharCode.CarriageReturn */) {
|
|
134
|
+
this.cr++;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export { PieceTreeTextBufferBuilder };
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
class Point {
|
|
6
|
+
static equals(a, b) {
|
|
7
|
+
return a.x === b.x && a.y === b.y;
|
|
8
|
+
}
|
|
9
|
+
constructor(x, y) {
|
|
10
|
+
this.x = x;
|
|
11
|
+
this.y = y;
|
|
12
|
+
}
|
|
13
|
+
add(other) {
|
|
14
|
+
return new Point(this.x + other.x, this.y + other.y);
|
|
15
|
+
}
|
|
16
|
+
deltaX(delta) {
|
|
17
|
+
return new Point(this.x + delta, this.y);
|
|
18
|
+
}
|
|
19
|
+
deltaY(delta) {
|
|
20
|
+
return new Point(this.x, this.y + delta);
|
|
21
|
+
}
|
|
22
|
+
toString() {
|
|
23
|
+
return `(${this.x},${this.y})`;
|
|
24
|
+
}
|
|
25
|
+
subtract(other) {
|
|
26
|
+
return new Point(this.x - other.x, this.y - other.y);
|
|
27
|
+
}
|
|
28
|
+
scale(factor) {
|
|
29
|
+
return new Point(this.x * factor, this.y * factor);
|
|
30
|
+
}
|
|
31
|
+
mapComponents(map) {
|
|
32
|
+
return new Point(map(this.x), map(this.y));
|
|
33
|
+
}
|
|
34
|
+
isZero() {
|
|
35
|
+
return this.x === 0 && this.y === 0;
|
|
36
|
+
}
|
|
37
|
+
withThreshold(threshold) {
|
|
38
|
+
return this.mapComponents(axisVal => {
|
|
39
|
+
if (axisVal > threshold) {
|
|
40
|
+
return axisVal - threshold;
|
|
41
|
+
}
|
|
42
|
+
else if (axisVal < -threshold) {
|
|
43
|
+
return axisVal + threshold;
|
|
44
|
+
}
|
|
45
|
+
return 0;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { Point };
|