@codingame/monaco-vscode-api 33.0.3 → 33.0.4

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 (52) hide show
  1. package/package.json +9 -9
  2. package/services.js +3 -3
  3. package/vscode/src/vs/platform/product/common/product.js +1 -1
  4. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/cellOperations.d.ts +0 -26
  5. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/cellOperations.js +0 -746
  6. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/insertCellActions.d.ts +0 -13
  7. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/insertCellActions.js +0 -300
  8. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffCellEditorOptions.d.ts +0 -8
  9. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffCellEditorOptions.js +0 -55
  10. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffComponents.d.ts +0 -273
  11. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffComponents.js +0 -1963
  12. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffElementOutputs.d.ts +0 -50
  13. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffElementOutputs.js +0 -314
  14. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffElementViewModel.d.ts +0 -258
  15. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffElementViewModel.js +0 -886
  16. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffNestedCellViewModel.d.ts +0 -41
  17. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffNestedCellViewModel.js +0 -118
  18. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/editorHeightCalculator.d.ts +0 -17
  19. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/editorHeightCalculator.js +0 -71
  20. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/eventDispatcher.d.ts +0 -27
  21. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/eventDispatcher.js +0 -40
  22. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookCellDiffDecorator.d.ts +0 -23
  23. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookCellDiffDecorator.js +0 -313
  24. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookDeletedCellDecorator.d.ts +0 -51
  25. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookDeletedCellDecorator.js +0 -265
  26. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookInlineDiff.d.ts +0 -24
  27. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookInlineDiff.js +0 -185
  28. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookInlineDiffWidget.d.ts +0 -28
  29. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookInlineDiffWidget.js +0 -104
  30. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookInsertedCellDecorator.d.ts +0 -10
  31. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookInsertedCellDecorator.js +0 -43
  32. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookOriginalCellModelFactory.d.ts +0 -21
  33. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookOriginalCellModelFactory.js +0 -41
  34. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookOriginalModelRefFactory.d.ts +0 -25
  35. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookOriginalModelRefFactory.js +0 -69
  36. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiff.css +0 -469
  37. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.d.ts +0 -149
  38. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.js +0 -933
  39. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser.d.ts +0 -180
  40. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser.js +0 -32
  41. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffList.d.ts +0 -102
  42. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffList.js +0 -643
  43. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffOverviewRuler.d.ts +0 -30
  44. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffOverviewRuler.js +0 -197
  45. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffViewModel.d.ts +0 -75
  46. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffViewModel.js +0 -539
  47. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/unchangedEditorRegions.d.ts +0 -13
  48. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/unchangedEditorRegions.js +0 -39
  49. package/vscode/src/vs/workbench/contrib/notebook/common/model/notebookMetadataTextModel.d.ts +0 -19
  50. package/vscode/src/vs/workbench/contrib/notebook/common/model/notebookMetadataTextModel.js +0 -90
  51. package/vscode/src/vs/workbench/contrib/notebook/common/notebookDiff.d.ts +0 -26
  52. package/vscode/src/vs/workbench/contrib/notebook/common/notebookDiff.js +0 -92
@@ -1,746 +0,0 @@
1
-
2
- import { ResourceTextEdit } from '../../../../../editor/browser/services/bulkEditService.js';
3
- import { Position } from '../../../../../editor/common/core/position.js';
4
- import { Range } from '../../../../../editor/common/core/range.js';
5
- import { EndOfLinePreference } from '../../../../../editor/common/model.js';
6
- import { PLAINTEXT_LANGUAGE_ID } from '../../../../../editor/common/languages/modesRegistry.js';
7
- import { ResourceNotebookCellEdit } from '../../../bulkEdit/browser/bulkCellEdits.js';
8
- import { CellEditState, expandCellRangesWithHiddenCells, CellFocusMode } from '../notebookBrowser.js';
9
- import { cloneNotebookCellTextModel } from '../../common/model/notebookCellTextModel.js';
10
- import { CellEditType, SelectionStateType, CellKind } from '../../common/notebookCommon.js';
11
- import { cellRangeContains, cellRangesToIndexes } from '../../common/notebookRange.js';
12
- import { localize } from '../../../../../nls.js';
13
-
14
- async function changeCellToKind(kind, context, language, mime) {
15
- const {
16
- notebookEditor
17
- } = context;
18
- if (!notebookEditor.hasModel()) {
19
- return;
20
- }
21
- if (notebookEditor.isReadOnly) {
22
- return;
23
- }
24
- if (context.ui && context.cell) {
25
- const {
26
- cell
27
- } = context;
28
- if (cell.cellKind === kind) {
29
- return;
30
- }
31
- const text = cell.getText();
32
- const idx = notebookEditor.getCellIndex(cell);
33
- if (language === undefined) {
34
- const availableLanguages = notebookEditor.activeKernel?.supportedLanguages ?? [];
35
- language = availableLanguages[0] ?? PLAINTEXT_LANGUAGE_ID;
36
- }
37
- notebookEditor.textModel.applyEdits([{
38
- editType: CellEditType.Replace,
39
- index: idx,
40
- count: 1,
41
- cells: [{
42
- cellKind: kind,
43
- source: text,
44
- language: language,
45
- mime: mime ?? cell.mime,
46
- outputs: cell.model.outputs,
47
- metadata: cell.metadata
48
- }]
49
- }], true, {
50
- kind: SelectionStateType.Index,
51
- focus: notebookEditor.getFocus(),
52
- selections: notebookEditor.getSelections()
53
- }, () => {
54
- return {
55
- kind: SelectionStateType.Index,
56
- focus: notebookEditor.getFocus(),
57
- selections: notebookEditor.getSelections()
58
- };
59
- }, undefined, true);
60
- const newCell = notebookEditor.cellAt(idx);
61
- await notebookEditor.focusNotebookCell(
62
- newCell,
63
- cell.getEditState() === CellEditState.Editing ? "editor" : "container"
64
- );
65
- } else if (context.selectedCells) {
66
- const selectedCells = context.selectedCells;
67
- const rawEdits = [];
68
- selectedCells.forEach(cell => {
69
- if (cell.cellKind === kind) {
70
- return;
71
- }
72
- const text = cell.getText();
73
- const idx = notebookEditor.getCellIndex(cell);
74
- if (language === undefined) {
75
- const availableLanguages = notebookEditor.activeKernel?.supportedLanguages ?? [];
76
- language = availableLanguages[0] ?? PLAINTEXT_LANGUAGE_ID;
77
- }
78
- rawEdits.push({
79
- editType: CellEditType.Replace,
80
- index: idx,
81
- count: 1,
82
- cells: [{
83
- cellKind: kind,
84
- source: text,
85
- language: language,
86
- mime: mime ?? cell.mime,
87
- outputs: cell.model.outputs,
88
- metadata: cell.metadata
89
- }]
90
- });
91
- });
92
- notebookEditor.textModel.applyEdits(rawEdits, true, {
93
- kind: SelectionStateType.Index,
94
- focus: notebookEditor.getFocus(),
95
- selections: notebookEditor.getSelections()
96
- }, () => {
97
- return {
98
- kind: SelectionStateType.Index,
99
- focus: notebookEditor.getFocus(),
100
- selections: notebookEditor.getSelections()
101
- };
102
- }, undefined, true);
103
- }
104
- }
105
- function runDeleteAction(editor, cell) {
106
- const textModel = editor.textModel;
107
- const selections = editor.getSelections();
108
- const targetCellIndex = editor.getCellIndex(cell);
109
- const containingSelection = selections.find(
110
- selection => selection.start <= targetCellIndex && targetCellIndex < selection.end
111
- );
112
- const computeUndoRedo = !editor.isReadOnly || textModel.viewType === "interactive";
113
- if (containingSelection) {
114
- const edits = ( selections.reverse().map(selection => ({
115
- editType: CellEditType.Replace,
116
- index: selection.start,
117
- count: selection.end - selection.start,
118
- cells: []
119
- })));
120
- const nextCellAfterContainingSelection = containingSelection.end >= editor.getLength() ? undefined : editor.cellAt(containingSelection.end);
121
- textModel.applyEdits(edits, true, {
122
- kind: SelectionStateType.Index,
123
- focus: editor.getFocus(),
124
- selections: editor.getSelections()
125
- }, () => {
126
- if (nextCellAfterContainingSelection) {
127
- const cellIndex = textModel.cells.findIndex(cell => cell.handle === nextCellAfterContainingSelection.handle);
128
- return {
129
- kind: SelectionStateType.Index,
130
- focus: {
131
- start: cellIndex,
132
- end: cellIndex + 1
133
- },
134
- selections: [{
135
- start: cellIndex,
136
- end: cellIndex + 1
137
- }]
138
- };
139
- } else {
140
- if (textModel.length) {
141
- const lastCellIndex = textModel.length - 1;
142
- return {
143
- kind: SelectionStateType.Index,
144
- focus: {
145
- start: lastCellIndex,
146
- end: lastCellIndex + 1
147
- },
148
- selections: [{
149
- start: lastCellIndex,
150
- end: lastCellIndex + 1
151
- }]
152
- };
153
- } else {
154
- return {
155
- kind: SelectionStateType.Index,
156
- focus: {
157
- start: 0,
158
- end: 0
159
- },
160
- selections: [{
161
- start: 0,
162
- end: 0
163
- }]
164
- };
165
- }
166
- }
167
- }, undefined, computeUndoRedo);
168
- } else {
169
- const focus = editor.getFocus();
170
- const edits = [{
171
- editType: CellEditType.Replace,
172
- index: targetCellIndex,
173
- count: 1,
174
- cells: []
175
- }];
176
- const finalSelections = [];
177
- for (let i = 0; i < selections.length; i++) {
178
- const selection = selections[i];
179
- if (selection.end <= targetCellIndex) {
180
- finalSelections.push(selection);
181
- } else if (selection.start > targetCellIndex) {
182
- finalSelections.push({
183
- start: selection.start - 1,
184
- end: selection.end - 1
185
- });
186
- } else {
187
- finalSelections.push({
188
- start: targetCellIndex,
189
- end: targetCellIndex + 1
190
- });
191
- }
192
- }
193
- if (editor.cellAt(focus.start) === cell) {
194
- const newFocus = focus.end === textModel.length ? {
195
- start: focus.start - 1,
196
- end: focus.end - 1
197
- } : focus;
198
- textModel.applyEdits(edits, true, {
199
- kind: SelectionStateType.Index,
200
- focus: editor.getFocus(),
201
- selections: editor.getSelections()
202
- }, () => ({
203
- kind: SelectionStateType.Index,
204
- focus: newFocus,
205
- selections: finalSelections
206
- }), undefined, computeUndoRedo);
207
- } else {
208
- const newFocus = focus.start > targetCellIndex ? {
209
- start: focus.start - 1,
210
- end: focus.end - 1
211
- } : focus;
212
- textModel.applyEdits(edits, true, {
213
- kind: SelectionStateType.Index,
214
- focus: editor.getFocus(),
215
- selections: editor.getSelections()
216
- }, () => ({
217
- kind: SelectionStateType.Index,
218
- focus: newFocus,
219
- selections: finalSelections
220
- }), undefined, computeUndoRedo);
221
- }
222
- }
223
- }
224
- async function moveCellRange(context, direction) {
225
- if (!context.notebookEditor.hasModel()) {
226
- return;
227
- }
228
- const editor = context.notebookEditor;
229
- const textModel = editor.textModel;
230
- if (editor.isReadOnly) {
231
- return;
232
- }
233
- let range = undefined;
234
- if (context.cell) {
235
- const idx = editor.getCellIndex(context.cell);
236
- range = {
237
- start: idx,
238
- end: idx + 1
239
- };
240
- } else {
241
- const selections = editor.getSelections();
242
- const modelRanges = expandCellRangesWithHiddenCells(editor, selections);
243
- range = modelRanges[0];
244
- }
245
- if (!range || range.start === range.end) {
246
- return;
247
- }
248
- if (direction === "up") {
249
- if (range.start === 0) {
250
- return;
251
- }
252
- const indexAbove = range.start - 1;
253
- const finalSelection = {
254
- start: range.start - 1,
255
- end: range.end - 1
256
- };
257
- const focus = context.notebookEditor.getFocus();
258
- const newFocus = cellRangeContains(range, focus) ? {
259
- start: focus.start - 1,
260
- end: focus.end - 1
261
- } : {
262
- start: range.start - 1,
263
- end: range.start
264
- };
265
- textModel.applyEdits([{
266
- editType: CellEditType.Move,
267
- index: indexAbove,
268
- length: 1,
269
- newIdx: range.end - 1
270
- }], true, {
271
- kind: SelectionStateType.Index,
272
- focus: editor.getFocus(),
273
- selections: editor.getSelections()
274
- }, () => ({
275
- kind: SelectionStateType.Index,
276
- focus: newFocus,
277
- selections: [finalSelection]
278
- }), undefined, true);
279
- const focusRange = editor.getSelections()[0] ?? editor.getFocus();
280
- editor.revealCellRangeInView(focusRange);
281
- } else {
282
- if (range.end >= textModel.length) {
283
- return;
284
- }
285
- const indexBelow = range.end;
286
- const finalSelection = {
287
- start: range.start + 1,
288
- end: range.end + 1
289
- };
290
- const focus = editor.getFocus();
291
- const newFocus = cellRangeContains(range, focus) ? {
292
- start: focus.start + 1,
293
- end: focus.end + 1
294
- } : {
295
- start: range.start + 1,
296
- end: range.start + 2
297
- };
298
- textModel.applyEdits([{
299
- editType: CellEditType.Move,
300
- index: indexBelow,
301
- length: 1,
302
- newIdx: range.start
303
- }], true, {
304
- kind: SelectionStateType.Index,
305
- focus: editor.getFocus(),
306
- selections: editor.getSelections()
307
- }, () => ({
308
- kind: SelectionStateType.Index,
309
- focus: newFocus,
310
- selections: [finalSelection]
311
- }), undefined, true);
312
- const focusRange = editor.getSelections()[0] ?? editor.getFocus();
313
- editor.revealCellRangeInView(focusRange);
314
- }
315
- }
316
- async function copyCellRange(context, direction) {
317
- const editor = context.notebookEditor;
318
- if (!editor.hasModel()) {
319
- return;
320
- }
321
- const textModel = editor.textModel;
322
- if (editor.isReadOnly) {
323
- return;
324
- }
325
- let range = undefined;
326
- if (context.ui) {
327
- const targetCell = context.cell;
328
- const targetCellIndex = editor.getCellIndex(targetCell);
329
- range = {
330
- start: targetCellIndex,
331
- end: targetCellIndex + 1
332
- };
333
- } else {
334
- const selections = editor.getSelections();
335
- const modelRanges = expandCellRangesWithHiddenCells(editor, selections);
336
- range = modelRanges[0];
337
- }
338
- if (!range || range.start === range.end) {
339
- return;
340
- }
341
- if (direction === "up") {
342
- const focus = editor.getFocus();
343
- const selections = editor.getSelections();
344
- textModel.applyEdits([{
345
- editType: CellEditType.Replace,
346
- index: range.end,
347
- count: 0,
348
- cells: ( cellRangesToIndexes([range]).map(index => cloneNotebookCellTextModel(editor.cellAt(index).model)))
349
- }], true, {
350
- kind: SelectionStateType.Index,
351
- focus: focus,
352
- selections: selections
353
- }, () => ({
354
- kind: SelectionStateType.Index,
355
- focus: focus,
356
- selections: selections
357
- }), undefined, true);
358
- } else {
359
- const focus = editor.getFocus();
360
- const selections = editor.getSelections();
361
- const newCells = ( cellRangesToIndexes([range]).map(index => cloneNotebookCellTextModel(editor.cellAt(index).model)));
362
- const countDelta = newCells.length;
363
- const newFocus = context.ui ? focus : {
364
- start: focus.start + countDelta,
365
- end: focus.end + countDelta
366
- };
367
- const newSelections = context.ui ? selections : [{
368
- start: range.start + countDelta,
369
- end: range.end + countDelta
370
- }];
371
- textModel.applyEdits([{
372
- editType: CellEditType.Replace,
373
- index: range.end,
374
- count: 0,
375
- cells: ( cellRangesToIndexes([range]).map(index => cloneNotebookCellTextModel(editor.cellAt(index).model)))
376
- }], true, {
377
- kind: SelectionStateType.Index,
378
- focus: focus,
379
- selections: selections
380
- }, () => ({
381
- kind: SelectionStateType.Index,
382
- focus: newFocus,
383
- selections: newSelections
384
- }), undefined, true);
385
- const focusRange = editor.getSelections()[0] ?? editor.getFocus();
386
- editor.revealCellRangeInView(focusRange);
387
- }
388
- }
389
- async function joinSelectedCells(bulkEditService, notificationService, context) {
390
- const editor = context.notebookEditor;
391
- if (editor.isReadOnly) {
392
- return;
393
- }
394
- const edits = [];
395
- const cells = [];
396
- for (const selection of editor.getSelections()) {
397
- cells.push(...editor.getCellsInRange(selection));
398
- }
399
- if (cells.length <= 1) {
400
- return;
401
- }
402
- const cellKind = cells[0].cellKind;
403
- const isSameKind = cells.every(cell => cell.cellKind === cellKind);
404
- if (!isSameKind) {
405
- const message = ( localize(11670, "Cannot join cells of different kinds"));
406
- return notificationService.warn(message);
407
- }
408
- const firstCell = cells[0];
409
- const insertContent = ( cells.map(cell => cell.getText())).join(firstCell.textBuffer.getEOL());
410
- const firstSelection = editor.getSelections()[0];
411
- edits.push(( new ResourceNotebookCellEdit(editor.textModel.uri, {
412
- editType: CellEditType.Replace,
413
- index: firstSelection.start,
414
- count: firstSelection.end - firstSelection.start,
415
- cells: [{
416
- cellKind: firstCell.cellKind,
417
- source: insertContent,
418
- language: firstCell.language,
419
- mime: firstCell.mime,
420
- outputs: firstCell.model.outputs,
421
- metadata: firstCell.metadata
422
- }]
423
- })));
424
- for (const selection of editor.getSelections().slice(1)) {
425
- edits.push(( new ResourceNotebookCellEdit(editor.textModel.uri, {
426
- editType: CellEditType.Replace,
427
- index: selection.start,
428
- count: selection.end - selection.start,
429
- cells: []
430
- })));
431
- }
432
- if (edits.length) {
433
- await bulkEditService.apply(edits, {
434
- quotableLabel: ( localize(11671, "Join Notebook Cells"))
435
- });
436
- }
437
- }
438
- async function joinNotebookCells(editor, range, direction, constraint) {
439
- if (editor.isReadOnly) {
440
- return null;
441
- }
442
- const textModel = editor.textModel;
443
- const cells = editor.getCellsInRange(range);
444
- if (!cells.length) {
445
- return null;
446
- }
447
- if (range.start === 0 && direction === "above") {
448
- return null;
449
- }
450
- if (range.end === textModel.length && direction === "below") {
451
- return null;
452
- }
453
- if (direction === "above") {
454
- const above = editor.cellAt(range.start - 1);
455
- const insertContent = ( cells.map(cell => (cell.textBuffer.getEOL() ?? "") + cell.getText())).join("");
456
- const aboveCellLineCount = above.textBuffer.getLineCount();
457
- const aboveCellLastLineEndColumn = above.textBuffer.getLineLength(aboveCellLineCount);
458
- return {
459
- edits: [( new ResourceTextEdit(above.uri, {
460
- range: ( new Range(
461
- aboveCellLineCount,
462
- aboveCellLastLineEndColumn + 1,
463
- aboveCellLineCount,
464
- aboveCellLastLineEndColumn + 1
465
- )),
466
- text: insertContent
467
- })), ( new ResourceNotebookCellEdit(textModel.uri, {
468
- editType: CellEditType.Replace,
469
- index: range.start,
470
- count: range.end - range.start,
471
- cells: []
472
- }))],
473
- cell: above,
474
- endFocus: {
475
- start: range.start - 1,
476
- end: range.start
477
- },
478
- endSelections: [{
479
- start: range.start - 1,
480
- end: range.start
481
- }]
482
- };
483
- } else {
484
- const below = editor.cellAt(range.end);
485
- const cell = cells[0];
486
- const restCells = [...cells.slice(1), below];
487
- const insertContent = ( restCells.map(cl => (cl.textBuffer.getEOL() ?? "") + cl.getText())).join("");
488
- const cellLineCount = cell.textBuffer.getLineCount();
489
- const cellLastLineEndColumn = cell.textBuffer.getLineLength(cellLineCount);
490
- return {
491
- edits: [( new ResourceTextEdit(cell.uri, {
492
- range: ( new Range(
493
- cellLineCount,
494
- cellLastLineEndColumn + 1,
495
- cellLineCount,
496
- cellLastLineEndColumn + 1
497
- )),
498
- text: insertContent
499
- })), ( new ResourceNotebookCellEdit(textModel.uri, {
500
- editType: CellEditType.Replace,
501
- index: range.start + 1,
502
- count: range.end - range.start,
503
- cells: []
504
- }))],
505
- cell,
506
- endFocus: {
507
- start: range.start,
508
- end: range.start + 1
509
- },
510
- endSelections: [{
511
- start: range.start,
512
- end: range.start + 1
513
- }]
514
- };
515
- }
516
- }
517
- async function joinCellsWithSurrounds(bulkEditService, context, direction) {
518
- const editor = context.notebookEditor;
519
- const textModel = editor.textModel;
520
- const viewModel = editor.getViewModel();
521
- let ret = null;
522
- if (context.ui) {
523
- const focusMode = context.cell.focusMode;
524
- const cellIndex = editor.getCellIndex(context.cell);
525
- ret = await joinNotebookCells(editor, {
526
- start: cellIndex,
527
- end: cellIndex + 1
528
- }, direction);
529
- if (!ret) {
530
- return;
531
- }
532
- await bulkEditService.apply(ret?.edits, {
533
- quotableLabel: "Join Notebook Cells"
534
- });
535
- viewModel.updateSelectionsState({
536
- kind: SelectionStateType.Index,
537
- focus: ret.endFocus,
538
- selections: ret.endSelections
539
- });
540
- ret.cell.updateEditState(CellEditState.Editing, "joinCellsWithSurrounds");
541
- editor.revealCellRangeInView(editor.getFocus());
542
- if (focusMode === CellFocusMode.Editor) {
543
- ret.cell.focusMode = CellFocusMode.Editor;
544
- }
545
- } else {
546
- const selections = editor.getSelections();
547
- if (!selections.length) {
548
- return;
549
- }
550
- const focus = editor.getFocus();
551
- const focusMode = editor.cellAt(focus.start)?.focusMode;
552
- const edits = [];
553
- let cell = null;
554
- const cells = [];
555
- for (let i = selections.length - 1; i >= 0; i--) {
556
- const selection = selections[i];
557
- const containFocus = cellRangeContains(selection, focus);
558
- if (selection.end >= textModel.length && direction === "below" || selection.start === 0 && direction === "above") {
559
- if (containFocus) {
560
- cell = editor.cellAt(focus.start);
561
- }
562
- cells.push(...editor.getCellsInRange(selection));
563
- continue;
564
- }
565
- const singleRet = await joinNotebookCells(editor, selection, direction);
566
- if (!singleRet) {
567
- return;
568
- }
569
- edits.push(...singleRet.edits);
570
- cells.push(singleRet.cell);
571
- if (containFocus) {
572
- cell = singleRet.cell;
573
- }
574
- }
575
- if (!edits.length) {
576
- return;
577
- }
578
- if (!cell || !cells.length) {
579
- return;
580
- }
581
- await bulkEditService.apply(edits, {
582
- quotableLabel: "Join Notebook Cells"
583
- });
584
- cells.forEach(cell => {
585
- cell.updateEditState(CellEditState.Editing, "joinCellsWithSurrounds");
586
- });
587
- viewModel.updateSelectionsState({
588
- kind: SelectionStateType.Handle,
589
- primary: cell.handle,
590
- selections: ( cells.map(cell => cell.handle))
591
- });
592
- editor.revealCellRangeInView(editor.getFocus());
593
- const newFocusedCell = editor.cellAt(editor.getFocus().start);
594
- if (focusMode === CellFocusMode.Editor && newFocusedCell) {
595
- newFocusedCell.focusMode = CellFocusMode.Editor;
596
- }
597
- }
598
- }
599
- function _splitPointsToBoundaries(splitPoints, textBuffer) {
600
- const boundaries = [];
601
- const lineCnt = textBuffer.getLineCount();
602
- const getLineLen = lineNumber => {
603
- return textBuffer.getLineLength(lineNumber);
604
- };
605
- splitPoints = splitPoints.sort((l, r) => {
606
- const lineDiff = l.lineNumber - r.lineNumber;
607
- const columnDiff = l.column - r.column;
608
- return lineDiff !== 0 ? lineDiff : columnDiff;
609
- });
610
- for (let sp of splitPoints) {
611
- if (getLineLen(sp.lineNumber) + 1 === sp.column && sp.column !== 1 && sp.lineNumber < lineCnt) {
612
- sp = ( new Position(sp.lineNumber + 1, 1));
613
- }
614
- _pushIfAbsent(boundaries, sp);
615
- }
616
- if (boundaries.length === 0) {
617
- return null;
618
- }
619
- const modelStart = ( new Position(1, 1));
620
- const modelEnd = ( new Position(lineCnt, getLineLen(lineCnt) + 1));
621
- return [modelStart, ...boundaries, modelEnd];
622
- }
623
- function _pushIfAbsent(positions, p) {
624
- const last = positions.length > 0 ? positions[positions.length - 1] : undefined;
625
- if (!last || last.lineNumber !== p.lineNumber || last.column !== p.column) {
626
- positions.push(p);
627
- }
628
- }
629
- function computeCellLinesContents(cell, splitPoints) {
630
- const rangeBoundaries = _splitPointsToBoundaries(splitPoints, cell.textBuffer);
631
- if (!rangeBoundaries) {
632
- return null;
633
- }
634
- const newLineModels = [];
635
- for (let i = 1; i < rangeBoundaries.length; i++) {
636
- const start = rangeBoundaries[i - 1];
637
- const end = rangeBoundaries[i];
638
- newLineModels.push(cell.textBuffer.getValueInRange(( new Range(start.lineNumber, start.column, end.lineNumber, end.column)), EndOfLinePreference.TextDefined));
639
- }
640
- return newLineModels;
641
- }
642
- function insertCell(
643
- languageService,
644
- editor,
645
- index,
646
- type,
647
- direction = "above",
648
- initialText = "",
649
- ui = false,
650
- kernelHistoryService
651
- ) {
652
- const viewModel = editor.getViewModel();
653
- const activeKernel = editor.activeKernel;
654
- if (viewModel.options.isReadOnly) {
655
- return null;
656
- }
657
- const cell = editor.cellAt(index);
658
- const nextIndex = ui ? viewModel.getNextVisibleCellIndex(index) : index + 1;
659
- let language;
660
- if (type === CellKind.Code) {
661
- const supportedLanguages = activeKernel?.supportedLanguages ?? languageService.getRegisteredLanguageIds();
662
- const defaultLanguage = supportedLanguages[0] || PLAINTEXT_LANGUAGE_ID;
663
- if (cell?.cellKind === CellKind.Code) {
664
- language = cell.language;
665
- } else if (cell?.cellKind === CellKind.Markup) {
666
- const nearestCodeCellIndex = viewModel.nearestCodeCellIndex(index);
667
- if (nearestCodeCellIndex > -1) {
668
- language = viewModel.cellAt(nearestCodeCellIndex).language;
669
- } else {
670
- language = defaultLanguage;
671
- }
672
- } else if (!cell && viewModel.length === 0) {
673
- const lastKernels = kernelHistoryService?.getKernels(viewModel.notebookDocument);
674
- if (lastKernels?.all.length) {
675
- const lastKernel = lastKernels.all[0];
676
- language = lastKernel.supportedLanguages[0] || defaultLanguage;
677
- } else {
678
- language = defaultLanguage;
679
- }
680
- } else {
681
- if (cell === undefined && direction === "above") {
682
- language = viewModel.viewCells.find(cell => cell.cellKind === CellKind.Code)?.language || defaultLanguage;
683
- } else {
684
- language = defaultLanguage;
685
- }
686
- }
687
- if (!supportedLanguages.includes(language)) {
688
- language = defaultLanguage;
689
- }
690
- } else {
691
- language = "markdown";
692
- }
693
- const insertIndex = cell ? (direction === "above" ? index : nextIndex) : index;
694
- return insertCellAtIndex(
695
- viewModel,
696
- insertIndex,
697
- initialText,
698
- language,
699
- type,
700
- undefined,
701
- [],
702
- true);
703
- }
704
- function insertCellAtIndex(
705
- viewModel,
706
- index,
707
- source,
708
- language,
709
- type,
710
- metadata,
711
- outputs,
712
- synchronous,
713
- pushUndoStop
714
- ) {
715
- const endSelections = {
716
- kind: SelectionStateType.Index,
717
- focus: {
718
- start: index,
719
- end: index + 1
720
- },
721
- selections: [{
722
- start: index,
723
- end: index + 1
724
- }]
725
- };
726
- viewModel.notebookDocument.applyEdits([{
727
- editType: CellEditType.Replace,
728
- index,
729
- count: 0,
730
- cells: [{
731
- cellKind: type,
732
- language: language,
733
- mime: undefined,
734
- outputs: outputs,
735
- metadata: metadata,
736
- source: source
737
- }]
738
- }], synchronous, {
739
- kind: SelectionStateType.Index,
740
- focus: viewModel.getFocus(),
741
- selections: viewModel.getSelections()
742
- }, () => endSelections, undefined, !viewModel.options.isReadOnly);
743
- return viewModel.cellAt(index);
744
- }
745
-
746
- export { changeCellToKind, computeCellLinesContents, copyCellRange, insertCell, insertCellAtIndex, joinCellsWithSurrounds, joinNotebookCells, joinSelectedCells, moveCellRange, runDeleteAction };