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,350 @@
|
|
|
1
|
+
import { LineTokens } from '../tokens/lineTokens.js';
|
|
2
|
+
import { Position } from '../core/position.js';
|
|
3
|
+
import { LineInjectedText } from '../textModelEvents.js';
|
|
4
|
+
import { ViewLineData } from '../viewModel.js';
|
|
5
|
+
import { SingleLineInlineDecoration } from './inlineDecorations.js';
|
|
6
|
+
|
|
7
|
+
/*---------------------------------------------------------------------------------------------
|
|
8
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
9
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
10
|
+
*--------------------------------------------------------------------------------------------*/
|
|
11
|
+
function createModelLineProjection(lineBreakData, isVisible) {
|
|
12
|
+
if (lineBreakData === null) {
|
|
13
|
+
// No mapping needed
|
|
14
|
+
if (isVisible) {
|
|
15
|
+
return IdentityModelLineProjection.INSTANCE;
|
|
16
|
+
}
|
|
17
|
+
return HiddenModelLineProjection.INSTANCE;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return new ModelLineProjection(lineBreakData, isVisible);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* This projection is used to
|
|
25
|
+
* * wrap model lines
|
|
26
|
+
* * inject text
|
|
27
|
+
*/
|
|
28
|
+
class ModelLineProjection {
|
|
29
|
+
constructor(lineBreakData, isVisible) {
|
|
30
|
+
this._projectionData = lineBreakData;
|
|
31
|
+
this._isVisible = isVisible;
|
|
32
|
+
}
|
|
33
|
+
isVisible() {
|
|
34
|
+
return this._isVisible;
|
|
35
|
+
}
|
|
36
|
+
setVisible(isVisible) {
|
|
37
|
+
this._isVisible = isVisible;
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
getProjectionData() {
|
|
41
|
+
return this._projectionData;
|
|
42
|
+
}
|
|
43
|
+
getViewLineCount() {
|
|
44
|
+
if (!this._isVisible) {
|
|
45
|
+
return 0;
|
|
46
|
+
}
|
|
47
|
+
return this._projectionData.getOutputLineCount();
|
|
48
|
+
}
|
|
49
|
+
getViewLineContent(model, modelLineNumber, outputLineIndex) {
|
|
50
|
+
this._assertVisible();
|
|
51
|
+
const startOffsetInInputWithInjections = outputLineIndex > 0 ? this._projectionData.breakOffsets[outputLineIndex - 1] : 0;
|
|
52
|
+
const endOffsetInInputWithInjections = this._projectionData.breakOffsets[outputLineIndex];
|
|
53
|
+
let r;
|
|
54
|
+
if (this._projectionData.injectionOffsets !== null) {
|
|
55
|
+
const injectedTexts = this._projectionData.injectionOffsets.map((offset, idx) => new LineInjectedText(0, 0, offset + 1, this._projectionData.injectionOptions[idx], 0));
|
|
56
|
+
const lineWithInjections = LineInjectedText.applyInjectedText(model.getLineContent(modelLineNumber), injectedTexts);
|
|
57
|
+
r = lineWithInjections.substring(startOffsetInInputWithInjections, endOffsetInInputWithInjections);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
r = model.getValueInRange({
|
|
61
|
+
startLineNumber: modelLineNumber,
|
|
62
|
+
startColumn: startOffsetInInputWithInjections + 1,
|
|
63
|
+
endLineNumber: modelLineNumber,
|
|
64
|
+
endColumn: endOffsetInInputWithInjections + 1
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (outputLineIndex > 0) {
|
|
68
|
+
r = spaces(this._projectionData.wrappedTextIndentLength) + r;
|
|
69
|
+
}
|
|
70
|
+
return r;
|
|
71
|
+
}
|
|
72
|
+
getViewLineLength(model, modelLineNumber, outputLineIndex) {
|
|
73
|
+
this._assertVisible();
|
|
74
|
+
return this._projectionData.getLineLength(outputLineIndex);
|
|
75
|
+
}
|
|
76
|
+
getViewLineMinColumn(_model, _modelLineNumber, outputLineIndex) {
|
|
77
|
+
this._assertVisible();
|
|
78
|
+
return this._projectionData.getMinOutputOffset(outputLineIndex) + 1;
|
|
79
|
+
}
|
|
80
|
+
getViewLineMaxColumn(model, modelLineNumber, outputLineIndex) {
|
|
81
|
+
this._assertVisible();
|
|
82
|
+
return this._projectionData.getMaxOutputOffset(outputLineIndex) + 1;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Try using {@link getViewLinesData} instead.
|
|
86
|
+
*/
|
|
87
|
+
getViewLineData(model, modelLineNumber, outputLineIndex) {
|
|
88
|
+
const arr = new Array();
|
|
89
|
+
this.getViewLinesData(model, modelLineNumber, outputLineIndex, 1, 0, [true], arr);
|
|
90
|
+
return arr[0];
|
|
91
|
+
}
|
|
92
|
+
getViewLinesData(model, modelLineNumber, outputLineIdx, lineCount, globalStartIndex, needed, result) {
|
|
93
|
+
this._assertVisible();
|
|
94
|
+
const lineBreakData = this._projectionData;
|
|
95
|
+
const injectionOffsets = lineBreakData.injectionOffsets;
|
|
96
|
+
const injectionOptions = lineBreakData.injectionOptions;
|
|
97
|
+
let inlineDecorationsPerOutputLine = null;
|
|
98
|
+
if (injectionOffsets) {
|
|
99
|
+
inlineDecorationsPerOutputLine = [];
|
|
100
|
+
let totalInjectedTextLengthBefore = 0;
|
|
101
|
+
let currentInjectedOffset = 0;
|
|
102
|
+
for (let outputLineIndex = 0; outputLineIndex < lineBreakData.getOutputLineCount(); outputLineIndex++) {
|
|
103
|
+
const inlineDecorations = new Array();
|
|
104
|
+
inlineDecorationsPerOutputLine[outputLineIndex] = inlineDecorations;
|
|
105
|
+
const lineStartOffsetInInputWithInjections = outputLineIndex > 0 ? lineBreakData.breakOffsets[outputLineIndex - 1] : 0;
|
|
106
|
+
const lineEndOffsetInInputWithInjections = lineBreakData.breakOffsets[outputLineIndex];
|
|
107
|
+
while (currentInjectedOffset < injectionOffsets.length) {
|
|
108
|
+
const length = injectionOptions[currentInjectedOffset].content.length;
|
|
109
|
+
const injectedTextStartOffsetInInputWithInjections = injectionOffsets[currentInjectedOffset] + totalInjectedTextLengthBefore;
|
|
110
|
+
const injectedTextEndOffsetInInputWithInjections = injectedTextStartOffsetInInputWithInjections + length;
|
|
111
|
+
if (injectedTextStartOffsetInInputWithInjections > lineEndOffsetInInputWithInjections) {
|
|
112
|
+
// Injected text only starts in later wrapped lines.
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
if (lineStartOffsetInInputWithInjections < injectedTextEndOffsetInInputWithInjections) {
|
|
116
|
+
// Injected text ends after or in this line (but also starts in or before this line).
|
|
117
|
+
const options = injectionOptions[currentInjectedOffset];
|
|
118
|
+
if (options.inlineClassName) {
|
|
119
|
+
const offset = (outputLineIndex > 0 ? lineBreakData.wrappedTextIndentLength : 0);
|
|
120
|
+
const start = offset + Math.max(injectedTextStartOffsetInInputWithInjections - lineStartOffsetInInputWithInjections, 0);
|
|
121
|
+
const end = offset + Math.min(injectedTextEndOffsetInInputWithInjections - lineStartOffsetInInputWithInjections, lineEndOffsetInInputWithInjections - lineStartOffsetInInputWithInjections);
|
|
122
|
+
if (start !== end) {
|
|
123
|
+
inlineDecorations.push(new SingleLineInlineDecoration(start, end, options.inlineClassName, options.inlineClassNameAffectsLetterSpacing));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (injectedTextEndOffsetInInputWithInjections <= lineEndOffsetInInputWithInjections) {
|
|
128
|
+
totalInjectedTextLengthBefore += length;
|
|
129
|
+
currentInjectedOffset++;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
// injected text breaks into next line, process it again
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
let lineWithInjections;
|
|
139
|
+
if (injectionOffsets) {
|
|
140
|
+
const tokensToInsert = [];
|
|
141
|
+
for (let idx = 0; idx < injectionOffsets.length; idx++) {
|
|
142
|
+
const offset = injectionOffsets[idx];
|
|
143
|
+
const tokens = injectionOptions[idx].tokens;
|
|
144
|
+
if (tokens) {
|
|
145
|
+
tokens.forEach((range, info) => {
|
|
146
|
+
tokensToInsert.push({
|
|
147
|
+
offset,
|
|
148
|
+
text: range.substring(injectionOptions[idx].content),
|
|
149
|
+
tokenMetadata: info.metadata,
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
tokensToInsert.push({
|
|
155
|
+
offset,
|
|
156
|
+
text: injectionOptions[idx].content,
|
|
157
|
+
tokenMetadata: LineTokens.defaultTokenMetadata,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
lineWithInjections = model.tokenization.getLineTokens(modelLineNumber).withInserted(tokensToInsert);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
lineWithInjections = model.tokenization.getLineTokens(modelLineNumber);
|
|
165
|
+
}
|
|
166
|
+
for (let outputLineIndex = outputLineIdx; outputLineIndex < outputLineIdx + lineCount; outputLineIndex++) {
|
|
167
|
+
const globalIndex = globalStartIndex + outputLineIndex - outputLineIdx;
|
|
168
|
+
if (!needed[globalIndex]) {
|
|
169
|
+
result[globalIndex] = null;
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
result[globalIndex] = this._getViewLineData(lineWithInjections, inlineDecorationsPerOutputLine ? inlineDecorationsPerOutputLine[outputLineIndex] : null, outputLineIndex);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
_getViewLineData(lineWithInjections, inlineDecorations, outputLineIndex) {
|
|
176
|
+
this._assertVisible();
|
|
177
|
+
const lineBreakData = this._projectionData;
|
|
178
|
+
const deltaStartIndex = (outputLineIndex > 0 ? lineBreakData.wrappedTextIndentLength : 0);
|
|
179
|
+
const lineStartOffsetInInputWithInjections = outputLineIndex > 0 ? lineBreakData.breakOffsets[outputLineIndex - 1] : 0;
|
|
180
|
+
const lineEndOffsetInInputWithInjections = lineBreakData.breakOffsets[outputLineIndex];
|
|
181
|
+
const tokens = lineWithInjections.sliceAndInflate(lineStartOffsetInInputWithInjections, lineEndOffsetInInputWithInjections, deltaStartIndex);
|
|
182
|
+
let lineContent = tokens.getLineContent();
|
|
183
|
+
if (outputLineIndex > 0) {
|
|
184
|
+
lineContent = spaces(lineBreakData.wrappedTextIndentLength) + lineContent;
|
|
185
|
+
}
|
|
186
|
+
const minColumn = this._projectionData.getMinOutputOffset(outputLineIndex) + 1;
|
|
187
|
+
const maxColumn = lineContent.length + 1;
|
|
188
|
+
const continuesWithWrappedLine = (outputLineIndex + 1 < this.getViewLineCount());
|
|
189
|
+
const startVisibleColumn = (outputLineIndex === 0 ? 0 : lineBreakData.breakOffsetsVisibleColumn[outputLineIndex - 1]);
|
|
190
|
+
return new ViewLineData(lineContent, continuesWithWrappedLine, minColumn, maxColumn, startVisibleColumn, tokens, inlineDecorations);
|
|
191
|
+
}
|
|
192
|
+
getModelColumnOfViewPosition(outputLineIndex, outputColumn) {
|
|
193
|
+
this._assertVisible();
|
|
194
|
+
return this._projectionData.translateToInputOffset(outputLineIndex, outputColumn - 1) + 1;
|
|
195
|
+
}
|
|
196
|
+
getViewPositionOfModelPosition(deltaLineNumber, inputColumn, affinity = 2 /* PositionAffinity.None */) {
|
|
197
|
+
this._assertVisible();
|
|
198
|
+
const r = this._projectionData.translateToOutputPosition(inputColumn - 1, affinity);
|
|
199
|
+
return r.toPosition(deltaLineNumber);
|
|
200
|
+
}
|
|
201
|
+
getViewLineNumberOfModelPosition(deltaLineNumber, inputColumn) {
|
|
202
|
+
this._assertVisible();
|
|
203
|
+
const r = this._projectionData.translateToOutputPosition(inputColumn - 1);
|
|
204
|
+
return deltaLineNumber + r.outputLineIndex;
|
|
205
|
+
}
|
|
206
|
+
normalizePosition(outputLineIndex, outputPosition, affinity) {
|
|
207
|
+
const baseViewLineNumber = outputPosition.lineNumber - outputLineIndex;
|
|
208
|
+
const normalizedOutputPosition = this._projectionData.normalizeOutputPosition(outputLineIndex, outputPosition.column - 1, affinity);
|
|
209
|
+
const result = normalizedOutputPosition.toPosition(baseViewLineNumber);
|
|
210
|
+
return result;
|
|
211
|
+
}
|
|
212
|
+
getInjectedTextAt(outputLineIndex, outputColumn) {
|
|
213
|
+
return this._projectionData.getInjectedText(outputLineIndex, outputColumn - 1);
|
|
214
|
+
}
|
|
215
|
+
_assertVisible() {
|
|
216
|
+
if (!this._isVisible) {
|
|
217
|
+
throw new Error('Not supported');
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* This projection does not change the model line.
|
|
223
|
+
*/
|
|
224
|
+
class IdentityModelLineProjection {
|
|
225
|
+
static { this.INSTANCE = new IdentityModelLineProjection(); }
|
|
226
|
+
constructor() { }
|
|
227
|
+
isVisible() {
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
setVisible(isVisible) {
|
|
231
|
+
if (isVisible) {
|
|
232
|
+
return this;
|
|
233
|
+
}
|
|
234
|
+
return HiddenModelLineProjection.INSTANCE;
|
|
235
|
+
}
|
|
236
|
+
getProjectionData() {
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
getViewLineCount() {
|
|
240
|
+
return 1;
|
|
241
|
+
}
|
|
242
|
+
getViewLineContent(model, modelLineNumber, _outputLineIndex) {
|
|
243
|
+
return model.getLineContent(modelLineNumber);
|
|
244
|
+
}
|
|
245
|
+
getViewLineLength(model, modelLineNumber, _outputLineIndex) {
|
|
246
|
+
return model.getLineLength(modelLineNumber);
|
|
247
|
+
}
|
|
248
|
+
getViewLineMinColumn(model, modelLineNumber, _outputLineIndex) {
|
|
249
|
+
return model.getLineMinColumn(modelLineNumber);
|
|
250
|
+
}
|
|
251
|
+
getViewLineMaxColumn(model, modelLineNumber, _outputLineIndex) {
|
|
252
|
+
return model.getLineMaxColumn(modelLineNumber);
|
|
253
|
+
}
|
|
254
|
+
getViewLineData(model, modelLineNumber, _outputLineIndex) {
|
|
255
|
+
const lineTokens = model.tokenization.getLineTokens(modelLineNumber);
|
|
256
|
+
const lineContent = lineTokens.getLineContent();
|
|
257
|
+
return new ViewLineData(lineContent, false, 1, lineContent.length + 1, 0, lineTokens.inflate(), null);
|
|
258
|
+
}
|
|
259
|
+
getViewLinesData(model, modelLineNumber, _fromOuputLineIndex, _toOutputLineIndex, globalStartIndex, needed, result) {
|
|
260
|
+
if (!needed[globalStartIndex]) {
|
|
261
|
+
result[globalStartIndex] = null;
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
result[globalStartIndex] = this.getViewLineData(model, modelLineNumber, 0);
|
|
265
|
+
}
|
|
266
|
+
getModelColumnOfViewPosition(_outputLineIndex, outputColumn) {
|
|
267
|
+
return outputColumn;
|
|
268
|
+
}
|
|
269
|
+
getViewPositionOfModelPosition(deltaLineNumber, inputColumn) {
|
|
270
|
+
return new Position(deltaLineNumber, inputColumn);
|
|
271
|
+
}
|
|
272
|
+
getViewLineNumberOfModelPosition(deltaLineNumber, _inputColumn) {
|
|
273
|
+
return deltaLineNumber;
|
|
274
|
+
}
|
|
275
|
+
normalizePosition(outputLineIndex, outputPosition, affinity) {
|
|
276
|
+
return outputPosition;
|
|
277
|
+
}
|
|
278
|
+
getInjectedTextAt(_outputLineIndex, _outputColumn) {
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* This projection hides the model line.
|
|
284
|
+
*/
|
|
285
|
+
class HiddenModelLineProjection {
|
|
286
|
+
static { this.INSTANCE = new HiddenModelLineProjection(); }
|
|
287
|
+
constructor() { }
|
|
288
|
+
isVisible() {
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
setVisible(isVisible) {
|
|
292
|
+
if (!isVisible) {
|
|
293
|
+
return this;
|
|
294
|
+
}
|
|
295
|
+
return IdentityModelLineProjection.INSTANCE;
|
|
296
|
+
}
|
|
297
|
+
getProjectionData() {
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
getViewLineCount() {
|
|
301
|
+
return 0;
|
|
302
|
+
}
|
|
303
|
+
getViewLineContent(_model, _modelLineNumber, _outputLineIndex) {
|
|
304
|
+
throw new Error('Not supported');
|
|
305
|
+
}
|
|
306
|
+
getViewLineLength(_model, _modelLineNumber, _outputLineIndex) {
|
|
307
|
+
throw new Error('Not supported');
|
|
308
|
+
}
|
|
309
|
+
getViewLineMinColumn(_model, _modelLineNumber, _outputLineIndex) {
|
|
310
|
+
throw new Error('Not supported');
|
|
311
|
+
}
|
|
312
|
+
getViewLineMaxColumn(_model, _modelLineNumber, _outputLineIndex) {
|
|
313
|
+
throw new Error('Not supported');
|
|
314
|
+
}
|
|
315
|
+
getViewLineData(_model, _modelLineNumber, _outputLineIndex) {
|
|
316
|
+
throw new Error('Not supported');
|
|
317
|
+
}
|
|
318
|
+
getViewLinesData(_model, _modelLineNumber, _fromOuputLineIndex, _toOutputLineIndex, _globalStartIndex, _needed, _result) {
|
|
319
|
+
throw new Error('Not supported');
|
|
320
|
+
}
|
|
321
|
+
getModelColumnOfViewPosition(_outputLineIndex, _outputColumn) {
|
|
322
|
+
throw new Error('Not supported');
|
|
323
|
+
}
|
|
324
|
+
getViewPositionOfModelPosition(_deltaLineNumber, _inputColumn) {
|
|
325
|
+
throw new Error('Not supported');
|
|
326
|
+
}
|
|
327
|
+
getViewLineNumberOfModelPosition(_deltaLineNumber, _inputColumn) {
|
|
328
|
+
throw new Error('Not supported');
|
|
329
|
+
}
|
|
330
|
+
normalizePosition(outputLineIndex, outputPosition, affinity) {
|
|
331
|
+
throw new Error('Not supported');
|
|
332
|
+
}
|
|
333
|
+
getInjectedTextAt(_outputLineIndex, _outputColumn) {
|
|
334
|
+
throw new Error('Not supported');
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
const _spaces = [''];
|
|
338
|
+
function spaces(count) {
|
|
339
|
+
if (count >= _spaces.length) {
|
|
340
|
+
for (let i = 1; i <= count; i++) {
|
|
341
|
+
_spaces[i] = _makeSpaces(i);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return _spaces[count];
|
|
345
|
+
}
|
|
346
|
+
function _makeSpaces(count) {
|
|
347
|
+
return new Array(count + 1).join(' ');
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export { createModelLineProjection };
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { assertNever } from '../../base/common/assert.js';
|
|
2
|
+
import { Position } from './core/position.js';
|
|
3
|
+
import { InjectedTextCursorStops } from './model.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
|
+
* *input*:
|
|
11
|
+
* ```
|
|
12
|
+
* xxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* -> Applying injections `[i...i]`, *inputWithInjections*:
|
|
16
|
+
* ```
|
|
17
|
+
* xxxxxx[iiiiiiiiii]xxxxxxxxxxxxxxxxx[ii]xxxx
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* -> breaking at offsets `|` in `xxxxxx[iiiiiii|iii]xxxxxxxxxxx|xxxxxx[ii]xxxx|`:
|
|
21
|
+
* ```
|
|
22
|
+
* xxxxxx[iiiiiii
|
|
23
|
+
* iii]xxxxxxxxxxx
|
|
24
|
+
* xxxxxx[ii]xxxx
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* -> applying wrappedTextIndentLength, *output*:
|
|
28
|
+
* ```
|
|
29
|
+
* xxxxxx[iiiiiii
|
|
30
|
+
* iii]xxxxxxxxxxx
|
|
31
|
+
* xxxxxx[ii]xxxx
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
class ModelLineProjectionData {
|
|
35
|
+
constructor(injectionOffsets,
|
|
36
|
+
/**
|
|
37
|
+
* `injectionOptions.length` must equal `injectionOffsets.length`
|
|
38
|
+
*/
|
|
39
|
+
injectionOptions,
|
|
40
|
+
/**
|
|
41
|
+
* Refers to offsets after applying injections to the source.
|
|
42
|
+
* The last break offset indicates the length of the source after applying injections.
|
|
43
|
+
*/
|
|
44
|
+
breakOffsets,
|
|
45
|
+
/**
|
|
46
|
+
* Refers to offsets after applying injections
|
|
47
|
+
*/
|
|
48
|
+
breakOffsetsVisibleColumn, wrappedTextIndentLength) {
|
|
49
|
+
this.injectionOffsets = injectionOffsets;
|
|
50
|
+
this.injectionOptions = injectionOptions;
|
|
51
|
+
this.breakOffsets = breakOffsets;
|
|
52
|
+
this.breakOffsetsVisibleColumn = breakOffsetsVisibleColumn;
|
|
53
|
+
this.wrappedTextIndentLength = wrappedTextIndentLength;
|
|
54
|
+
}
|
|
55
|
+
getOutputLineCount() {
|
|
56
|
+
return this.breakOffsets.length;
|
|
57
|
+
}
|
|
58
|
+
getMinOutputOffset(outputLineIndex) {
|
|
59
|
+
if (outputLineIndex > 0) {
|
|
60
|
+
return this.wrappedTextIndentLength;
|
|
61
|
+
}
|
|
62
|
+
return 0;
|
|
63
|
+
}
|
|
64
|
+
getLineLength(outputLineIndex) {
|
|
65
|
+
// These offsets refer to model text with injected text.
|
|
66
|
+
const startOffset = outputLineIndex > 0 ? this.breakOffsets[outputLineIndex - 1] : 0;
|
|
67
|
+
const endOffset = this.breakOffsets[outputLineIndex];
|
|
68
|
+
let lineLength = endOffset - startOffset;
|
|
69
|
+
if (outputLineIndex > 0) {
|
|
70
|
+
lineLength += this.wrappedTextIndentLength;
|
|
71
|
+
}
|
|
72
|
+
return lineLength;
|
|
73
|
+
}
|
|
74
|
+
getMaxOutputOffset(outputLineIndex) {
|
|
75
|
+
return this.getLineLength(outputLineIndex);
|
|
76
|
+
}
|
|
77
|
+
translateToInputOffset(outputLineIndex, outputOffset) {
|
|
78
|
+
if (outputLineIndex > 0) {
|
|
79
|
+
outputOffset = Math.max(0, outputOffset - this.wrappedTextIndentLength);
|
|
80
|
+
}
|
|
81
|
+
const offsetInInputWithInjection = outputLineIndex === 0 ? outputOffset : this.breakOffsets[outputLineIndex - 1] + outputOffset;
|
|
82
|
+
let offsetInInput = offsetInInputWithInjection;
|
|
83
|
+
if (this.injectionOffsets !== null) {
|
|
84
|
+
for (let i = 0; i < this.injectionOffsets.length; i++) {
|
|
85
|
+
if (offsetInInput > this.injectionOffsets[i]) {
|
|
86
|
+
if (offsetInInput < this.injectionOffsets[i] + this.injectionOptions[i].content.length) {
|
|
87
|
+
// `inputOffset` is within injected text
|
|
88
|
+
offsetInInput = this.injectionOffsets[i];
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
offsetInInput -= this.injectionOptions[i].content.length;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return offsetInInput;
|
|
100
|
+
}
|
|
101
|
+
translateToOutputPosition(inputOffset, affinity = 2 /* PositionAffinity.None */) {
|
|
102
|
+
let inputOffsetInInputWithInjection = inputOffset;
|
|
103
|
+
if (this.injectionOffsets !== null) {
|
|
104
|
+
for (let i = 0; i < this.injectionOffsets.length; i++) {
|
|
105
|
+
if (inputOffset < this.injectionOffsets[i]) {
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
if (affinity !== 1 /* PositionAffinity.Right */ && inputOffset === this.injectionOffsets[i]) {
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
inputOffsetInInputWithInjection += this.injectionOptions[i].content.length;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return this.offsetInInputWithInjectionsToOutputPosition(inputOffsetInInputWithInjection, affinity);
|
|
115
|
+
}
|
|
116
|
+
offsetInInputWithInjectionsToOutputPosition(offsetInInputWithInjections, affinity = 2 /* PositionAffinity.None */) {
|
|
117
|
+
let low = 0;
|
|
118
|
+
let high = this.breakOffsets.length - 1;
|
|
119
|
+
let mid = 0;
|
|
120
|
+
let midStart = 0;
|
|
121
|
+
while (low <= high) {
|
|
122
|
+
mid = low + ((high - low) / 2) | 0;
|
|
123
|
+
const midStop = this.breakOffsets[mid];
|
|
124
|
+
midStart = mid > 0 ? this.breakOffsets[mid - 1] : 0;
|
|
125
|
+
if (affinity === 0 /* PositionAffinity.Left */) {
|
|
126
|
+
if (offsetInInputWithInjections <= midStart) {
|
|
127
|
+
high = mid - 1;
|
|
128
|
+
}
|
|
129
|
+
else if (offsetInInputWithInjections > midStop) {
|
|
130
|
+
low = mid + 1;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
if (offsetInInputWithInjections < midStart) {
|
|
138
|
+
high = mid - 1;
|
|
139
|
+
}
|
|
140
|
+
else if (offsetInInputWithInjections >= midStop) {
|
|
141
|
+
low = mid + 1;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
let outputOffset = offsetInInputWithInjections - midStart;
|
|
149
|
+
if (mid > 0) {
|
|
150
|
+
outputOffset += this.wrappedTextIndentLength;
|
|
151
|
+
}
|
|
152
|
+
return new OutputPosition(mid, outputOffset);
|
|
153
|
+
}
|
|
154
|
+
normalizeOutputPosition(outputLineIndex, outputOffset, affinity) {
|
|
155
|
+
if (this.injectionOffsets !== null) {
|
|
156
|
+
const offsetInInputWithInjections = this.outputPositionToOffsetInInputWithInjections(outputLineIndex, outputOffset);
|
|
157
|
+
const normalizedOffsetInUnwrappedLine = this.normalizeOffsetInInputWithInjectionsAroundInjections(offsetInInputWithInjections, affinity);
|
|
158
|
+
if (normalizedOffsetInUnwrappedLine !== offsetInInputWithInjections) {
|
|
159
|
+
// injected text caused a change
|
|
160
|
+
return this.offsetInInputWithInjectionsToOutputPosition(normalizedOffsetInUnwrappedLine, affinity);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (affinity === 0 /* PositionAffinity.Left */) {
|
|
164
|
+
if (outputLineIndex > 0 && outputOffset === this.getMinOutputOffset(outputLineIndex)) {
|
|
165
|
+
return new OutputPosition(outputLineIndex - 1, this.getMaxOutputOffset(outputLineIndex - 1));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
else if (affinity === 1 /* PositionAffinity.Right */) {
|
|
169
|
+
const maxOutputLineIndex = this.getOutputLineCount() - 1;
|
|
170
|
+
if (outputLineIndex < maxOutputLineIndex && outputOffset === this.getMaxOutputOffset(outputLineIndex)) {
|
|
171
|
+
return new OutputPosition(outputLineIndex + 1, this.getMinOutputOffset(outputLineIndex + 1));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return new OutputPosition(outputLineIndex, outputOffset);
|
|
175
|
+
}
|
|
176
|
+
outputPositionToOffsetInInputWithInjections(outputLineIndex, outputOffset) {
|
|
177
|
+
if (outputLineIndex > 0) {
|
|
178
|
+
outputOffset = Math.max(0, outputOffset - this.wrappedTextIndentLength);
|
|
179
|
+
}
|
|
180
|
+
const result = (outputLineIndex > 0 ? this.breakOffsets[outputLineIndex - 1] : 0) + outputOffset;
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
|
+
normalizeOffsetInInputWithInjectionsAroundInjections(offsetInInputWithInjections, affinity) {
|
|
184
|
+
const injectedText = this.getInjectedTextAtOffset(offsetInInputWithInjections);
|
|
185
|
+
if (!injectedText) {
|
|
186
|
+
return offsetInInputWithInjections;
|
|
187
|
+
}
|
|
188
|
+
if (affinity === 2 /* PositionAffinity.None */) {
|
|
189
|
+
if (offsetInInputWithInjections === injectedText.offsetInInputWithInjections + injectedText.length
|
|
190
|
+
&& hasRightCursorStop(this.injectionOptions[injectedText.injectedTextIndex].cursorStops)) {
|
|
191
|
+
return injectedText.offsetInInputWithInjections + injectedText.length;
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
let result = injectedText.offsetInInputWithInjections;
|
|
195
|
+
if (hasLeftCursorStop(this.injectionOptions[injectedText.injectedTextIndex].cursorStops)) {
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
let index = injectedText.injectedTextIndex - 1;
|
|
199
|
+
while (index >= 0 && this.injectionOffsets[index] === this.injectionOffsets[injectedText.injectedTextIndex]) {
|
|
200
|
+
if (hasRightCursorStop(this.injectionOptions[index].cursorStops)) {
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
result -= this.injectionOptions[index].content.length;
|
|
204
|
+
if (hasLeftCursorStop(this.injectionOptions[index].cursorStops)) {
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
index--;
|
|
208
|
+
}
|
|
209
|
+
return result;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
else if (affinity === 1 /* PositionAffinity.Right */ || affinity === 4 /* PositionAffinity.RightOfInjectedText */) {
|
|
213
|
+
let result = injectedText.offsetInInputWithInjections + injectedText.length;
|
|
214
|
+
let index = injectedText.injectedTextIndex;
|
|
215
|
+
// traverse all injected text that touch each other
|
|
216
|
+
while (index + 1 < this.injectionOffsets.length && this.injectionOffsets[index + 1] === this.injectionOffsets[index]) {
|
|
217
|
+
result += this.injectionOptions[index + 1].content.length;
|
|
218
|
+
index++;
|
|
219
|
+
}
|
|
220
|
+
return result;
|
|
221
|
+
}
|
|
222
|
+
else if (affinity === 0 /* PositionAffinity.Left */ || affinity === 3 /* PositionAffinity.LeftOfInjectedText */) {
|
|
223
|
+
// affinity is left
|
|
224
|
+
let result = injectedText.offsetInInputWithInjections;
|
|
225
|
+
let index = injectedText.injectedTextIndex;
|
|
226
|
+
// traverse all injected text that touch each other
|
|
227
|
+
while (index - 1 >= 0 && this.injectionOffsets[index - 1] === this.injectionOffsets[index]) {
|
|
228
|
+
result -= this.injectionOptions[index - 1].content.length;
|
|
229
|
+
index--;
|
|
230
|
+
}
|
|
231
|
+
return result;
|
|
232
|
+
}
|
|
233
|
+
assertNever();
|
|
234
|
+
}
|
|
235
|
+
getInjectedText(outputLineIndex, outputOffset) {
|
|
236
|
+
const offset = this.outputPositionToOffsetInInputWithInjections(outputLineIndex, outputOffset);
|
|
237
|
+
const injectedText = this.getInjectedTextAtOffset(offset);
|
|
238
|
+
if (!injectedText) {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
242
|
+
options: this.injectionOptions[injectedText.injectedTextIndex]
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
getInjectedTextAtOffset(offsetInInputWithInjections) {
|
|
246
|
+
const injectionOffsets = this.injectionOffsets;
|
|
247
|
+
const injectionOptions = this.injectionOptions;
|
|
248
|
+
if (injectionOffsets !== null) {
|
|
249
|
+
let totalInjectedTextLengthBefore = 0;
|
|
250
|
+
for (let i = 0; i < injectionOffsets.length; i++) {
|
|
251
|
+
const length = injectionOptions[i].content.length;
|
|
252
|
+
const injectedTextStartOffsetInInputWithInjections = injectionOffsets[i] + totalInjectedTextLengthBefore;
|
|
253
|
+
const injectedTextEndOffsetInInputWithInjections = injectionOffsets[i] + totalInjectedTextLengthBefore + length;
|
|
254
|
+
if (injectedTextStartOffsetInInputWithInjections > offsetInInputWithInjections) {
|
|
255
|
+
// Injected text starts later.
|
|
256
|
+
break; // All later injected texts have an even larger offset.
|
|
257
|
+
}
|
|
258
|
+
if (offsetInInputWithInjections <= injectedTextEndOffsetInInputWithInjections) {
|
|
259
|
+
// Injected text ends after or with the given position (but also starts with or before it).
|
|
260
|
+
return {
|
|
261
|
+
injectedTextIndex: i,
|
|
262
|
+
offsetInInputWithInjections: injectedTextStartOffsetInInputWithInjections,
|
|
263
|
+
length
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
totalInjectedTextLengthBefore += length;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return undefined;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function hasRightCursorStop(cursorStop) {
|
|
273
|
+
if (cursorStop === null || cursorStop === undefined) {
|
|
274
|
+
return true;
|
|
275
|
+
}
|
|
276
|
+
return cursorStop === InjectedTextCursorStops.Right || cursorStop === InjectedTextCursorStops.Both;
|
|
277
|
+
}
|
|
278
|
+
function hasLeftCursorStop(cursorStop) {
|
|
279
|
+
if (cursorStop === null || cursorStop === undefined) {
|
|
280
|
+
return true;
|
|
281
|
+
}
|
|
282
|
+
return cursorStop === InjectedTextCursorStops.Left || cursorStop === InjectedTextCursorStops.Both;
|
|
283
|
+
}
|
|
284
|
+
class OutputPosition {
|
|
285
|
+
constructor(outputLineIndex, outputOffset) {
|
|
286
|
+
this.outputLineIndex = outputLineIndex;
|
|
287
|
+
this.outputOffset = outputOffset;
|
|
288
|
+
}
|
|
289
|
+
toString() {
|
|
290
|
+
return `${this.outputLineIndex}:${this.outputOffset}`;
|
|
291
|
+
}
|
|
292
|
+
toPosition(baseLineNumber) {
|
|
293
|
+
return new Position(baseLineNumber + this.outputLineIndex, this.outputOffset + 1);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export { ModelLineProjectionData, OutputPosition };
|