@codingame/monaco-vscode-notebook-service-override 8.0.4 → 9.0.2

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 (58) hide show
  1. package/package.json +3 -2
  2. package/vscode/src/vs/workbench/contrib/codeEditor/browser/emptyTextEditorHint/emptyTextEditorHint.js +8 -8
  3. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellCommands/cellCommands.js +21 -21
  4. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellDiagnostics/cellDiagnosticsActions.js +2 -2
  5. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellDiagnostics/diagnosticCellStatusBarContrib.js +1 -1
  6. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/statusBarProviders.js +3 -3
  7. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/clipboard/notebookClipboard.js +6 -6
  8. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/editorStatusBar/editorStatusBar.js +26 -24
  9. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFind.js +2 -2
  10. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/format/formatting.js +4 -4
  11. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/gettingStarted/notebookGettingStarted.js +1 -1
  12. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/layout/layoutActions.js +1 -1
  13. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/multicursor/notebookMulticursor.js +624 -0
  14. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/navigation/arrow.js +13 -13
  15. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariables.js +1 -1
  16. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesDataSource.js +1 -1
  17. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesTree.js +4 -5
  18. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView.js +1 -1
  19. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/outline/notebookOutline.js +9 -9
  20. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/profile/notebookProfile.js +1 -1
  21. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants.js +12 -12
  22. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/troubleshoot/layout.js +3 -3
  23. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/chat/cellChatActions.js +24 -24
  24. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/editActions.js +54 -55
  25. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/executeActions.js +22 -22
  26. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/insertCellActions.js +24 -24
  27. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/layoutActions.js +23 -21
  28. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/notebookIndentationActions.js +7 -7
  29. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/sectionActions.js +12 -12
  30. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffActions.js +297 -21
  31. package/vscode/src/vs/workbench/contrib/notebook/browser/notebook.contribution.js +124 -73
  32. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookAccessibilityHelp.js +27 -19
  33. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookExtensionPoint.js +33 -33
  34. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookEditorServiceImpl.js +62 -39
  35. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookExecutionServiceImpl.js +7 -6
  36. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKernelHistoryServiceImpl.js +1 -1
  37. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKeymapServiceImpl.js +3 -3
  38. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookLoggingServiceImpl.js +7 -1
  39. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookServiceImpl.js +18 -6
  40. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookWorkerServiceImpl.js +15 -40
  41. package/vscode/src/vs/workbench/contrib/notebook/browser/viewModel/notebookOutlineEntryFactory.js +0 -1
  42. package/vscode/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.js +28 -0
  43. package/vscode/src/vs/workbench/contrib/notebook/common/notebookEditorModelResolverServiceImpl.js +55 -45
  44. package/vscode/src/vs/workbench/contrib/notebook/common/services/notebookSimpleWorker.js +6 -6
  45. package/vscode/src/vs/workbench/services/workingCopy/common/fileWorkingCopyManager.js +12 -12
  46. package/vscode/src/vs/workbench/services/workingCopy/common/storedFileWorkingCopyManager.js +1 -1
  47. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffCellEditorOptions.js +0 -47
  48. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffComponents.js +0 -1303
  49. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffElementOutputs.js +0 -267
  50. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffElementViewModel.js +0 -569
  51. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffNestedCellViewModel.js +0 -115
  52. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/eventDispatcher.js +0 -39
  53. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiff.css.js +0 -6
  54. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.js +0 -903
  55. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser.js +0 -13
  56. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffList.js +0 -397
  57. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffOverviewRuler.js +0 -186
  58. package/vscode/src/vs/workbench/contrib/notebook/common/notebookDiffEditorInput.js +0 -107
@@ -0,0 +1,624 @@
1
+ import { __decorate, __param } from 'vscode/external/tslib/tslib.es6.js';
2
+ import { localize } from 'vscode/vscode/vs/nls';
3
+ import { Emitter } from 'vscode/vscode/vs/base/common/event';
4
+ import { KeyMod, KeyCode } from 'vscode/vscode/vs/base/common/keyCodes';
5
+ import { Disposable, DisposableStore } from 'vscode/vscode/vs/base/common/lifecycle';
6
+ import { ResourceMap } from 'vscode/vscode/vs/base/common/map';
7
+ import { EditorConfiguration } from 'vscode/vscode/vs/editor/browser/config/editorConfiguration';
8
+ import { CodeEditorWidget } from 'vscode/vscode/vs/editor/browser/widget/codeEditor/codeEditorWidget';
9
+ import { Selection, SelectionDirection } from 'vscode/vscode/vs/editor/common/core/selection';
10
+ import { USUAL_WORD_SEPARATORS } from 'vscode/vscode/vs/editor/common/core/wordHelper';
11
+ import { CursorsController, CommandExecutor } from 'vscode/vscode/vs/editor/common/cursor/cursor';
12
+ import { DeleteOperations } from 'vscode/vscode/vs/editor/common/cursor/cursorDeleteOperations';
13
+ import { CursorConfiguration } from 'vscode/vscode/vs/editor/common/cursorCommon';
14
+ import { CursorChangeReason } from 'vscode/vscode/vs/editor/common/cursorEvents';
15
+ import { ILanguageConfigurationService } from 'vscode/vscode/vs/editor/common/languages/languageConfigurationRegistry';
16
+ import { indentOfLine } from 'vscode/vscode/vs/editor/common/model/textModel';
17
+ import { ITextModelService } from 'vscode/vscode/vs/editor/common/services/resolverService';
18
+ import { ViewModelEventsCollector } from 'vscode/vscode/vs/editor/common/viewModelEventDispatcher';
19
+ import { IAccessibilityService } from 'vscode/vscode/vs/platform/accessibility/common/accessibility.service';
20
+ import { MenuId, registerAction2 } from 'vscode/vscode/vs/platform/actions/common/actions';
21
+ import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration.service';
22
+ import { RawContextKey, ContextKeyExpr } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
23
+ import { IContextKeyService } from 'vscode/vscode/vs/platform/contextkey/common/contextkey.service';
24
+ import { KeybindingWeight } from 'vscode/vscode/vs/platform/keybinding/common/keybindingsRegistry';
25
+ import { UndoRedoElementType } from 'vscode/vscode/vs/platform/undoRedo/common/undoRedo';
26
+ import { IUndoRedoService } from 'vscode/vscode/vs/platform/undoRedo/common/undoRedo.service';
27
+ import { NotebookAction } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/controller/coreActions';
28
+ import { getNotebookEditorFromEditorPane } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/notebookBrowser';
29
+ import { registerNotebookContribution } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/notebookEditorExtensions';
30
+ import { CellEditorOptions } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/view/cellParts/cellEditorOptions';
31
+ import { NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_CELL_EDITOR_FOCUSED } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookContextKeys';
32
+ import { IEditorService } from 'vscode/vscode/vs/workbench/services/editor/common/editorService.service';
33
+ import { UndoCommand, RedoCommand } from 'vscode/vscode/vs/editor/browser/editorExtensions';
34
+ import { registerWorkbenchContribution2, WorkbenchPhase } from 'vscode/vscode/vs/workbench/common/contributions';
35
+
36
+ const NOTEBOOK_ADD_FIND_MATCH_TO_SELECTION_ID = 'notebook.addFindMatchToSelection';
37
+ var NotebookMultiCursorState;
38
+ ( ((function(NotebookMultiCursorState) {
39
+ NotebookMultiCursorState[NotebookMultiCursorState["Idle"] = 0] = "Idle";
40
+ NotebookMultiCursorState[NotebookMultiCursorState["Selecting"] = 1] = "Selecting";
41
+ NotebookMultiCursorState[NotebookMultiCursorState["Editing"] = 2] = "Editing";
42
+ })(NotebookMultiCursorState || (NotebookMultiCursorState = {}))));
43
+ const NOTEBOOK_MULTI_SELECTION_CONTEXT = {
44
+ IsNotebookMultiSelect: ( (new RawContextKey('isNotebookMultiSelect', false))),
45
+ NotebookMultiSelectState: ( (new RawContextKey('notebookMultiSelectState', NotebookMultiCursorState.Idle))),
46
+ };
47
+ let NotebookMultiCursorController = class NotebookMultiCursorController extends Disposable {
48
+ static { this.id = 'notebook.multiCursorController'; }
49
+ constructor(notebookEditor, contextKeyService, textModelService, languageConfigurationService, accessibilityService, configurationService, undoRedoService) {
50
+ super();
51
+ this.notebookEditor = notebookEditor;
52
+ this.contextKeyService = contextKeyService;
53
+ this.textModelService = textModelService;
54
+ this.languageConfigurationService = languageConfigurationService;
55
+ this.accessibilityService = accessibilityService;
56
+ this.configurationService = configurationService;
57
+ this.undoRedoService = undoRedoService;
58
+ this.state = NotebookMultiCursorState.Idle;
59
+ this.word = '';
60
+ this.trackedMatches = [];
61
+ this._onDidChangeAnchorCell = this._register(( (new Emitter())));
62
+ this.onDidChangeAnchorCell = this._onDidChangeAnchorCell.event;
63
+ this.anchorDisposables = this._register(( (new DisposableStore())));
64
+ this.cursorsDisposables = this._register(( (new DisposableStore())));
65
+ this.cursorsControllers = ( (new ResourceMap()));
66
+ this._nbIsMultiSelectSession = NOTEBOOK_MULTI_SELECTION_CONTEXT.IsNotebookMultiSelect.bindTo(this.contextKeyService);
67
+ this._nbMultiSelectState = NOTEBOOK_MULTI_SELECTION_CONTEXT.NotebookMultiSelectState.bindTo(this.contextKeyService);
68
+ if (!this.configurationService.getValue('notebook.multiSelect.enabled')) {
69
+ return;
70
+ }
71
+ this.anchorCell = this.notebookEditor.activeCellAndCodeEditor;
72
+ this._register(this.onDidChangeAnchorCell(() => {
73
+ this.updateCursorsControllers();
74
+ this.updateAnchorListeners();
75
+ }));
76
+ }
77
+ updateCursorsControllers() {
78
+ this.cursorsDisposables.clear();
79
+ this.trackedMatches.forEach(async (match) => {
80
+ const textModelRef = await this.textModelService.createModelReference(match.cellViewModel.uri);
81
+ const textModel = textModelRef.object.textEditorModel;
82
+ if (!textModel) {
83
+ return;
84
+ }
85
+ const cursorSimpleModel = this.constructCursorSimpleModel(match.cellViewModel);
86
+ const converter = this.constructCoordinatesConverter();
87
+ const editorConfig = match.config;
88
+ const controller = this.cursorsDisposables.add(( (new CursorsController(
89
+ textModel,
90
+ cursorSimpleModel,
91
+ converter,
92
+ (new CursorConfiguration(
93
+ textModel.getLanguageId(),
94
+ textModel.getOptions(),
95
+ editorConfig,
96
+ this.languageConfigurationService
97
+ ))
98
+ ))));
99
+ controller.setSelections(( (new ViewModelEventsCollector())), undefined, match.wordSelections, CursorChangeReason.Explicit);
100
+ this.cursorsControllers.set(match.cellViewModel.uri, controller);
101
+ });
102
+ }
103
+ constructCoordinatesConverter() {
104
+ return {
105
+ convertViewPositionToModelPosition(viewPosition) {
106
+ return viewPosition;
107
+ },
108
+ convertViewRangeToModelRange(viewRange) {
109
+ return viewRange;
110
+ },
111
+ validateViewPosition(viewPosition, expectedModelPosition) {
112
+ return viewPosition;
113
+ },
114
+ validateViewRange(viewRange, expectedModelRange) {
115
+ return viewRange;
116
+ },
117
+ convertModelPositionToViewPosition(modelPosition, affinity, allowZeroLineNumber, belowHiddenRanges) {
118
+ return modelPosition;
119
+ },
120
+ convertModelRangeToViewRange(modelRange, affinity) {
121
+ return modelRange;
122
+ },
123
+ modelPositionIsVisible(modelPosition) {
124
+ return true;
125
+ },
126
+ getModelLineViewLineCount(modelLineNumber) {
127
+ return 1;
128
+ },
129
+ getViewLineNumberOfModelPosition(modelLineNumber, modelColumn) {
130
+ return modelLineNumber;
131
+ }
132
+ };
133
+ }
134
+ constructCursorSimpleModel(cell) {
135
+ return {
136
+ getLineCount() {
137
+ return cell.textBuffer.getLineCount();
138
+ },
139
+ getLineContent(lineNumber) {
140
+ return cell.textBuffer.getLineContent(lineNumber);
141
+ },
142
+ getLineMinColumn(lineNumber) {
143
+ return cell.textBuffer.getLineMinColumn(lineNumber);
144
+ },
145
+ getLineMaxColumn(lineNumber) {
146
+ return cell.textBuffer.getLineMaxColumn(lineNumber);
147
+ },
148
+ getLineFirstNonWhitespaceColumn(lineNumber) {
149
+ return cell.textBuffer.getLineFirstNonWhitespaceColumn(lineNumber);
150
+ },
151
+ getLineLastNonWhitespaceColumn(lineNumber) {
152
+ return cell.textBuffer.getLineLastNonWhitespaceColumn(lineNumber);
153
+ },
154
+ normalizePosition(position, affinity) {
155
+ return position;
156
+ },
157
+ getLineIndentColumn(lineNumber) {
158
+ return indentOfLine(cell.textBuffer.getLineContent(lineNumber)) + 1;
159
+ }
160
+ };
161
+ }
162
+ updateAnchorListeners() {
163
+ this.anchorDisposables.clear();
164
+ if (!this.anchorCell) {
165
+ throw ( (new Error('Anchor cell is undefined')));
166
+ }
167
+ this.anchorDisposables.add(this.anchorCell[1].onWillType((input) => {
168
+ const collector = ( (new ViewModelEventsCollector()));
169
+ this.trackedMatches.forEach(match => {
170
+ const controller = this.cursorsControllers.get(match.cellViewModel.uri);
171
+ if (!controller) {
172
+ return;
173
+ }
174
+ if (match.cellViewModel.handle !== this.anchorCell?.[0].handle) {
175
+ controller.type(collector, input, 'keyboard');
176
+ }
177
+ });
178
+ }));
179
+ this.anchorDisposables.add(this.anchorCell[1].onDidType(() => {
180
+ this.state = NotebookMultiCursorState.Editing;
181
+ this._nbMultiSelectState.set(NotebookMultiCursorState.Editing);
182
+ const anchorController = this.cursorsControllers.get(this.anchorCell[0].uri);
183
+ if (!anchorController) {
184
+ return;
185
+ }
186
+ const activeSelections = this.notebookEditor.activeCodeEditor?.getSelections();
187
+ if (!activeSelections) {
188
+ return;
189
+ }
190
+ anchorController.setSelections(( (new ViewModelEventsCollector())), 'keyboard', activeSelections, CursorChangeReason.Explicit);
191
+ this.trackedMatches.forEach(match => {
192
+ const controller = this.cursorsControllers.get(match.cellViewModel.uri);
193
+ if (!controller) {
194
+ return;
195
+ }
196
+ match.initialSelection = controller.getSelection();
197
+ match.wordSelections = [];
198
+ });
199
+ this.updateLazyDecorations();
200
+ }));
201
+ this.anchorDisposables.add(this.anchorCell[1].onDidChangeCursorSelection((e) => {
202
+ if (e.source === 'mouse' || e.source === 'deleteRight') {
203
+ this.resetToIdleState();
204
+ }
205
+ }));
206
+ this.anchorDisposables.add(this.anchorCell[1].onDidBlurEditorWidget(() => {
207
+ if (this.state === NotebookMultiCursorState.Selecting || this.state === NotebookMultiCursorState.Editing) {
208
+ this.resetToIdleState();
209
+ }
210
+ }));
211
+ }
212
+ updateFinalUndoRedo() {
213
+ const anchorCellModel = this.anchorCell?.[1].getModel();
214
+ if (!anchorCellModel) {
215
+ return;
216
+ }
217
+ const newElementsMap = ( (new ResourceMap()));
218
+ const resources = [];
219
+ this.trackedMatches.forEach(trackedMatch => {
220
+ const undoRedoState = trackedMatch.undoRedoHistory;
221
+ if (!undoRedoState) {
222
+ return;
223
+ }
224
+ resources.push(trackedMatch.cellViewModel.uri);
225
+ const currentPastElements = this.undoRedoService.getElements(trackedMatch.cellViewModel.uri).past.slice();
226
+ const oldPastElements = trackedMatch.undoRedoHistory.past.slice();
227
+ const newElements = currentPastElements.slice(oldPastElements.length);
228
+ if (newElements.length === 0) {
229
+ return;
230
+ }
231
+ newElementsMap.set(trackedMatch.cellViewModel.uri, newElements);
232
+ this.undoRedoService.removeElements(trackedMatch.cellViewModel.uri);
233
+ oldPastElements.forEach(element => {
234
+ this.undoRedoService.pushElement(element);
235
+ });
236
+ });
237
+ this.undoRedoService.pushElement({
238
+ type: UndoRedoElementType.Workspace,
239
+ resources: resources,
240
+ label: 'Multi Cursor Edit',
241
+ code: 'multiCursorEdit',
242
+ confirmBeforeUndo: false,
243
+ undo: async () => {
244
+ newElementsMap.forEach(async (value) => {
245
+ value.reverse().forEach(async (element) => {
246
+ await element.undo();
247
+ });
248
+ });
249
+ },
250
+ redo: async () => {
251
+ newElementsMap.forEach(async (value) => {
252
+ value.forEach(async (element) => {
253
+ await element.redo();
254
+ });
255
+ });
256
+ }
257
+ });
258
+ }
259
+ resetToIdleState() {
260
+ this.state = NotebookMultiCursorState.Idle;
261
+ this._nbMultiSelectState.set(NotebookMultiCursorState.Idle);
262
+ this._nbIsMultiSelectSession.set(false);
263
+ this.updateFinalUndoRedo();
264
+ this.trackedMatches.forEach(match => {
265
+ this.clearDecorations(match);
266
+ match.cellViewModel.setSelections([match.initialSelection]);
267
+ });
268
+ this.anchorDisposables.clear();
269
+ this.cursorsDisposables.clear();
270
+ this.cursorsControllers.clear();
271
+ this.trackedMatches = [];
272
+ }
273
+ async findAndTrackNextSelection(cell) {
274
+ if (this.state === NotebookMultiCursorState.Idle) {
275
+ const textModel = cell.textModel;
276
+ if (!textModel) {
277
+ return;
278
+ }
279
+ const inputSelection = cell.getSelections()[0];
280
+ const word = this.getWord(inputSelection, textModel);
281
+ if (!word) {
282
+ return;
283
+ }
284
+ this.word = word.word;
285
+ const newSelection = ( (new Selection(
286
+ inputSelection.startLineNumber,
287
+ word.startColumn,
288
+ inputSelection.startLineNumber,
289
+ word.endColumn
290
+ )));
291
+ cell.setSelections([newSelection]);
292
+ this.anchorCell = this.notebookEditor.activeCellAndCodeEditor;
293
+ if (!this.anchorCell || this.anchorCell[0].handle !== cell.handle) {
294
+ throw ( (new Error('Active cell is not the same as the cell passed as context')));
295
+ }
296
+ if (!(this.anchorCell[1] instanceof CodeEditorWidget)) {
297
+ throw ( (new Error('Active cell is not an instance of CodeEditorWidget')));
298
+ }
299
+ textModel.pushStackElement();
300
+ this.trackedMatches = [];
301
+ const editorConfig = this.constructCellEditorOptions(this.anchorCell[0]);
302
+ const newMatch = {
303
+ cellViewModel: cell,
304
+ initialSelection: inputSelection,
305
+ wordSelections: [newSelection],
306
+ config: editorConfig,
307
+ decorationIds: [],
308
+ undoRedoHistory: this.undoRedoService.getElements(cell.uri)
309
+ };
310
+ this.trackedMatches.push(newMatch);
311
+ this.initializeMultiSelectDecorations(newMatch);
312
+ this._nbIsMultiSelectSession.set(true);
313
+ this.state = NotebookMultiCursorState.Selecting;
314
+ this._nbMultiSelectState.set(NotebookMultiCursorState.Selecting);
315
+ this._onDidChangeAnchorCell.fire();
316
+ }
317
+ else if (this.state === NotebookMultiCursorState.Selecting) {
318
+ const notebookTextModel = this.notebookEditor.textModel;
319
+ if (!notebookTextModel) {
320
+ return;
321
+ }
322
+ const index = this.notebookEditor.getCellIndex(cell);
323
+ if (index === undefined) {
324
+ return;
325
+ }
326
+ const findResult = notebookTextModel.findNextMatch(this.word, { cellIndex: index, position: cell.getSelections()[cell.getSelections().length - 1].getEndPosition() }, false, true, USUAL_WORD_SEPARATORS
327
+ );
328
+ if (!findResult) {
329
+ return;
330
+ }
331
+ const resultCellViewModel = this.notebookEditor.getCellByHandle(findResult.cell.handle);
332
+ if (!resultCellViewModel) {
333
+ return;
334
+ }
335
+ let newMatch;
336
+ if (findResult.cell.handle !== cell.handle) {
337
+ await this.notebookEditor.revealRangeInViewAsync(resultCellViewModel, findResult.match.range);
338
+ this.notebookEditor.focusNotebookCell(resultCellViewModel, 'editor');
339
+ const initialSelection = resultCellViewModel.getSelections()[0];
340
+ const newSelection = Selection.fromRange(findResult.match.range, SelectionDirection.LTR);
341
+ resultCellViewModel.setSelections([newSelection]);
342
+ this.anchorCell = this.notebookEditor.activeCellAndCodeEditor;
343
+ if (!this.anchorCell || !(this.anchorCell[1] instanceof CodeEditorWidget)) {
344
+ throw ( (new Error('Active cell is not an instance of CodeEditorWidget')));
345
+ }
346
+ const textModel = await resultCellViewModel.resolveTextModel();
347
+ textModel.pushStackElement();
348
+ newMatch = {
349
+ cellViewModel: resultCellViewModel,
350
+ initialSelection: initialSelection,
351
+ wordSelections: [newSelection],
352
+ config: this.constructCellEditorOptions(this.anchorCell[0]),
353
+ decorationIds: [],
354
+ undoRedoHistory: this.undoRedoService.getElements(resultCellViewModel.uri)
355
+ };
356
+ this.trackedMatches.push(newMatch);
357
+ this._onDidChangeAnchorCell.fire();
358
+ }
359
+ else {
360
+ newMatch = this.trackedMatches.find(match => match.cellViewModel.handle === findResult.cell.handle);
361
+ newMatch.wordSelections.push(Selection.fromRange(findResult.match.range, SelectionDirection.LTR));
362
+ resultCellViewModel.setSelections(newMatch.wordSelections);
363
+ }
364
+ this.initializeMultiSelectDecorations(newMatch);
365
+ }
366
+ }
367
+ async deleteLeft() {
368
+ this.trackedMatches.forEach(match => {
369
+ const controller = this.cursorsControllers.get(match.cellViewModel.uri);
370
+ if (!controller) {
371
+ return;
372
+ }
373
+ const [, commands] = DeleteOperations.deleteLeft(controller.getPrevEditOperationType(), controller.context.cursorConfig, controller.context.model, controller.getSelections(), controller.getAutoClosedCharacters());
374
+ const delSelections = CommandExecutor.executeCommands(controller.context.model, controller.getSelections(), commands);
375
+ if (!delSelections) {
376
+ return;
377
+ }
378
+ controller.setSelections(( (new ViewModelEventsCollector())), undefined, delSelections, CursorChangeReason.Explicit);
379
+ });
380
+ }
381
+ async undo() {
382
+ const models = [];
383
+ for (const match of this.trackedMatches) {
384
+ const model = await match.cellViewModel.resolveTextModel();
385
+ if (model) {
386
+ models.push(model);
387
+ }
388
+ }
389
+ await Promise.all(( (models.map(model => model.undo()))));
390
+ }
391
+ async redo() {
392
+ const models = [];
393
+ for (const match of this.trackedMatches) {
394
+ const model = await match.cellViewModel.resolveTextModel();
395
+ if (model) {
396
+ models.push(model);
397
+ }
398
+ }
399
+ await Promise.all(( (models.map(model => model.redo()))));
400
+ }
401
+ constructCellEditorOptions(cell) {
402
+ const cellEditorOptions = ( (new CellEditorOptions(
403
+ this.notebookEditor.getBaseCellEditorOptions(cell.language),
404
+ this.notebookEditor.notebookOptions,
405
+ this.configurationService
406
+ )));
407
+ const options = cellEditorOptions.getUpdatedValue(cell.internalMetadata, cell.uri);
408
+ return (
409
+ (new EditorConfiguration(
410
+ false,
411
+ MenuId.EditorContent,
412
+ false,
413
+ options,
414
+ null,
415
+ this.accessibilityService
416
+ ))
417
+ );
418
+ }
419
+ initializeMultiSelectDecorations(match) {
420
+ const decorations = [];
421
+ match.wordSelections.forEach(selection => {
422
+ decorations.push({
423
+ range: selection,
424
+ options: {
425
+ description: '',
426
+ className: 'nb-multicursor-selection',
427
+ }
428
+ });
429
+ });
430
+ match.decorationIds = match.cellViewModel.deltaModelDecorations(match.decorationIds, decorations);
431
+ }
432
+ updateLazyDecorations() {
433
+ this.trackedMatches.forEach(match => {
434
+ const cellIndex = this.notebookEditor.getCellIndex(match.cellViewModel);
435
+ if (cellIndex === undefined) {
436
+ return;
437
+ }
438
+ const controller = this.cursorsControllers.get(match.cellViewModel.uri);
439
+ if (!controller) {
440
+ return;
441
+ }
442
+ const selections = controller.getSelections();
443
+ const newDecorations = selections?.map(selection => {
444
+ return {
445
+ range: selection,
446
+ options: {
447
+ description: '',
448
+ className: 'nb-multicursor-selection',
449
+ }
450
+ };
451
+ });
452
+ match.decorationIds = match.cellViewModel.deltaModelDecorations(match.decorationIds, newDecorations ?? []);
453
+ });
454
+ }
455
+ clearDecorations(match) {
456
+ match.decorationIds = match.cellViewModel.deltaModelDecorations(match.decorationIds, []);
457
+ }
458
+ getWord(selection, model) {
459
+ const lineNumber = selection.startLineNumber;
460
+ const startColumn = selection.startColumn;
461
+ if (model.isDisposed()) {
462
+ return null;
463
+ }
464
+ return model.getWordAtPosition({
465
+ lineNumber: lineNumber,
466
+ column: startColumn
467
+ });
468
+ }
469
+ dispose() {
470
+ super.dispose();
471
+ this.anchorDisposables.dispose();
472
+ this.cursorsDisposables.dispose();
473
+ this.trackedMatches.forEach(match => {
474
+ this.clearDecorations(match);
475
+ });
476
+ this.trackedMatches = [];
477
+ }
478
+ };
479
+ NotebookMultiCursorController = ( (__decorate([
480
+ ( (__param(1, IContextKeyService))),
481
+ ( (__param(2, ITextModelService))),
482
+ ( (__param(3, ILanguageConfigurationService))),
483
+ ( (__param(4, IAccessibilityService))),
484
+ ( (__param(5, IConfigurationService))),
485
+ ( (__param(6, IUndoRedoService)))
486
+ ], NotebookMultiCursorController)));
487
+ class NotebookAddMatchToMultiSelectionAction extends NotebookAction {
488
+ constructor() {
489
+ super({
490
+ id: NOTEBOOK_ADD_FIND_MATCH_TO_SELECTION_ID,
491
+ title: ( localize(8049, "Add Find Match to Selection")),
492
+ keybinding: {
493
+ when: ( (ContextKeyExpr.and(
494
+ (ContextKeyExpr.equals('config.notebook.multiSelect.enabled', true)),
495
+ NOTEBOOK_IS_ACTIVE_EDITOR,
496
+ NOTEBOOK_CELL_EDITOR_FOCUSED
497
+ ))),
498
+ primary: KeyMod.CtrlCmd | KeyCode.KeyD,
499
+ weight: KeybindingWeight.WorkbenchContrib
500
+ }
501
+ });
502
+ }
503
+ async runWithContext(accessor, context) {
504
+ const editorService = accessor.get(IEditorService);
505
+ const editor = getNotebookEditorFromEditorPane(editorService.activeEditorPane);
506
+ if (!editor) {
507
+ return;
508
+ }
509
+ if (!context.cell) {
510
+ return;
511
+ }
512
+ const controller = editor.getContribution(NotebookMultiCursorController.id);
513
+ controller.findAndTrackNextSelection(context.cell);
514
+ }
515
+ }
516
+ class NotebookExitMultiSelectionAction extends NotebookAction {
517
+ constructor() {
518
+ super({
519
+ id: 'noteMultiCursor.exit',
520
+ title: ( localize(8050, "Exit Multi Cursor Mode")),
521
+ keybinding: {
522
+ when: ( (ContextKeyExpr.and(
523
+ (ContextKeyExpr.equals('config.notebook.multiSelect.enabled', true)),
524
+ NOTEBOOK_IS_ACTIVE_EDITOR,
525
+ NOTEBOOK_MULTI_SELECTION_CONTEXT.IsNotebookMultiSelect
526
+ ))),
527
+ primary: KeyCode.Escape,
528
+ weight: KeybindingWeight.WorkbenchContrib
529
+ }
530
+ });
531
+ }
532
+ async runWithContext(accessor, context) {
533
+ const editorService = accessor.get(IEditorService);
534
+ const editor = getNotebookEditorFromEditorPane(editorService.activeEditorPane);
535
+ if (!editor) {
536
+ return;
537
+ }
538
+ const controller = editor.getContribution(NotebookMultiCursorController.id);
539
+ controller.resetToIdleState();
540
+ }
541
+ }
542
+ class NotebookDeleteLeftMultiSelectionAction extends NotebookAction {
543
+ constructor() {
544
+ super({
545
+ id: 'noteMultiCursor.deleteLeft',
546
+ title: ( localize(8051, "Delete Left")),
547
+ keybinding: {
548
+ when: ( (ContextKeyExpr.and(
549
+ (ContextKeyExpr.equals('config.notebook.multiSelect.enabled', true)),
550
+ NOTEBOOK_IS_ACTIVE_EDITOR,
551
+ NOTEBOOK_MULTI_SELECTION_CONTEXT.IsNotebookMultiSelect,
552
+ (ContextKeyExpr.or(
553
+ (NOTEBOOK_MULTI_SELECTION_CONTEXT.NotebookMultiSelectState.isEqualTo(NotebookMultiCursorState.Selecting)),
554
+ (NOTEBOOK_MULTI_SELECTION_CONTEXT.NotebookMultiSelectState.isEqualTo(NotebookMultiCursorState.Editing))
555
+ ))
556
+ ))),
557
+ primary: KeyCode.Backspace,
558
+ weight: KeybindingWeight.WorkbenchContrib
559
+ }
560
+ });
561
+ }
562
+ async runWithContext(accessor, context) {
563
+ const editorService = accessor.get(IEditorService);
564
+ const editor = getNotebookEditorFromEditorPane(editorService.activeEditorPane);
565
+ if (!editor) {
566
+ return;
567
+ }
568
+ const controller = editor.getContribution(NotebookMultiCursorController.id);
569
+ controller.deleteLeft();
570
+ }
571
+ }
572
+ let NotebookMultiCursorUndoRedoContribution = class NotebookMultiCursorUndoRedoContribution extends Disposable {
573
+ static { this.ID = 'workbench.contrib.notebook.multiCursorUndoRedo'; }
574
+ constructor(_editorService, configurationService) {
575
+ super();
576
+ this._editorService = _editorService;
577
+ this.configurationService = configurationService;
578
+ if (!this.configurationService.getValue('notebook.multiSelect.enabled')) {
579
+ return;
580
+ }
581
+ const PRIORITY = 10005;
582
+ this._register(UndoCommand.addImplementation(PRIORITY, 'notebook-multicursor-undo-redo', () => {
583
+ const editor = getNotebookEditorFromEditorPane(this._editorService.activeEditorPane);
584
+ if (!editor) {
585
+ return false;
586
+ }
587
+ if (!editor.hasModel()) {
588
+ return false;
589
+ }
590
+ const controller = editor.getContribution(NotebookMultiCursorController.id);
591
+ return controller.undo();
592
+ }, ( (ContextKeyExpr.and(
593
+ (ContextKeyExpr.equals('config.notebook.multiSelect.enabled', true)),
594
+ NOTEBOOK_IS_ACTIVE_EDITOR,
595
+ NOTEBOOK_MULTI_SELECTION_CONTEXT.IsNotebookMultiSelect
596
+ )))));
597
+ this._register(RedoCommand.addImplementation(PRIORITY, 'notebook-multicursor-undo-redo', () => {
598
+ const editor = getNotebookEditorFromEditorPane(this._editorService.activeEditorPane);
599
+ if (!editor) {
600
+ return false;
601
+ }
602
+ if (!editor.hasModel()) {
603
+ return false;
604
+ }
605
+ const controller = editor.getContribution(NotebookMultiCursorController.id);
606
+ return controller.redo();
607
+ }, ( (ContextKeyExpr.and(
608
+ (ContextKeyExpr.equals('config.notebook.multiSelect.enabled', true)),
609
+ NOTEBOOK_IS_ACTIVE_EDITOR,
610
+ NOTEBOOK_MULTI_SELECTION_CONTEXT.IsNotebookMultiSelect
611
+ )))));
612
+ }
613
+ };
614
+ NotebookMultiCursorUndoRedoContribution = ( (__decorate([
615
+ ( (__param(0, IEditorService))),
616
+ ( (__param(1, IConfigurationService)))
617
+ ], NotebookMultiCursorUndoRedoContribution)));
618
+ registerNotebookContribution(NotebookMultiCursorController.id, NotebookMultiCursorController);
619
+ registerAction2(NotebookAddMatchToMultiSelectionAction);
620
+ registerAction2(NotebookExitMultiSelectionAction);
621
+ registerAction2(NotebookDeleteLeftMultiSelectionAction);
622
+ registerWorkbenchContribution2(NotebookMultiCursorUndoRedoContribution.ID, NotebookMultiCursorUndoRedoContribution, WorkbenchPhase.BlockRestore);
623
+
624
+ export { NOTEBOOK_MULTI_SELECTION_CONTEXT, NotebookMultiCursorController };