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.
Files changed (237) hide show
  1. package/dist/assets/css.worker-C7FogG4G.js +93 -0
  2. package/dist/assets/editor.worker-iXcRX1Tq.js +26 -0
  3. package/dist/assets/html.worker-C8VxctEJ.js +470 -0
  4. package/dist/assets/json.worker-CMC9kgPL.js +58 -0
  5. package/dist/assets/ts.worker-CtTJ3hNN.js +67731 -0
  6. package/dist/index.d.ts +0 -6
  7. package/dist/monaco-editor11.es.js +49 -78
  8. package/dist/monaco-editor11.umd.js +1 -50
  9. package/dist/monaco.d.ts +8 -0
  10. package/dist/workers/common/initialize.js +16 -0
  11. package/dist/workers/common/workers.js +141 -0
  12. package/dist/workers/editor/common/abstractSyntaxTokenBackend.js +128 -0
  13. package/dist/workers/editor/common/abstractText.js +89 -0
  14. package/dist/workers/editor/common/ast.js +485 -0
  15. package/dist/workers/editor/common/autoIndent.js +390 -0
  16. package/dist/workers/editor/common/beforeEditPositionMapper.js +110 -0
  17. package/dist/workers/editor/common/bracketPairsImpl.js +717 -0
  18. package/dist/workers/editor/common/bracketPairsTree.js +343 -0
  19. package/dist/workers/editor/common/brackets.js +108 -0
  20. package/dist/workers/editor/common/characterClassifier.js +59 -0
  21. package/dist/workers/editor/common/characterPair.js +40 -0
  22. package/dist/workers/editor/common/colorizedBracketPairsDecorationProvider.js +97 -0
  23. package/dist/workers/editor/common/columnRange.js +35 -0
  24. package/dist/workers/editor/common/combineTextEditInfos.js +124 -0
  25. package/dist/workers/editor/common/common.js +20 -0
  26. package/dist/workers/editor/common/computeMovedLines.js +249 -0
  27. package/dist/workers/editor/common/concat23Trees.js +192 -0
  28. package/dist/workers/editor/common/contiguousMultilineTokens.js +32 -0
  29. package/dist/workers/editor/common/contiguousMultilineTokensBuilder.js +23 -0
  30. package/dist/workers/editor/common/contiguousTokensEditing.js +128 -0
  31. package/dist/workers/editor/common/contiguousTokensStore.js +207 -0
  32. package/dist/workers/editor/common/coordinatesConverter.js +51 -0
  33. package/dist/workers/editor/common/cursor.js +899 -0
  34. package/dist/workers/editor/common/cursorAtomicMoveOperations.js +145 -0
  35. package/dist/workers/editor/common/cursorCollection.js +194 -0
  36. package/dist/workers/editor/common/cursorColumnSelection.js +93 -0
  37. package/dist/workers/editor/common/cursorColumns.js +112 -0
  38. package/dist/workers/editor/common/cursorCommon.js +250 -0
  39. package/dist/workers/editor/common/cursorContext.js +15 -0
  40. package/dist/workers/editor/common/cursorDeleteOperations.js +231 -0
  41. package/dist/workers/editor/common/cursorMoveCommands.js +676 -0
  42. package/dist/workers/editor/common/cursorMoveOperations.js +290 -0
  43. package/dist/workers/editor/common/cursorTypeEditOperations.js +968 -0
  44. package/dist/workers/editor/common/cursorTypeOperations.js +173 -0
  45. package/dist/workers/editor/common/cursorUtils.js +75 -0
  46. package/dist/workers/editor/common/cursorWordOperations.js +720 -0
  47. package/dist/workers/editor/common/defaultDocumentColorsComputer.js +138 -0
  48. package/dist/workers/editor/common/defaultLinesDiffComputer.js +188 -0
  49. package/dist/workers/editor/common/diffAlgorithm.js +139 -0
  50. package/dist/workers/editor/common/diffEditor.js +38 -0
  51. package/dist/workers/editor/common/dynamicProgrammingDiffing.js +101 -0
  52. package/dist/workers/editor/common/edit.js +183 -0
  53. package/dist/workers/editor/common/editOperation.js +36 -0
  54. package/dist/workers/editor/common/editStack.js +363 -0
  55. package/dist/workers/editor/common/editorAction.js +26 -0
  56. package/dist/workers/editor/common/editorBaseApi.js +43 -0
  57. package/dist/workers/editor/common/editorColorRegistry.js +102 -0
  58. package/dist/workers/editor/common/editorCommon.js +13 -0
  59. package/dist/workers/editor/common/editorConfigurationSchema.js +338 -0
  60. package/dist/workers/editor/common/editorContextKeys.js +84 -0
  61. package/dist/workers/editor/common/editorFeatures.js +17 -0
  62. package/dist/workers/editor/common/editorOptions.js +3440 -0
  63. package/dist/workers/editor/common/editorTheme.js +23 -0
  64. package/dist/workers/editor/common/editorWebWorker.js +299 -0
  65. package/dist/workers/editor/common/editorWorker.js +9 -0
  66. package/dist/workers/editor/common/editorWorkerHost.js +15 -0
  67. package/dist/workers/editor/common/editorZoom.js +26 -0
  68. package/dist/workers/editor/common/electricCharacter.js +55 -0
  69. package/dist/workers/editor/common/encodedTokenAttributes.js +79 -0
  70. package/dist/workers/editor/common/enterAction.js +53 -0
  71. package/dist/workers/editor/common/eolCounter.js +44 -0
  72. package/dist/workers/editor/common/findSectionHeaders.js +128 -0
  73. package/dist/workers/editor/common/fixBrackets.js +67 -0
  74. package/dist/workers/editor/common/fixedArray.js +70 -0
  75. package/dist/workers/editor/common/fontInfo.js +172 -0
  76. package/dist/workers/editor/common/fontInfoFromSettings.js +29 -0
  77. package/dist/workers/editor/common/getIconClasses.js +106 -0
  78. package/dist/workers/editor/common/getPositionOffsetTransformerFromTextModel.js +24 -0
  79. package/dist/workers/editor/common/glyphLanesModel.js +61 -0
  80. package/dist/workers/editor/common/guidesTextModelPart.js +405 -0
  81. package/dist/workers/editor/common/heuristicSequenceOptimizations.js +374 -0
  82. package/dist/workers/editor/common/indentRules.js +63 -0
  83. package/dist/workers/editor/common/indentation.js +39 -0
  84. package/dist/workers/editor/common/indentationGuesser.js +178 -0
  85. package/dist/workers/editor/common/indentationLineProcessor.js +193 -0
  86. package/dist/workers/editor/common/inlineDecorations.js +26 -0
  87. package/dist/workers/editor/common/inplaceReplaceSupport.js +87 -0
  88. package/dist/workers/editor/common/inputMode.js +22 -0
  89. package/dist/workers/editor/common/intervalTree.js +1002 -0
  90. package/dist/workers/editor/common/language.js +9 -0
  91. package/dist/workers/editor/common/languageBracketsConfiguration.js +133 -0
  92. package/dist/workers/editor/common/languageConfiguration.js +138 -0
  93. package/dist/workers/editor/common/languageConfigurationRegistry.js +361 -0
  94. package/dist/workers/editor/common/languageFeatureDebounce.js +137 -0
  95. package/dist/workers/editor/common/languageFeatureRegistry.js +180 -0
  96. package/dist/workers/editor/common/languageFeatures.js +9 -0
  97. package/dist/workers/editor/common/languageFeaturesService.js +47 -0
  98. package/dist/workers/editor/common/languageSelector.js +112 -0
  99. package/dist/workers/editor/common/languageService.js +92 -0
  100. package/dist/workers/editor/common/languages.js +522 -0
  101. package/dist/workers/editor/common/languagesAssociations.js +193 -0
  102. package/dist/workers/editor/common/languagesRegistry.js +237 -0
  103. package/dist/workers/editor/common/legacyLinesDiffComputer.js +468 -0
  104. package/dist/workers/editor/common/length.js +129 -0
  105. package/dist/workers/editor/common/lineDecorations.js +208 -0
  106. package/dist/workers/editor/common/lineEdit.js +75 -0
  107. package/dist/workers/editor/common/lineHeights.js +370 -0
  108. package/dist/workers/editor/common/linePart.js +25 -0
  109. package/dist/workers/editor/common/lineRange.js +312 -0
  110. package/dist/workers/editor/common/lineSequence.js +36 -0
  111. package/dist/workers/editor/common/lineTokens.js +405 -0
  112. package/dist/workers/editor/common/linesDiffComputer.js +29 -0
  113. package/dist/workers/editor/common/linesDiffComputers.js +13 -0
  114. package/dist/workers/editor/common/linesLayout.js +765 -0
  115. package/dist/workers/editor/common/linesSliceCharSequence.js +205 -0
  116. package/dist/workers/editor/common/linkComputer.js +269 -0
  117. package/dist/workers/editor/common/markerDecorations.js +9 -0
  118. package/dist/workers/editor/common/markerDecorationsService.js +248 -0
  119. package/dist/workers/editor/common/minimapTokensColorTracker.js +58 -0
  120. package/dist/workers/editor/common/mirrorTextModel.js +117 -0
  121. package/dist/workers/editor/common/model.js +9 -0
  122. package/dist/workers/editor/common/modelLineProjection.js +350 -0
  123. package/dist/workers/editor/common/modelLineProjectionData.js +297 -0
  124. package/dist/workers/editor/common/modelService.js +413 -0
  125. package/dist/workers/editor/common/modesRegistry.js +75 -0
  126. package/dist/workers/editor/common/monospaceLineBreaksComputer.js +473 -0
  127. package/dist/workers/editor/common/myersDiffAlgorithm.js +159 -0
  128. package/dist/workers/editor/common/nodeReader.js +127 -0
  129. package/dist/workers/editor/common/nullTokenize.js +29 -0
  130. package/dist/workers/editor/common/offsetRange.js +225 -0
  131. package/dist/workers/editor/common/onEnter.js +109 -0
  132. package/dist/workers/editor/common/oneCursor.js +117 -0
  133. package/dist/workers/editor/common/overviewZoneManager.js +176 -0
  134. package/dist/workers/editor/common/parser.js +121 -0
  135. package/dist/workers/editor/common/pieceTreeBase.js +1473 -0
  136. package/dist/workers/editor/common/pieceTreeTextBuffer.js +461 -0
  137. package/dist/workers/editor/common/pieceTreeTextBufferBuilder.js +140 -0
  138. package/dist/workers/editor/common/point.js +50 -0
  139. package/dist/workers/editor/common/position.js +142 -0
  140. package/dist/workers/editor/common/positionToOffset.js +17 -0
  141. package/dist/workers/editor/common/positionToOffsetImpl.js +98 -0
  142. package/dist/workers/editor/common/prefixSumComputer.js +226 -0
  143. package/dist/workers/editor/common/range.js +421 -0
  144. package/dist/workers/editor/common/rangeMapping.js +229 -0
  145. package/dist/workers/editor/common/rangeSingleLine.js +17 -0
  146. package/dist/workers/editor/common/rbTreeBase.js +362 -0
  147. package/dist/workers/editor/common/rect.js +163 -0
  148. package/dist/workers/editor/common/replaceCommand.js +158 -0
  149. package/dist/workers/editor/common/resolverService.js +5 -0
  150. package/dist/workers/editor/common/rgba.js +35 -0
  151. package/dist/workers/editor/common/richEditBrackets.js +356 -0
  152. package/dist/workers/editor/common/selection.js +145 -0
  153. package/dist/workers/editor/common/semanticTokensDto.js +82 -0
  154. package/dist/workers/editor/common/semanticTokensProviderStyling.js +263 -0
  155. package/dist/workers/editor/common/semanticTokensStyling.js +9 -0
  156. package/dist/workers/editor/common/semanticTokensStylingService.js +47 -0
  157. package/dist/workers/editor/common/shiftCommand.js +241 -0
  158. package/dist/workers/editor/common/smallImmutableSet.js +108 -0
  159. package/dist/workers/editor/common/sparseMultilineTokens.js +548 -0
  160. package/dist/workers/editor/common/sparseTokensStore.js +210 -0
  161. package/dist/workers/editor/common/standaloneEnums.js +1017 -0
  162. package/dist/workers/editor/common/standaloneStrings.js +42 -0
  163. package/dist/workers/editor/common/stringBuilder.js +122 -0
  164. package/dist/workers/editor/common/stringEdit.js +165 -0
  165. package/dist/workers/editor/common/supports.js +58 -0
  166. package/dist/workers/editor/common/surroundSelectionCommand.js +44 -0
  167. package/dist/workers/editor/common/textChange.js +248 -0
  168. package/dist/workers/editor/common/textEdit.js +269 -0
  169. package/dist/workers/editor/common/textLength.js +87 -0
  170. package/dist/workers/editor/common/textModel.js +2031 -0
  171. package/dist/workers/editor/common/textModelBracketPairs.js +45 -0
  172. package/dist/workers/editor/common/textModelDefaults.js +18 -0
  173. package/dist/workers/editor/common/textModelEditSource.js +166 -0
  174. package/dist/workers/editor/common/textModelEvents.js +216 -0
  175. package/dist/workers/editor/common/textModelGuides.js +40 -0
  176. package/dist/workers/editor/common/textModelPart.js +23 -0
  177. package/dist/workers/editor/common/textModelSearch.js +455 -0
  178. package/dist/workers/editor/common/textModelStringEdit.js +11 -0
  179. package/dist/workers/editor/common/textModelSync.impl.js +307 -0
  180. package/dist/workers/editor/common/textModelText.js +26 -0
  181. package/dist/workers/editor/common/textModelTokens.js +436 -0
  182. package/dist/workers/editor/common/textResourceConfiguration.js +6 -0
  183. package/dist/workers/editor/common/textToHtmlTokenizer.js +139 -0
  184. package/dist/workers/editor/common/tokenStore.js +407 -0
  185. package/dist/workers/editor/common/tokenWithTextArray.js +73 -0
  186. package/dist/workers/editor/common/tokenization.js +287 -0
  187. package/dist/workers/editor/common/tokenizationRegistry.js +123 -0
  188. package/dist/workers/editor/common/tokenizationTextModelPart.js +275 -0
  189. package/dist/workers/editor/common/tokenizer.js +301 -0
  190. package/dist/workers/editor/common/tokenizerSyntaxTokenBackend.js +261 -0
  191. package/dist/workers/editor/common/treeSitterLibraryService.js +9 -0
  192. package/dist/workers/editor/common/treeSitterSyntaxTokenBackend.js +167 -0
  193. package/dist/workers/editor/common/treeSitterThemeService.js +9 -0
  194. package/dist/workers/editor/common/treeSitterTokenizationImpl.js +713 -0
  195. package/dist/workers/editor/common/treeSitterTree.js +395 -0
  196. package/dist/workers/editor/common/treeViewsDnd.js +24 -0
  197. package/dist/workers/editor/common/treeViewsDndService.js +12 -0
  198. package/dist/workers/editor/common/trimTrailingWhitespaceCommand.js +98 -0
  199. package/dist/workers/editor/common/unicodeTextModelHighlighter.js +188 -0
  200. package/dist/workers/editor/common/utils.js +62 -0
  201. package/dist/workers/editor/common/viewContext.js +22 -0
  202. package/dist/workers/editor/common/viewEventHandler.js +186 -0
  203. package/dist/workers/editor/common/viewEvents.js +180 -0
  204. package/dist/workers/editor/common/viewLayout.js +368 -0
  205. package/dist/workers/editor/common/viewLineRenderer.js +948 -0
  206. package/dist/workers/editor/common/viewLinesViewportData.js +30 -0
  207. package/dist/workers/editor/common/viewModel.js +98 -0
  208. package/dist/workers/editor/common/viewModelDecoration.js +55 -0
  209. package/dist/workers/editor/common/viewModelDecorations.js +132 -0
  210. package/dist/workers/editor/common/viewModelEventDispatcher.js +398 -0
  211. package/dist/workers/editor/common/viewModelImpl.js +1163 -0
  212. package/dist/workers/editor/common/viewModelLines.js +938 -0
  213. package/dist/workers/editor/common/wordCharacterClassifier.js +87 -0
  214. package/dist/workers/editor/common/wordHelper.js +127 -0
  215. package/dist/workers/editor/editor.worker.js +11 -0
  216. package/dist/workers/language/css.worker.js +8 -0
  217. package/dist/workers/language/cssMode.js +198 -0
  218. package/dist/workers/language/cssWorker.js +183 -0
  219. package/dist/workers/language/html.worker.js +8 -0
  220. package/dist/workers/language/htmlMode.js +213 -0
  221. package/dist/workers/language/htmlWorker.js +126 -0
  222. package/dist/workers/language/json.worker.js +8 -0
  223. package/dist/workers/language/jsonMode.js +224 -0
  224. package/dist/workers/language/jsonWorker.js +187 -0
  225. package/dist/workers/language/languageFeatures.js +1009 -0
  226. package/dist/workers/language/lib.index.js +103 -0
  227. package/dist/workers/language/lib.js +1107 -0
  228. package/dist/workers/language/lspLanguageFeatures.js +716 -0
  229. package/dist/workers/language/monaco.contribution.js +144 -0
  230. package/dist/workers/language/tokenization.js +189 -0
  231. package/dist/workers/language/ts.worker.js +14 -0
  232. package/dist/workers/language/tsMode.js +212 -0
  233. package/dist/workers/language/tsWorker.js +352 -0
  234. package/dist/workers/language/typescriptServices.js +210154 -0
  235. package/dist/workers/language/typescriptServicesMetadata.js +3 -0
  236. package/dist/workers/language/workerManager.js +65 -0
  237. package/package.json +3 -2
@@ -0,0 +1,455 @@
1
+ import { createRegExp, getNextCodePoint } from '../../../base/common/strings.js';
2
+ import { getMapForWordSeparators } from '../core/wordCharacterClassifier.js';
3
+ import { Position } from '../core/position.js';
4
+ import { Range } from '../core/range.js';
5
+ import { SearchData, FindMatch } from '../model.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
+ const LIMIT_FIND_COUNT = 999;
12
+ class SearchParams {
13
+ constructor(searchString, isRegex, matchCase, wordSeparators) {
14
+ this.searchString = searchString;
15
+ this.isRegex = isRegex;
16
+ this.matchCase = matchCase;
17
+ this.wordSeparators = wordSeparators;
18
+ }
19
+ parseSearchRequest() {
20
+ if (this.searchString === '') {
21
+ return null;
22
+ }
23
+ // Try to create a RegExp out of the params
24
+ let multiline;
25
+ if (this.isRegex) {
26
+ multiline = isMultilineRegexSource(this.searchString);
27
+ }
28
+ else {
29
+ multiline = (this.searchString.indexOf('\n') >= 0);
30
+ }
31
+ let regex = null;
32
+ try {
33
+ regex = createRegExp(this.searchString, this.isRegex, {
34
+ matchCase: this.matchCase,
35
+ wholeWord: false,
36
+ multiline: multiline,
37
+ global: true,
38
+ unicode: true
39
+ });
40
+ }
41
+ catch (err) {
42
+ return null;
43
+ }
44
+ if (!regex) {
45
+ return null;
46
+ }
47
+ let canUseSimpleSearch = (!this.isRegex && !multiline);
48
+ if (canUseSimpleSearch && this.searchString.toLowerCase() !== this.searchString.toUpperCase()) {
49
+ // casing might make a difference
50
+ canUseSimpleSearch = this.matchCase;
51
+ }
52
+ return new SearchData(regex, this.wordSeparators ? getMapForWordSeparators(this.wordSeparators, []) : null, canUseSimpleSearch ? this.searchString : null);
53
+ }
54
+ }
55
+ function isMultilineRegexSource(searchString) {
56
+ if (!searchString || searchString.length === 0) {
57
+ return false;
58
+ }
59
+ for (let i = 0, len = searchString.length; i < len; i++) {
60
+ const chCode = searchString.charCodeAt(i);
61
+ if (chCode === 10 /* CharCode.LineFeed */) {
62
+ return true;
63
+ }
64
+ if (chCode === 92 /* CharCode.Backslash */) {
65
+ // move to next char
66
+ i++;
67
+ if (i >= len) {
68
+ // string ends with a \
69
+ break;
70
+ }
71
+ const nextChCode = searchString.charCodeAt(i);
72
+ if (nextChCode === 110 /* CharCode.n */ || nextChCode === 114 /* CharCode.r */ || nextChCode === 87 /* CharCode.W */) {
73
+ return true;
74
+ }
75
+ }
76
+ }
77
+ return false;
78
+ }
79
+ function createFindMatch(range, rawMatches, captureMatches) {
80
+ if (!captureMatches) {
81
+ return new FindMatch(range, null);
82
+ }
83
+ const matches = [];
84
+ for (let i = 0, len = rawMatches.length; i < len; i++) {
85
+ matches[i] = rawMatches[i];
86
+ }
87
+ return new FindMatch(range, matches);
88
+ }
89
+ class LineFeedCounter {
90
+ constructor(text) {
91
+ const lineFeedsOffsets = [];
92
+ let lineFeedsOffsetsLen = 0;
93
+ for (let i = 0, textLen = text.length; i < textLen; i++) {
94
+ if (text.charCodeAt(i) === 10 /* CharCode.LineFeed */) {
95
+ lineFeedsOffsets[lineFeedsOffsetsLen++] = i;
96
+ }
97
+ }
98
+ this._lineFeedsOffsets = lineFeedsOffsets;
99
+ }
100
+ findLineFeedCountBeforeOffset(offset) {
101
+ const lineFeedsOffsets = this._lineFeedsOffsets;
102
+ let min = 0;
103
+ let max = lineFeedsOffsets.length - 1;
104
+ if (max === -1) {
105
+ // no line feeds
106
+ return 0;
107
+ }
108
+ if (offset <= lineFeedsOffsets[0]) {
109
+ // before first line feed
110
+ return 0;
111
+ }
112
+ while (min < max) {
113
+ const mid = min + ((max - min) / 2 >> 0);
114
+ if (lineFeedsOffsets[mid] >= offset) {
115
+ max = mid - 1;
116
+ }
117
+ else {
118
+ if (lineFeedsOffsets[mid + 1] >= offset) {
119
+ // bingo!
120
+ min = mid;
121
+ max = mid;
122
+ }
123
+ else {
124
+ min = mid + 1;
125
+ }
126
+ }
127
+ }
128
+ return min + 1;
129
+ }
130
+ }
131
+ class TextModelSearch {
132
+ static findMatches(model, searchParams, searchRange, captureMatches, limitResultCount) {
133
+ const searchData = searchParams.parseSearchRequest();
134
+ if (!searchData) {
135
+ return [];
136
+ }
137
+ if (searchData.regex.multiline) {
138
+ return this._doFindMatchesMultiline(model, searchRange, new Searcher(searchData.wordSeparators, searchData.regex), captureMatches, limitResultCount);
139
+ }
140
+ return this._doFindMatchesLineByLine(model, searchRange, searchData, captureMatches, limitResultCount);
141
+ }
142
+ /**
143
+ * Multiline search always executes on the lines concatenated with \n.
144
+ * We must therefore compensate for the count of \n in case the model is CRLF
145
+ */
146
+ static _getMultilineMatchRange(model, deltaOffset, text, lfCounter, matchIndex, match0) {
147
+ let startOffset;
148
+ let lineFeedCountBeforeMatch = 0;
149
+ if (lfCounter) {
150
+ lineFeedCountBeforeMatch = lfCounter.findLineFeedCountBeforeOffset(matchIndex);
151
+ startOffset = deltaOffset + matchIndex + lineFeedCountBeforeMatch /* add as many \r as there were \n */;
152
+ }
153
+ else {
154
+ startOffset = deltaOffset + matchIndex;
155
+ }
156
+ let endOffset;
157
+ if (lfCounter) {
158
+ const lineFeedCountBeforeEndOfMatch = lfCounter.findLineFeedCountBeforeOffset(matchIndex + match0.length);
159
+ const lineFeedCountInMatch = lineFeedCountBeforeEndOfMatch - lineFeedCountBeforeMatch;
160
+ endOffset = startOffset + match0.length + lineFeedCountInMatch /* add as many \r as there were \n */;
161
+ }
162
+ else {
163
+ endOffset = startOffset + match0.length;
164
+ }
165
+ const startPosition = model.getPositionAt(startOffset);
166
+ const endPosition = model.getPositionAt(endOffset);
167
+ return new Range(startPosition.lineNumber, startPosition.column, endPosition.lineNumber, endPosition.column);
168
+ }
169
+ static _doFindMatchesMultiline(model, searchRange, searcher, captureMatches, limitResultCount) {
170
+ const deltaOffset = model.getOffsetAt(searchRange.getStartPosition());
171
+ // We always execute multiline search over the lines joined with \n
172
+ // This makes it that \n will match the EOL for both CRLF and LF models
173
+ // We compensate for offset errors in `_getMultilineMatchRange`
174
+ const text = model.getValueInRange(searchRange, 1 /* EndOfLinePreference.LF */);
175
+ const lfCounter = (model.getEOL() === '\r\n' ? new LineFeedCounter(text) : null);
176
+ const result = [];
177
+ let counter = 0;
178
+ let m;
179
+ searcher.reset(0);
180
+ while ((m = searcher.next(text))) {
181
+ result[counter++] = createFindMatch(this._getMultilineMatchRange(model, deltaOffset, text, lfCounter, m.index, m[0]), m, captureMatches);
182
+ if (counter >= limitResultCount) {
183
+ return result;
184
+ }
185
+ }
186
+ return result;
187
+ }
188
+ static _doFindMatchesLineByLine(model, searchRange, searchData, captureMatches, limitResultCount) {
189
+ const result = [];
190
+ let resultLen = 0;
191
+ // Early case for a search range that starts & stops on the same line number
192
+ if (searchRange.startLineNumber === searchRange.endLineNumber) {
193
+ const text = model.getLineContent(searchRange.startLineNumber).substring(searchRange.startColumn - 1, searchRange.endColumn - 1);
194
+ resultLen = this._findMatchesInLine(searchData, text, searchRange.startLineNumber, searchRange.startColumn - 1, resultLen, result, captureMatches, limitResultCount);
195
+ return result;
196
+ }
197
+ // Collect results from first line
198
+ const text = model.getLineContent(searchRange.startLineNumber).substring(searchRange.startColumn - 1);
199
+ resultLen = this._findMatchesInLine(searchData, text, searchRange.startLineNumber, searchRange.startColumn - 1, resultLen, result, captureMatches, limitResultCount);
200
+ // Collect results from middle lines
201
+ for (let lineNumber = searchRange.startLineNumber + 1; lineNumber < searchRange.endLineNumber && resultLen < limitResultCount; lineNumber++) {
202
+ resultLen = this._findMatchesInLine(searchData, model.getLineContent(lineNumber), lineNumber, 0, resultLen, result, captureMatches, limitResultCount);
203
+ }
204
+ // Collect results from last line
205
+ if (resultLen < limitResultCount) {
206
+ const text = model.getLineContent(searchRange.endLineNumber).substring(0, searchRange.endColumn - 1);
207
+ resultLen = this._findMatchesInLine(searchData, text, searchRange.endLineNumber, 0, resultLen, result, captureMatches, limitResultCount);
208
+ }
209
+ return result;
210
+ }
211
+ static _findMatchesInLine(searchData, text, lineNumber, deltaOffset, resultLen, result, captureMatches, limitResultCount) {
212
+ const wordSeparators = searchData.wordSeparators;
213
+ if (!captureMatches && searchData.simpleSearch) {
214
+ const searchString = searchData.simpleSearch;
215
+ const searchStringLen = searchString.length;
216
+ const textLength = text.length;
217
+ let lastMatchIndex = -searchStringLen;
218
+ while ((lastMatchIndex = text.indexOf(searchString, lastMatchIndex + searchStringLen)) !== -1) {
219
+ if (!wordSeparators || isValidMatch(wordSeparators, text, textLength, lastMatchIndex, searchStringLen)) {
220
+ result[resultLen++] = new FindMatch(new Range(lineNumber, lastMatchIndex + 1 + deltaOffset, lineNumber, lastMatchIndex + 1 + searchStringLen + deltaOffset), null);
221
+ if (resultLen >= limitResultCount) {
222
+ return resultLen;
223
+ }
224
+ }
225
+ }
226
+ return resultLen;
227
+ }
228
+ const searcher = new Searcher(searchData.wordSeparators, searchData.regex);
229
+ let m;
230
+ // Reset regex to search from the beginning
231
+ searcher.reset(0);
232
+ do {
233
+ m = searcher.next(text);
234
+ if (m) {
235
+ result[resultLen++] = createFindMatch(new Range(lineNumber, m.index + 1 + deltaOffset, lineNumber, m.index + 1 + m[0].length + deltaOffset), m, captureMatches);
236
+ if (resultLen >= limitResultCount) {
237
+ return resultLen;
238
+ }
239
+ }
240
+ } while (m);
241
+ return resultLen;
242
+ }
243
+ static findNextMatch(model, searchParams, searchStart, captureMatches) {
244
+ const searchData = searchParams.parseSearchRequest();
245
+ if (!searchData) {
246
+ return null;
247
+ }
248
+ const searcher = new Searcher(searchData.wordSeparators, searchData.regex);
249
+ if (searchData.regex.multiline) {
250
+ return this._doFindNextMatchMultiline(model, searchStart, searcher, captureMatches);
251
+ }
252
+ return this._doFindNextMatchLineByLine(model, searchStart, searcher, captureMatches);
253
+ }
254
+ static _doFindNextMatchMultiline(model, searchStart, searcher, captureMatches) {
255
+ const searchTextStart = new Position(searchStart.lineNumber, 1);
256
+ const deltaOffset = model.getOffsetAt(searchTextStart);
257
+ const lineCount = model.getLineCount();
258
+ // We always execute multiline search over the lines joined with \n
259
+ // This makes it that \n will match the EOL for both CRLF and LF models
260
+ // We compensate for offset errors in `_getMultilineMatchRange`
261
+ const text = model.getValueInRange(new Range(searchTextStart.lineNumber, searchTextStart.column, lineCount, model.getLineMaxColumn(lineCount)), 1 /* EndOfLinePreference.LF */);
262
+ const lfCounter = (model.getEOL() === '\r\n' ? new LineFeedCounter(text) : null);
263
+ searcher.reset(searchStart.column - 1);
264
+ const m = searcher.next(text);
265
+ if (m) {
266
+ return createFindMatch(this._getMultilineMatchRange(model, deltaOffset, text, lfCounter, m.index, m[0]), m, captureMatches);
267
+ }
268
+ if (searchStart.lineNumber !== 1 || searchStart.column !== 1) {
269
+ // Try again from the top
270
+ return this._doFindNextMatchMultiline(model, new Position(1, 1), searcher, captureMatches);
271
+ }
272
+ return null;
273
+ }
274
+ static _doFindNextMatchLineByLine(model, searchStart, searcher, captureMatches) {
275
+ const lineCount = model.getLineCount();
276
+ const startLineNumber = searchStart.lineNumber;
277
+ // Look in first line
278
+ const text = model.getLineContent(startLineNumber);
279
+ const r = this._findFirstMatchInLine(searcher, text, startLineNumber, searchStart.column, captureMatches);
280
+ if (r) {
281
+ return r;
282
+ }
283
+ for (let i = 1; i <= lineCount; i++) {
284
+ const lineIndex = (startLineNumber + i - 1) % lineCount;
285
+ const text = model.getLineContent(lineIndex + 1);
286
+ const r = this._findFirstMatchInLine(searcher, text, lineIndex + 1, 1, captureMatches);
287
+ if (r) {
288
+ return r;
289
+ }
290
+ }
291
+ return null;
292
+ }
293
+ static _findFirstMatchInLine(searcher, text, lineNumber, fromColumn, captureMatches) {
294
+ // Set regex to search from column
295
+ searcher.reset(fromColumn - 1);
296
+ const m = searcher.next(text);
297
+ if (m) {
298
+ return createFindMatch(new Range(lineNumber, m.index + 1, lineNumber, m.index + 1 + m[0].length), m, captureMatches);
299
+ }
300
+ return null;
301
+ }
302
+ static findPreviousMatch(model, searchParams, searchStart, captureMatches) {
303
+ const searchData = searchParams.parseSearchRequest();
304
+ if (!searchData) {
305
+ return null;
306
+ }
307
+ const searcher = new Searcher(searchData.wordSeparators, searchData.regex);
308
+ if (searchData.regex.multiline) {
309
+ return this._doFindPreviousMatchMultiline(model, searchStart, searcher, captureMatches);
310
+ }
311
+ return this._doFindPreviousMatchLineByLine(model, searchStart, searcher, captureMatches);
312
+ }
313
+ static _doFindPreviousMatchMultiline(model, searchStart, searcher, captureMatches) {
314
+ const matches = this._doFindMatchesMultiline(model, new Range(1, 1, searchStart.lineNumber, searchStart.column), searcher, captureMatches, 10 * LIMIT_FIND_COUNT);
315
+ if (matches.length > 0) {
316
+ return matches[matches.length - 1];
317
+ }
318
+ const lineCount = model.getLineCount();
319
+ if (searchStart.lineNumber !== lineCount || searchStart.column !== model.getLineMaxColumn(lineCount)) {
320
+ // Try again with all content
321
+ return this._doFindPreviousMatchMultiline(model, new Position(lineCount, model.getLineMaxColumn(lineCount)), searcher, captureMatches);
322
+ }
323
+ return null;
324
+ }
325
+ static _doFindPreviousMatchLineByLine(model, searchStart, searcher, captureMatches) {
326
+ const lineCount = model.getLineCount();
327
+ const startLineNumber = searchStart.lineNumber;
328
+ // Look in first line
329
+ const text = model.getLineContent(startLineNumber).substring(0, searchStart.column - 1);
330
+ const r = this._findLastMatchInLine(searcher, text, startLineNumber, captureMatches);
331
+ if (r) {
332
+ return r;
333
+ }
334
+ for (let i = 1; i <= lineCount; i++) {
335
+ const lineIndex = (lineCount + startLineNumber - i - 1) % lineCount;
336
+ const text = model.getLineContent(lineIndex + 1);
337
+ const r = this._findLastMatchInLine(searcher, text, lineIndex + 1, captureMatches);
338
+ if (r) {
339
+ return r;
340
+ }
341
+ }
342
+ return null;
343
+ }
344
+ static _findLastMatchInLine(searcher, text, lineNumber, captureMatches) {
345
+ let bestResult = null;
346
+ let m;
347
+ searcher.reset(0);
348
+ while ((m = searcher.next(text))) {
349
+ bestResult = createFindMatch(new Range(lineNumber, m.index + 1, lineNumber, m.index + 1 + m[0].length), m, captureMatches);
350
+ }
351
+ return bestResult;
352
+ }
353
+ }
354
+ function leftIsWordBounday(wordSeparators, text, textLength, matchStartIndex, matchLength) {
355
+ if (matchStartIndex === 0) {
356
+ // Match starts at start of string
357
+ return true;
358
+ }
359
+ const charBefore = text.charCodeAt(matchStartIndex - 1);
360
+ if (wordSeparators.get(charBefore) !== 0 /* WordCharacterClass.Regular */) {
361
+ // The character before the match is a word separator
362
+ return true;
363
+ }
364
+ if (charBefore === 13 /* CharCode.CarriageReturn */ || charBefore === 10 /* CharCode.LineFeed */) {
365
+ // The character before the match is line break or carriage return.
366
+ return true;
367
+ }
368
+ if (matchLength > 0) {
369
+ const firstCharInMatch = text.charCodeAt(matchStartIndex);
370
+ if (wordSeparators.get(firstCharInMatch) !== 0 /* WordCharacterClass.Regular */) {
371
+ // The first character inside the match is a word separator
372
+ return true;
373
+ }
374
+ }
375
+ return false;
376
+ }
377
+ function rightIsWordBounday(wordSeparators, text, textLength, matchStartIndex, matchLength) {
378
+ if (matchStartIndex + matchLength === textLength) {
379
+ // Match ends at end of string
380
+ return true;
381
+ }
382
+ const charAfter = text.charCodeAt(matchStartIndex + matchLength);
383
+ if (wordSeparators.get(charAfter) !== 0 /* WordCharacterClass.Regular */) {
384
+ // The character after the match is a word separator
385
+ return true;
386
+ }
387
+ if (charAfter === 13 /* CharCode.CarriageReturn */ || charAfter === 10 /* CharCode.LineFeed */) {
388
+ // The character after the match is line break or carriage return.
389
+ return true;
390
+ }
391
+ if (matchLength > 0) {
392
+ const lastCharInMatch = text.charCodeAt(matchStartIndex + matchLength - 1);
393
+ if (wordSeparators.get(lastCharInMatch) !== 0 /* WordCharacterClass.Regular */) {
394
+ // The last character in the match is a word separator
395
+ return true;
396
+ }
397
+ }
398
+ return false;
399
+ }
400
+ function isValidMatch(wordSeparators, text, textLength, matchStartIndex, matchLength) {
401
+ return (leftIsWordBounday(wordSeparators, text, textLength, matchStartIndex, matchLength)
402
+ && rightIsWordBounday(wordSeparators, text, textLength, matchStartIndex, matchLength));
403
+ }
404
+ class Searcher {
405
+ constructor(wordSeparators, searchRegex) {
406
+ this._wordSeparators = wordSeparators;
407
+ this._searchRegex = searchRegex;
408
+ this._prevMatchStartIndex = -1;
409
+ this._prevMatchLength = 0;
410
+ }
411
+ reset(lastIndex) {
412
+ this._searchRegex.lastIndex = lastIndex;
413
+ this._prevMatchStartIndex = -1;
414
+ this._prevMatchLength = 0;
415
+ }
416
+ next(text) {
417
+ const textLength = text.length;
418
+ let m;
419
+ do {
420
+ if (this._prevMatchStartIndex + this._prevMatchLength === textLength) {
421
+ // Reached the end of the line
422
+ return null;
423
+ }
424
+ m = this._searchRegex.exec(text);
425
+ if (!m) {
426
+ return null;
427
+ }
428
+ const matchStartIndex = m.index;
429
+ const matchLength = m[0].length;
430
+ if (matchStartIndex === this._prevMatchStartIndex && matchLength === this._prevMatchLength) {
431
+ if (matchLength === 0) {
432
+ // the search result is an empty string and won't advance `regex.lastIndex`, so `regex.exec` will stuck here
433
+ // we attempt to recover from that by advancing by two if surrogate pair found and by one otherwise
434
+ if (getNextCodePoint(text, textLength, this._searchRegex.lastIndex) > 0xFFFF) {
435
+ this._searchRegex.lastIndex += 2;
436
+ }
437
+ else {
438
+ this._searchRegex.lastIndex += 1;
439
+ }
440
+ continue;
441
+ }
442
+ // Exit early if the regex matches the same range twice
443
+ return null;
444
+ }
445
+ this._prevMatchStartIndex = matchStartIndex;
446
+ this._prevMatchLength = matchLength;
447
+ if (!this._wordSeparators || isValidMatch(this._wordSeparators, text, textLength, matchStartIndex, matchLength)) {
448
+ return m;
449
+ }
450
+ } while (m);
451
+ return null;
452
+ }
453
+ }
454
+
455
+ export { SearchParams, Searcher, TextModelSearch, createFindMatch, isMultilineRegexSource, isValidMatch };
@@ -0,0 +1,11 @@
1
+ import { StringReplacement, StringEdit } from '../core/edits/stringEdit.js';
2
+ import { OffsetRange } from '../core/ranges/offsetRange.js';
3
+
4
+ function offsetEditFromContentChanges(contentChanges) {
5
+ const editsArr = contentChanges.map(c => new StringReplacement(OffsetRange.ofStartAndLength(c.rangeOffset, c.rangeLength), c.text));
6
+ editsArr.reverse();
7
+ const edits = new StringEdit(editsArr);
8
+ return edits;
9
+ }
10
+
11
+ export { offsetEditFromContentChanges };