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,720 @@
|
|
|
1
|
+
import { isLowerAsciiLetter, isAsciiDigit, isUpperAsciiLetter, lastNonWhitespaceIndex } from '../../../base/common/strings.js';
|
|
2
|
+
import { SingleCursorState } from '../cursorCommon.js';
|
|
3
|
+
import { DeleteOperations } from './cursorDeleteOperations.js';
|
|
4
|
+
import { getMapForWordSeparators } from '../core/wordCharacterClassifier.js';
|
|
5
|
+
import { Position } from '../core/position.js';
|
|
6
|
+
import { Range } from '../core/range.js';
|
|
7
|
+
|
|
8
|
+
/*---------------------------------------------------------------------------------------------
|
|
9
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
10
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
11
|
+
*--------------------------------------------------------------------------------------------*/
|
|
12
|
+
class WordOperations {
|
|
13
|
+
static _createWord(lineContent, wordType, nextCharClass, start, end) {
|
|
14
|
+
// console.log('WORD ==> ' + start + ' => ' + end + ':::: <<<' + lineContent.substring(start, end) + '>>>');
|
|
15
|
+
return { start: start, end: end, wordType: wordType, nextCharClass: nextCharClass };
|
|
16
|
+
}
|
|
17
|
+
static _createIntlWord(intlWord, nextCharClass) {
|
|
18
|
+
// console.log('INTL WORD ==> ' + intlWord.index + ' => ' + intlWord.index + intlWord.segment.length + ':::: <<<' + intlWord.segment + '>>>');
|
|
19
|
+
return { start: intlWord.index, end: intlWord.index + intlWord.segment.length, wordType: 1 /* WordType.Regular */, nextCharClass: nextCharClass };
|
|
20
|
+
}
|
|
21
|
+
static _findPreviousWordOnLine(wordSeparators, model, position) {
|
|
22
|
+
const lineContent = model.getLineContent(position.lineNumber);
|
|
23
|
+
return this._doFindPreviousWordOnLine(lineContent, wordSeparators, position);
|
|
24
|
+
}
|
|
25
|
+
static _doFindPreviousWordOnLine(lineContent, wordSeparators, position) {
|
|
26
|
+
let wordType = 0 /* WordType.None */;
|
|
27
|
+
const previousIntlWord = wordSeparators.findPrevIntlWordBeforeOrAtOffset(lineContent, position.column - 2);
|
|
28
|
+
for (let chIndex = position.column - 2; chIndex >= 0; chIndex--) {
|
|
29
|
+
const chCode = lineContent.charCodeAt(chIndex);
|
|
30
|
+
const chClass = wordSeparators.get(chCode);
|
|
31
|
+
if (previousIntlWord && chIndex === previousIntlWord.index) {
|
|
32
|
+
return this._createIntlWord(previousIntlWord, chClass);
|
|
33
|
+
}
|
|
34
|
+
if (chClass === 0 /* WordCharacterClass.Regular */) {
|
|
35
|
+
if (wordType === 2 /* WordType.Separator */) {
|
|
36
|
+
return this._createWord(lineContent, wordType, chClass, chIndex + 1, this._findEndOfWord(lineContent, wordSeparators, wordType, chIndex + 1));
|
|
37
|
+
}
|
|
38
|
+
wordType = 1 /* WordType.Regular */;
|
|
39
|
+
}
|
|
40
|
+
else if (chClass === 2 /* WordCharacterClass.WordSeparator */) {
|
|
41
|
+
if (wordType === 1 /* WordType.Regular */) {
|
|
42
|
+
return this._createWord(lineContent, wordType, chClass, chIndex + 1, this._findEndOfWord(lineContent, wordSeparators, wordType, chIndex + 1));
|
|
43
|
+
}
|
|
44
|
+
wordType = 2 /* WordType.Separator */;
|
|
45
|
+
}
|
|
46
|
+
else if (chClass === 1 /* WordCharacterClass.Whitespace */) {
|
|
47
|
+
if (wordType !== 0 /* WordType.None */) {
|
|
48
|
+
return this._createWord(lineContent, wordType, chClass, chIndex + 1, this._findEndOfWord(lineContent, wordSeparators, wordType, chIndex + 1));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (wordType !== 0 /* WordType.None */) {
|
|
53
|
+
return this._createWord(lineContent, wordType, 1 /* WordCharacterClass.Whitespace */, 0, this._findEndOfWord(lineContent, wordSeparators, wordType, 0));
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
static _findEndOfWord(lineContent, wordSeparators, wordType, startIndex) {
|
|
58
|
+
const nextIntlWord = wordSeparators.findNextIntlWordAtOrAfterOffset(lineContent, startIndex);
|
|
59
|
+
const len = lineContent.length;
|
|
60
|
+
for (let chIndex = startIndex; chIndex < len; chIndex++) {
|
|
61
|
+
const chCode = lineContent.charCodeAt(chIndex);
|
|
62
|
+
const chClass = wordSeparators.get(chCode);
|
|
63
|
+
if (nextIntlWord && chIndex === nextIntlWord.index + nextIntlWord.segment.length) {
|
|
64
|
+
return chIndex;
|
|
65
|
+
}
|
|
66
|
+
if (chClass === 1 /* WordCharacterClass.Whitespace */) {
|
|
67
|
+
return chIndex;
|
|
68
|
+
}
|
|
69
|
+
if (wordType === 1 /* WordType.Regular */ && chClass === 2 /* WordCharacterClass.WordSeparator */) {
|
|
70
|
+
return chIndex;
|
|
71
|
+
}
|
|
72
|
+
if (wordType === 2 /* WordType.Separator */ && chClass === 0 /* WordCharacterClass.Regular */) {
|
|
73
|
+
return chIndex;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return len;
|
|
77
|
+
}
|
|
78
|
+
static _findNextWordOnLine(wordSeparators, model, position) {
|
|
79
|
+
const lineContent = model.getLineContent(position.lineNumber);
|
|
80
|
+
return this._doFindNextWordOnLine(lineContent, wordSeparators, position);
|
|
81
|
+
}
|
|
82
|
+
static _doFindNextWordOnLine(lineContent, wordSeparators, position) {
|
|
83
|
+
let wordType = 0 /* WordType.None */;
|
|
84
|
+
const len = lineContent.length;
|
|
85
|
+
const nextIntlWord = wordSeparators.findNextIntlWordAtOrAfterOffset(lineContent, position.column - 1);
|
|
86
|
+
for (let chIndex = position.column - 1; chIndex < len; chIndex++) {
|
|
87
|
+
const chCode = lineContent.charCodeAt(chIndex);
|
|
88
|
+
const chClass = wordSeparators.get(chCode);
|
|
89
|
+
if (nextIntlWord && chIndex === nextIntlWord.index) {
|
|
90
|
+
return this._createIntlWord(nextIntlWord, chClass);
|
|
91
|
+
}
|
|
92
|
+
if (chClass === 0 /* WordCharacterClass.Regular */) {
|
|
93
|
+
if (wordType === 2 /* WordType.Separator */) {
|
|
94
|
+
return this._createWord(lineContent, wordType, chClass, this._findStartOfWord(lineContent, wordSeparators, wordType, chIndex - 1), chIndex);
|
|
95
|
+
}
|
|
96
|
+
wordType = 1 /* WordType.Regular */;
|
|
97
|
+
}
|
|
98
|
+
else if (chClass === 2 /* WordCharacterClass.WordSeparator */) {
|
|
99
|
+
if (wordType === 1 /* WordType.Regular */) {
|
|
100
|
+
return this._createWord(lineContent, wordType, chClass, this._findStartOfWord(lineContent, wordSeparators, wordType, chIndex - 1), chIndex);
|
|
101
|
+
}
|
|
102
|
+
wordType = 2 /* WordType.Separator */;
|
|
103
|
+
}
|
|
104
|
+
else if (chClass === 1 /* WordCharacterClass.Whitespace */) {
|
|
105
|
+
if (wordType !== 0 /* WordType.None */) {
|
|
106
|
+
return this._createWord(lineContent, wordType, chClass, this._findStartOfWord(lineContent, wordSeparators, wordType, chIndex - 1), chIndex);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (wordType !== 0 /* WordType.None */) {
|
|
111
|
+
return this._createWord(lineContent, wordType, 1 /* WordCharacterClass.Whitespace */, this._findStartOfWord(lineContent, wordSeparators, wordType, len - 1), len);
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
static _findStartOfWord(lineContent, wordSeparators, wordType, startIndex) {
|
|
116
|
+
const previousIntlWord = wordSeparators.findPrevIntlWordBeforeOrAtOffset(lineContent, startIndex);
|
|
117
|
+
for (let chIndex = startIndex; chIndex >= 0; chIndex--) {
|
|
118
|
+
const chCode = lineContent.charCodeAt(chIndex);
|
|
119
|
+
const chClass = wordSeparators.get(chCode);
|
|
120
|
+
if (previousIntlWord && chIndex === previousIntlWord.index) {
|
|
121
|
+
return chIndex;
|
|
122
|
+
}
|
|
123
|
+
if (chClass === 1 /* WordCharacterClass.Whitespace */) {
|
|
124
|
+
return chIndex + 1;
|
|
125
|
+
}
|
|
126
|
+
if (wordType === 1 /* WordType.Regular */ && chClass === 2 /* WordCharacterClass.WordSeparator */) {
|
|
127
|
+
return chIndex + 1;
|
|
128
|
+
}
|
|
129
|
+
if (wordType === 2 /* WordType.Separator */ && chClass === 0 /* WordCharacterClass.Regular */) {
|
|
130
|
+
return chIndex + 1;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return 0;
|
|
134
|
+
}
|
|
135
|
+
static moveWordLeft(wordSeparators, model, position, wordNavigationType, hasMulticursor) {
|
|
136
|
+
let lineNumber = position.lineNumber;
|
|
137
|
+
let column = position.column;
|
|
138
|
+
if (column === 1) {
|
|
139
|
+
if (lineNumber > 1) {
|
|
140
|
+
lineNumber = lineNumber - 1;
|
|
141
|
+
column = model.getLineMaxColumn(lineNumber);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
let prevWordOnLine = WordOperations._findPreviousWordOnLine(wordSeparators, model, new Position(lineNumber, column));
|
|
145
|
+
if (wordNavigationType === 0 /* WordNavigationType.WordStart */) {
|
|
146
|
+
return new Position(lineNumber, prevWordOnLine ? prevWordOnLine.start + 1 : 1);
|
|
147
|
+
}
|
|
148
|
+
if (wordNavigationType === 1 /* WordNavigationType.WordStartFast */) {
|
|
149
|
+
if (!hasMulticursor // avoid having multiple cursors stop at different locations when doing word start
|
|
150
|
+
&& prevWordOnLine
|
|
151
|
+
&& prevWordOnLine.wordType === 2 /* WordType.Separator */
|
|
152
|
+
&& prevWordOnLine.end - prevWordOnLine.start === 1
|
|
153
|
+
&& prevWordOnLine.nextCharClass === 0 /* WordCharacterClass.Regular */) {
|
|
154
|
+
// Skip over a word made up of one single separator and followed by a regular character
|
|
155
|
+
prevWordOnLine = WordOperations._findPreviousWordOnLine(wordSeparators, model, new Position(lineNumber, prevWordOnLine.start + 1));
|
|
156
|
+
}
|
|
157
|
+
return new Position(lineNumber, prevWordOnLine ? prevWordOnLine.start + 1 : 1);
|
|
158
|
+
}
|
|
159
|
+
if (wordNavigationType === 3 /* WordNavigationType.WordAccessibility */) {
|
|
160
|
+
while (prevWordOnLine
|
|
161
|
+
&& prevWordOnLine.wordType === 2 /* WordType.Separator */) {
|
|
162
|
+
// Skip over words made up of only separators
|
|
163
|
+
prevWordOnLine = WordOperations._findPreviousWordOnLine(wordSeparators, model, new Position(lineNumber, prevWordOnLine.start + 1));
|
|
164
|
+
}
|
|
165
|
+
return new Position(lineNumber, prevWordOnLine ? prevWordOnLine.start + 1 : 1);
|
|
166
|
+
}
|
|
167
|
+
// We are stopping at the ending of words
|
|
168
|
+
if (prevWordOnLine && column <= prevWordOnLine.end + 1) {
|
|
169
|
+
prevWordOnLine = WordOperations._findPreviousWordOnLine(wordSeparators, model, new Position(lineNumber, prevWordOnLine.start + 1));
|
|
170
|
+
}
|
|
171
|
+
return new Position(lineNumber, prevWordOnLine ? prevWordOnLine.end + 1 : 1);
|
|
172
|
+
}
|
|
173
|
+
static _moveWordPartLeft(model, position) {
|
|
174
|
+
const lineNumber = position.lineNumber;
|
|
175
|
+
const maxColumn = model.getLineMaxColumn(lineNumber);
|
|
176
|
+
if (position.column === 1) {
|
|
177
|
+
return (lineNumber > 1 ? new Position(lineNumber - 1, model.getLineMaxColumn(lineNumber - 1)) : position);
|
|
178
|
+
}
|
|
179
|
+
const lineContent = model.getLineContent(lineNumber);
|
|
180
|
+
for (let column = position.column - 1; column > 1; column--) {
|
|
181
|
+
const left = lineContent.charCodeAt(column - 2);
|
|
182
|
+
const right = lineContent.charCodeAt(column - 1);
|
|
183
|
+
if (left === 95 /* CharCode.Underline */ && right !== 95 /* CharCode.Underline */) {
|
|
184
|
+
// snake_case_variables
|
|
185
|
+
return new Position(lineNumber, column);
|
|
186
|
+
}
|
|
187
|
+
if (left === 45 /* CharCode.Dash */ && right !== 45 /* CharCode.Dash */) {
|
|
188
|
+
// kebab-case-variables
|
|
189
|
+
return new Position(lineNumber, column);
|
|
190
|
+
}
|
|
191
|
+
if ((isLowerAsciiLetter(left) || isAsciiDigit(left)) && isUpperAsciiLetter(right)) {
|
|
192
|
+
// camelCaseVariables
|
|
193
|
+
return new Position(lineNumber, column);
|
|
194
|
+
}
|
|
195
|
+
if (isUpperAsciiLetter(left) && isUpperAsciiLetter(right)) {
|
|
196
|
+
// thisIsACamelCaseWithOneLetterWords
|
|
197
|
+
if (column + 1 < maxColumn) {
|
|
198
|
+
const rightRight = lineContent.charCodeAt(column);
|
|
199
|
+
if (isLowerAsciiLetter(rightRight) || isAsciiDigit(rightRight)) {
|
|
200
|
+
return new Position(lineNumber, column);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return new Position(lineNumber, 1);
|
|
206
|
+
}
|
|
207
|
+
static moveWordRight(wordSeparators, model, position, wordNavigationType) {
|
|
208
|
+
let lineNumber = position.lineNumber;
|
|
209
|
+
let column = position.column;
|
|
210
|
+
let movedDown = false;
|
|
211
|
+
if (column === model.getLineMaxColumn(lineNumber)) {
|
|
212
|
+
if (lineNumber < model.getLineCount()) {
|
|
213
|
+
movedDown = true;
|
|
214
|
+
lineNumber = lineNumber + 1;
|
|
215
|
+
column = 1;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
let nextWordOnLine = WordOperations._findNextWordOnLine(wordSeparators, model, new Position(lineNumber, column));
|
|
219
|
+
if (wordNavigationType === 2 /* WordNavigationType.WordEnd */) {
|
|
220
|
+
if (nextWordOnLine && nextWordOnLine.wordType === 2 /* WordType.Separator */) {
|
|
221
|
+
if (nextWordOnLine.end - nextWordOnLine.start === 1 && nextWordOnLine.nextCharClass === 0 /* WordCharacterClass.Regular */) {
|
|
222
|
+
// Skip over a word made up of one single separator and followed by a regular character
|
|
223
|
+
nextWordOnLine = WordOperations._findNextWordOnLine(wordSeparators, model, new Position(lineNumber, nextWordOnLine.end + 1));
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (nextWordOnLine) {
|
|
227
|
+
column = nextWordOnLine.end + 1;
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
column = model.getLineMaxColumn(lineNumber);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
else if (wordNavigationType === 3 /* WordNavigationType.WordAccessibility */) {
|
|
234
|
+
if (movedDown) {
|
|
235
|
+
// If we move to the next line, pretend that the cursor is right before the first character.
|
|
236
|
+
// This is needed when the first word starts right at the first character - and in order not to miss it,
|
|
237
|
+
// we need to start before.
|
|
238
|
+
column = 0;
|
|
239
|
+
}
|
|
240
|
+
while (nextWordOnLine
|
|
241
|
+
&& (nextWordOnLine.wordType === 2 /* WordType.Separator */
|
|
242
|
+
|| nextWordOnLine.start + 1 <= column)) {
|
|
243
|
+
// Skip over a word made up of one single separator
|
|
244
|
+
// Also skip over word if it begins before current cursor position to ascertain we're moving forward at least 1 character.
|
|
245
|
+
nextWordOnLine = WordOperations._findNextWordOnLine(wordSeparators, model, new Position(lineNumber, nextWordOnLine.end + 1));
|
|
246
|
+
}
|
|
247
|
+
if (nextWordOnLine) {
|
|
248
|
+
column = nextWordOnLine.start + 1;
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
column = model.getLineMaxColumn(lineNumber);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
if (nextWordOnLine && !movedDown && column >= nextWordOnLine.start + 1) {
|
|
256
|
+
nextWordOnLine = WordOperations._findNextWordOnLine(wordSeparators, model, new Position(lineNumber, nextWordOnLine.end + 1));
|
|
257
|
+
}
|
|
258
|
+
if (nextWordOnLine) {
|
|
259
|
+
column = nextWordOnLine.start + 1;
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
column = model.getLineMaxColumn(lineNumber);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return new Position(lineNumber, column);
|
|
266
|
+
}
|
|
267
|
+
static _moveWordPartRight(model, position) {
|
|
268
|
+
const lineNumber = position.lineNumber;
|
|
269
|
+
const maxColumn = model.getLineMaxColumn(lineNumber);
|
|
270
|
+
if (position.column === maxColumn) {
|
|
271
|
+
return (lineNumber < model.getLineCount() ? new Position(lineNumber + 1, 1) : position);
|
|
272
|
+
}
|
|
273
|
+
const lineContent = model.getLineContent(lineNumber);
|
|
274
|
+
for (let column = position.column + 1; column < maxColumn; column++) {
|
|
275
|
+
const left = lineContent.charCodeAt(column - 2);
|
|
276
|
+
const right = lineContent.charCodeAt(column - 1);
|
|
277
|
+
if (left !== 95 /* CharCode.Underline */ && right === 95 /* CharCode.Underline */) {
|
|
278
|
+
// snake_case_variables
|
|
279
|
+
return new Position(lineNumber, column);
|
|
280
|
+
}
|
|
281
|
+
if (left !== 45 /* CharCode.Dash */ && right === 45 /* CharCode.Dash */) {
|
|
282
|
+
// kebab-case-variables
|
|
283
|
+
return new Position(lineNumber, column);
|
|
284
|
+
}
|
|
285
|
+
if ((isLowerAsciiLetter(left) || isAsciiDigit(left)) && isUpperAsciiLetter(right)) {
|
|
286
|
+
// camelCaseVariables
|
|
287
|
+
return new Position(lineNumber, column);
|
|
288
|
+
}
|
|
289
|
+
if (isUpperAsciiLetter(left) && isUpperAsciiLetter(right)) {
|
|
290
|
+
// thisIsACamelCaseWithOneLetterWords
|
|
291
|
+
if (column + 1 < maxColumn) {
|
|
292
|
+
const rightRight = lineContent.charCodeAt(column);
|
|
293
|
+
if (isLowerAsciiLetter(rightRight) || isAsciiDigit(rightRight)) {
|
|
294
|
+
return new Position(lineNumber, column);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return new Position(lineNumber, maxColumn);
|
|
300
|
+
}
|
|
301
|
+
static _deleteWordLeftWhitespace(model, position) {
|
|
302
|
+
const lineContent = model.getLineContent(position.lineNumber);
|
|
303
|
+
const startIndex = position.column - 2;
|
|
304
|
+
const lastNonWhitespace = lastNonWhitespaceIndex(lineContent, startIndex);
|
|
305
|
+
if (lastNonWhitespace + 1 < startIndex) {
|
|
306
|
+
return new Range(position.lineNumber, lastNonWhitespace + 2, position.lineNumber, position.column);
|
|
307
|
+
}
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
static deleteWordLeft(ctx, wordNavigationType) {
|
|
311
|
+
const wordSeparators = ctx.wordSeparators;
|
|
312
|
+
const model = ctx.model;
|
|
313
|
+
const selection = ctx.selection;
|
|
314
|
+
const whitespaceHeuristics = ctx.whitespaceHeuristics;
|
|
315
|
+
if (!selection.isEmpty()) {
|
|
316
|
+
return selection;
|
|
317
|
+
}
|
|
318
|
+
if (DeleteOperations.isAutoClosingPairDelete(ctx.autoClosingDelete, ctx.autoClosingBrackets, ctx.autoClosingQuotes, ctx.autoClosingPairs.autoClosingPairsOpenByEnd, ctx.model, [ctx.selection], ctx.autoClosedCharacters)) {
|
|
319
|
+
const position = ctx.selection.getPosition();
|
|
320
|
+
return new Range(position.lineNumber, position.column - 1, position.lineNumber, position.column + 1);
|
|
321
|
+
}
|
|
322
|
+
const position = new Position(selection.positionLineNumber, selection.positionColumn);
|
|
323
|
+
let lineNumber = position.lineNumber;
|
|
324
|
+
let column = position.column;
|
|
325
|
+
if (lineNumber === 1 && column === 1) {
|
|
326
|
+
// Ignore deleting at beginning of file
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
329
|
+
if (whitespaceHeuristics) {
|
|
330
|
+
const r = this._deleteWordLeftWhitespace(model, position);
|
|
331
|
+
if (r) {
|
|
332
|
+
return r;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
let prevWordOnLine = WordOperations._findPreviousWordOnLine(wordSeparators, model, position);
|
|
336
|
+
if (wordNavigationType === 0 /* WordNavigationType.WordStart */) {
|
|
337
|
+
if (prevWordOnLine) {
|
|
338
|
+
column = prevWordOnLine.start + 1;
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
if (column > 1) {
|
|
342
|
+
column = 1;
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
lineNumber--;
|
|
346
|
+
column = model.getLineMaxColumn(lineNumber);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
if (prevWordOnLine && column <= prevWordOnLine.end + 1) {
|
|
352
|
+
prevWordOnLine = WordOperations._findPreviousWordOnLine(wordSeparators, model, new Position(lineNumber, prevWordOnLine.start + 1));
|
|
353
|
+
}
|
|
354
|
+
if (prevWordOnLine) {
|
|
355
|
+
column = prevWordOnLine.end + 1;
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
if (column > 1) {
|
|
359
|
+
column = 1;
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
lineNumber--;
|
|
363
|
+
column = model.getLineMaxColumn(lineNumber);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return new Range(lineNumber, column, position.lineNumber, position.column);
|
|
368
|
+
}
|
|
369
|
+
static deleteInsideWord(wordSeparators, model, selection) {
|
|
370
|
+
if (!selection.isEmpty()) {
|
|
371
|
+
return selection;
|
|
372
|
+
}
|
|
373
|
+
const position = new Position(selection.positionLineNumber, selection.positionColumn);
|
|
374
|
+
const r = this._deleteInsideWordWhitespace(model, position);
|
|
375
|
+
if (r) {
|
|
376
|
+
return r;
|
|
377
|
+
}
|
|
378
|
+
return this._deleteInsideWordDetermineDeleteRange(wordSeparators, model, position);
|
|
379
|
+
}
|
|
380
|
+
static _charAtIsWhitespace(str, index) {
|
|
381
|
+
const charCode = str.charCodeAt(index);
|
|
382
|
+
return (charCode === 32 /* CharCode.Space */ || charCode === 9 /* CharCode.Tab */);
|
|
383
|
+
}
|
|
384
|
+
static _deleteInsideWordWhitespace(model, position) {
|
|
385
|
+
const lineContent = model.getLineContent(position.lineNumber);
|
|
386
|
+
const lineContentLength = lineContent.length;
|
|
387
|
+
if (lineContentLength === 0) {
|
|
388
|
+
// empty line
|
|
389
|
+
return null;
|
|
390
|
+
}
|
|
391
|
+
let leftIndex = Math.max(position.column - 2, 0);
|
|
392
|
+
if (!this._charAtIsWhitespace(lineContent, leftIndex)) {
|
|
393
|
+
// touches a non-whitespace character to the left
|
|
394
|
+
return null;
|
|
395
|
+
}
|
|
396
|
+
let rightIndex = Math.min(position.column - 1, lineContentLength - 1);
|
|
397
|
+
if (!this._charAtIsWhitespace(lineContent, rightIndex)) {
|
|
398
|
+
// touches a non-whitespace character to the right
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
// walk over whitespace to the left
|
|
402
|
+
while (leftIndex > 0 && this._charAtIsWhitespace(lineContent, leftIndex - 1)) {
|
|
403
|
+
leftIndex--;
|
|
404
|
+
}
|
|
405
|
+
// walk over whitespace to the right
|
|
406
|
+
while (rightIndex + 1 < lineContentLength && this._charAtIsWhitespace(lineContent, rightIndex + 1)) {
|
|
407
|
+
rightIndex++;
|
|
408
|
+
}
|
|
409
|
+
return new Range(position.lineNumber, leftIndex + 1, position.lineNumber, rightIndex + 2);
|
|
410
|
+
}
|
|
411
|
+
static _deleteInsideWordDetermineDeleteRange(wordSeparators, model, position) {
|
|
412
|
+
const lineContent = model.getLineContent(position.lineNumber);
|
|
413
|
+
const lineLength = lineContent.length;
|
|
414
|
+
if (lineLength === 0) {
|
|
415
|
+
// empty line
|
|
416
|
+
if (position.lineNumber > 1) {
|
|
417
|
+
return new Range(position.lineNumber - 1, model.getLineMaxColumn(position.lineNumber - 1), position.lineNumber, 1);
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
if (position.lineNumber < model.getLineCount()) {
|
|
421
|
+
return new Range(position.lineNumber, 1, position.lineNumber + 1, 1);
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
// empty model
|
|
425
|
+
return new Range(position.lineNumber, 1, position.lineNumber, 1);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
const touchesWord = (word) => {
|
|
430
|
+
return (word.start + 1 <= position.column && position.column <= word.end + 1);
|
|
431
|
+
};
|
|
432
|
+
const createRangeWithPosition = (startColumn, endColumn) => {
|
|
433
|
+
startColumn = Math.min(startColumn, position.column);
|
|
434
|
+
endColumn = Math.max(endColumn, position.column);
|
|
435
|
+
return new Range(position.lineNumber, startColumn, position.lineNumber, endColumn);
|
|
436
|
+
};
|
|
437
|
+
const deleteWordAndAdjacentWhitespace = (word) => {
|
|
438
|
+
let startColumn = word.start + 1;
|
|
439
|
+
let endColumn = word.end + 1;
|
|
440
|
+
let expandedToTheRight = false;
|
|
441
|
+
while (endColumn - 1 < lineLength && this._charAtIsWhitespace(lineContent, endColumn - 1)) {
|
|
442
|
+
expandedToTheRight = true;
|
|
443
|
+
endColumn++;
|
|
444
|
+
}
|
|
445
|
+
if (!expandedToTheRight) {
|
|
446
|
+
while (startColumn > 1 && this._charAtIsWhitespace(lineContent, startColumn - 2)) {
|
|
447
|
+
startColumn--;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return createRangeWithPosition(startColumn, endColumn);
|
|
451
|
+
};
|
|
452
|
+
const prevWordOnLine = WordOperations._findPreviousWordOnLine(wordSeparators, model, position);
|
|
453
|
+
if (prevWordOnLine && touchesWord(prevWordOnLine)) {
|
|
454
|
+
return deleteWordAndAdjacentWhitespace(prevWordOnLine);
|
|
455
|
+
}
|
|
456
|
+
const nextWordOnLine = WordOperations._findNextWordOnLine(wordSeparators, model, position);
|
|
457
|
+
if (nextWordOnLine && touchesWord(nextWordOnLine)) {
|
|
458
|
+
return deleteWordAndAdjacentWhitespace(nextWordOnLine);
|
|
459
|
+
}
|
|
460
|
+
if (prevWordOnLine && nextWordOnLine) {
|
|
461
|
+
return createRangeWithPosition(prevWordOnLine.end + 1, nextWordOnLine.start + 1);
|
|
462
|
+
}
|
|
463
|
+
if (prevWordOnLine) {
|
|
464
|
+
return createRangeWithPosition(prevWordOnLine.start + 1, prevWordOnLine.end + 1);
|
|
465
|
+
}
|
|
466
|
+
if (nextWordOnLine) {
|
|
467
|
+
return createRangeWithPosition(nextWordOnLine.start + 1, nextWordOnLine.end + 1);
|
|
468
|
+
}
|
|
469
|
+
return createRangeWithPosition(1, lineLength + 1);
|
|
470
|
+
}
|
|
471
|
+
static _deleteWordPartLeft(model, selection) {
|
|
472
|
+
if (!selection.isEmpty()) {
|
|
473
|
+
return selection;
|
|
474
|
+
}
|
|
475
|
+
const pos = selection.getPosition();
|
|
476
|
+
const toPosition = WordOperations._moveWordPartLeft(model, pos);
|
|
477
|
+
return new Range(pos.lineNumber, pos.column, toPosition.lineNumber, toPosition.column);
|
|
478
|
+
}
|
|
479
|
+
static _findFirstNonWhitespaceChar(str, startIndex) {
|
|
480
|
+
const len = str.length;
|
|
481
|
+
for (let chIndex = startIndex; chIndex < len; chIndex++) {
|
|
482
|
+
const ch = str.charAt(chIndex);
|
|
483
|
+
if (ch !== ' ' && ch !== '\t') {
|
|
484
|
+
return chIndex;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
return len;
|
|
488
|
+
}
|
|
489
|
+
static _deleteWordRightWhitespace(model, position) {
|
|
490
|
+
const lineContent = model.getLineContent(position.lineNumber);
|
|
491
|
+
const startIndex = position.column - 1;
|
|
492
|
+
const firstNonWhitespace = this._findFirstNonWhitespaceChar(lineContent, startIndex);
|
|
493
|
+
if (startIndex + 1 < firstNonWhitespace) {
|
|
494
|
+
// bingo
|
|
495
|
+
return new Range(position.lineNumber, position.column, position.lineNumber, firstNonWhitespace + 1);
|
|
496
|
+
}
|
|
497
|
+
return null;
|
|
498
|
+
}
|
|
499
|
+
static deleteWordRight(ctx, wordNavigationType) {
|
|
500
|
+
const wordSeparators = ctx.wordSeparators;
|
|
501
|
+
const model = ctx.model;
|
|
502
|
+
const selection = ctx.selection;
|
|
503
|
+
const whitespaceHeuristics = ctx.whitespaceHeuristics;
|
|
504
|
+
if (!selection.isEmpty()) {
|
|
505
|
+
return selection;
|
|
506
|
+
}
|
|
507
|
+
const position = new Position(selection.positionLineNumber, selection.positionColumn);
|
|
508
|
+
let lineNumber = position.lineNumber;
|
|
509
|
+
let column = position.column;
|
|
510
|
+
const lineCount = model.getLineCount();
|
|
511
|
+
const maxColumn = model.getLineMaxColumn(lineNumber);
|
|
512
|
+
if (lineNumber === lineCount && column === maxColumn) {
|
|
513
|
+
// Ignore deleting at end of file
|
|
514
|
+
return null;
|
|
515
|
+
}
|
|
516
|
+
if (whitespaceHeuristics) {
|
|
517
|
+
const r = this._deleteWordRightWhitespace(model, position);
|
|
518
|
+
if (r) {
|
|
519
|
+
return r;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
let nextWordOnLine = WordOperations._findNextWordOnLine(wordSeparators, model, position);
|
|
523
|
+
if (wordNavigationType === 2 /* WordNavigationType.WordEnd */) {
|
|
524
|
+
if (nextWordOnLine) {
|
|
525
|
+
column = nextWordOnLine.end + 1;
|
|
526
|
+
}
|
|
527
|
+
else {
|
|
528
|
+
if (column < maxColumn || lineNumber === lineCount) {
|
|
529
|
+
column = maxColumn;
|
|
530
|
+
}
|
|
531
|
+
else {
|
|
532
|
+
lineNumber++;
|
|
533
|
+
nextWordOnLine = WordOperations._findNextWordOnLine(wordSeparators, model, new Position(lineNumber, 1));
|
|
534
|
+
if (nextWordOnLine) {
|
|
535
|
+
column = nextWordOnLine.start + 1;
|
|
536
|
+
}
|
|
537
|
+
else {
|
|
538
|
+
column = model.getLineMaxColumn(lineNumber);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
else {
|
|
544
|
+
if (nextWordOnLine && column >= nextWordOnLine.start + 1) {
|
|
545
|
+
nextWordOnLine = WordOperations._findNextWordOnLine(wordSeparators, model, new Position(lineNumber, nextWordOnLine.end + 1));
|
|
546
|
+
}
|
|
547
|
+
if (nextWordOnLine) {
|
|
548
|
+
column = nextWordOnLine.start + 1;
|
|
549
|
+
}
|
|
550
|
+
else {
|
|
551
|
+
if (column < maxColumn || lineNumber === lineCount) {
|
|
552
|
+
column = maxColumn;
|
|
553
|
+
}
|
|
554
|
+
else {
|
|
555
|
+
lineNumber++;
|
|
556
|
+
nextWordOnLine = WordOperations._findNextWordOnLine(wordSeparators, model, new Position(lineNumber, 1));
|
|
557
|
+
if (nextWordOnLine) {
|
|
558
|
+
column = nextWordOnLine.start + 1;
|
|
559
|
+
}
|
|
560
|
+
else {
|
|
561
|
+
column = model.getLineMaxColumn(lineNumber);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
return new Range(lineNumber, column, position.lineNumber, position.column);
|
|
567
|
+
}
|
|
568
|
+
static _deleteWordPartRight(model, selection) {
|
|
569
|
+
if (!selection.isEmpty()) {
|
|
570
|
+
return selection;
|
|
571
|
+
}
|
|
572
|
+
const pos = selection.getPosition();
|
|
573
|
+
const toPosition = WordOperations._moveWordPartRight(model, pos);
|
|
574
|
+
return new Range(pos.lineNumber, pos.column, toPosition.lineNumber, toPosition.column);
|
|
575
|
+
}
|
|
576
|
+
static _createWordAtPosition(model, lineNumber, word) {
|
|
577
|
+
const range = new Range(lineNumber, word.start + 1, lineNumber, word.end + 1);
|
|
578
|
+
return {
|
|
579
|
+
word: model.getValueInRange(range),
|
|
580
|
+
startColumn: range.startColumn,
|
|
581
|
+
endColumn: range.endColumn
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
static getWordAtPosition(model, _wordSeparators, _intlSegmenterLocales, position) {
|
|
585
|
+
const wordSeparators = getMapForWordSeparators(_wordSeparators, _intlSegmenterLocales);
|
|
586
|
+
const prevWord = WordOperations._findPreviousWordOnLine(wordSeparators, model, position);
|
|
587
|
+
if (prevWord && prevWord.wordType === 1 /* WordType.Regular */ && prevWord.start <= position.column - 1 && position.column - 1 <= prevWord.end) {
|
|
588
|
+
return WordOperations._createWordAtPosition(model, position.lineNumber, prevWord);
|
|
589
|
+
}
|
|
590
|
+
const nextWord = WordOperations._findNextWordOnLine(wordSeparators, model, position);
|
|
591
|
+
if (nextWord && nextWord.wordType === 1 /* WordType.Regular */ && nextWord.start <= position.column - 1 && position.column - 1 <= nextWord.end) {
|
|
592
|
+
return WordOperations._createWordAtPosition(model, position.lineNumber, nextWord);
|
|
593
|
+
}
|
|
594
|
+
return null;
|
|
595
|
+
}
|
|
596
|
+
static word(config, model, cursor, inSelectionMode, position) {
|
|
597
|
+
const wordSeparators = getMapForWordSeparators(config.wordSeparators, config.wordSegmenterLocales);
|
|
598
|
+
const prevWord = WordOperations._findPreviousWordOnLine(wordSeparators, model, position);
|
|
599
|
+
const nextWord = WordOperations._findNextWordOnLine(wordSeparators, model, position);
|
|
600
|
+
if (!inSelectionMode) {
|
|
601
|
+
// Entering word selection for the first time
|
|
602
|
+
let startColumn;
|
|
603
|
+
let endColumn;
|
|
604
|
+
if (prevWord && prevWord.wordType === 1 /* WordType.Regular */ && prevWord.start <= position.column - 1 && position.column - 1 <= prevWord.end) {
|
|
605
|
+
// isTouchingPrevWord (Regular word)
|
|
606
|
+
startColumn = prevWord.start + 1;
|
|
607
|
+
endColumn = prevWord.end + 1;
|
|
608
|
+
}
|
|
609
|
+
else if (prevWord && prevWord.wordType === 2 /* WordType.Separator */ && prevWord.start <= position.column - 1 && position.column - 1 < prevWord.end) {
|
|
610
|
+
// isTouchingPrevWord (Separator word) - stricter check, don't include end boundary
|
|
611
|
+
startColumn = prevWord.start + 1;
|
|
612
|
+
endColumn = prevWord.end + 1;
|
|
613
|
+
}
|
|
614
|
+
else if (nextWord && nextWord.wordType === 1 /* WordType.Regular */ && nextWord.start <= position.column - 1 && position.column - 1 <= nextWord.end) {
|
|
615
|
+
// isTouchingNextWord (Regular word)
|
|
616
|
+
startColumn = nextWord.start + 1;
|
|
617
|
+
endColumn = nextWord.end + 1;
|
|
618
|
+
}
|
|
619
|
+
else if (nextWord && nextWord.wordType === 2 /* WordType.Separator */ && nextWord.start <= position.column - 1 && position.column - 1 < nextWord.end) {
|
|
620
|
+
// isTouchingNextWord (Separator word) - stricter check, don't include end boundary
|
|
621
|
+
startColumn = nextWord.start + 1;
|
|
622
|
+
endColumn = nextWord.end + 1;
|
|
623
|
+
}
|
|
624
|
+
else {
|
|
625
|
+
if (prevWord) {
|
|
626
|
+
startColumn = prevWord.end + 1;
|
|
627
|
+
}
|
|
628
|
+
else {
|
|
629
|
+
startColumn = 1;
|
|
630
|
+
}
|
|
631
|
+
if (nextWord) {
|
|
632
|
+
endColumn = nextWord.start + 1;
|
|
633
|
+
}
|
|
634
|
+
else {
|
|
635
|
+
endColumn = model.getLineMaxColumn(position.lineNumber);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
return new SingleCursorState(new Range(position.lineNumber, startColumn, position.lineNumber, endColumn), 1 /* SelectionStartKind.Word */, 0, new Position(position.lineNumber, endColumn), 0);
|
|
639
|
+
}
|
|
640
|
+
let startColumn;
|
|
641
|
+
let endColumn;
|
|
642
|
+
if (prevWord && prevWord.wordType === 1 /* WordType.Regular */ && prevWord.start < position.column - 1 && position.column - 1 < prevWord.end) {
|
|
643
|
+
// isInsidePrevWord (Regular word)
|
|
644
|
+
startColumn = prevWord.start + 1;
|
|
645
|
+
endColumn = prevWord.end + 1;
|
|
646
|
+
}
|
|
647
|
+
else if (nextWord && nextWord.wordType === 1 /* WordType.Regular */ && nextWord.start < position.column - 1 && position.column - 1 < nextWord.end) {
|
|
648
|
+
// isInsideNextWord (Regular word)
|
|
649
|
+
startColumn = nextWord.start + 1;
|
|
650
|
+
endColumn = nextWord.end + 1;
|
|
651
|
+
}
|
|
652
|
+
else {
|
|
653
|
+
startColumn = position.column;
|
|
654
|
+
endColumn = position.column;
|
|
655
|
+
}
|
|
656
|
+
const lineNumber = position.lineNumber;
|
|
657
|
+
let column;
|
|
658
|
+
if (cursor.selectionStart.containsPosition(position)) {
|
|
659
|
+
column = cursor.selectionStart.endColumn;
|
|
660
|
+
}
|
|
661
|
+
else if (position.isBeforeOrEqual(cursor.selectionStart.getStartPosition())) {
|
|
662
|
+
column = startColumn;
|
|
663
|
+
const possiblePosition = new Position(lineNumber, column);
|
|
664
|
+
if (cursor.selectionStart.containsPosition(possiblePosition)) {
|
|
665
|
+
column = cursor.selectionStart.endColumn;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
else {
|
|
669
|
+
column = endColumn;
|
|
670
|
+
const possiblePosition = new Position(lineNumber, column);
|
|
671
|
+
if (cursor.selectionStart.containsPosition(possiblePosition)) {
|
|
672
|
+
column = cursor.selectionStart.startColumn;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
return cursor.move(true, lineNumber, column, 0);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
class WordPartOperations extends WordOperations {
|
|
679
|
+
static deleteWordPartLeft(ctx) {
|
|
680
|
+
const candidates = enforceDefined([
|
|
681
|
+
WordOperations.deleteWordLeft(ctx, 0 /* WordNavigationType.WordStart */),
|
|
682
|
+
WordOperations.deleteWordLeft(ctx, 2 /* WordNavigationType.WordEnd */),
|
|
683
|
+
WordOperations._deleteWordPartLeft(ctx.model, ctx.selection)
|
|
684
|
+
]);
|
|
685
|
+
candidates.sort(Range.compareRangesUsingEnds);
|
|
686
|
+
return candidates[2];
|
|
687
|
+
}
|
|
688
|
+
static deleteWordPartRight(ctx) {
|
|
689
|
+
const candidates = enforceDefined([
|
|
690
|
+
WordOperations.deleteWordRight(ctx, 0 /* WordNavigationType.WordStart */),
|
|
691
|
+
WordOperations.deleteWordRight(ctx, 2 /* WordNavigationType.WordEnd */),
|
|
692
|
+
WordOperations._deleteWordPartRight(ctx.model, ctx.selection)
|
|
693
|
+
]);
|
|
694
|
+
candidates.sort(Range.compareRangesUsingStarts);
|
|
695
|
+
return candidates[0];
|
|
696
|
+
}
|
|
697
|
+
static moveWordPartLeft(wordSeparators, model, position, hasMulticursor) {
|
|
698
|
+
const candidates = enforceDefined([
|
|
699
|
+
WordOperations.moveWordLeft(wordSeparators, model, position, 0 /* WordNavigationType.WordStart */, hasMulticursor),
|
|
700
|
+
WordOperations.moveWordLeft(wordSeparators, model, position, 2 /* WordNavigationType.WordEnd */, hasMulticursor),
|
|
701
|
+
WordOperations._moveWordPartLeft(model, position)
|
|
702
|
+
]);
|
|
703
|
+
candidates.sort(Position.compare);
|
|
704
|
+
return candidates[2];
|
|
705
|
+
}
|
|
706
|
+
static moveWordPartRight(wordSeparators, model, position) {
|
|
707
|
+
const candidates = enforceDefined([
|
|
708
|
+
WordOperations.moveWordRight(wordSeparators, model, position, 0 /* WordNavigationType.WordStart */),
|
|
709
|
+
WordOperations.moveWordRight(wordSeparators, model, position, 2 /* WordNavigationType.WordEnd */),
|
|
710
|
+
WordOperations._moveWordPartRight(model, position)
|
|
711
|
+
]);
|
|
712
|
+
candidates.sort(Position.compare);
|
|
713
|
+
return candidates[0];
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
function enforceDefined(arr) {
|
|
717
|
+
return arr.filter(el => Boolean(el));
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
export { WordOperations, WordPartOperations };
|