@codingame/monaco-vscode-katex-common 29.1.0 → 30.0.0

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 (180) hide show
  1. package/package.json +2 -2
  2. package/vscode/src/vs/platform/actions/browser/buttonbar.js +14 -13
  3. package/vscode/src/vs/workbench/contrib/chat/browser/accessibility/chatAccessibilityProvider.js +16 -16
  4. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatContinueInAction.js +9 -9
  5. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatElicitationActions.js +1 -1
  6. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatExecuteActions.js +34 -34
  7. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatTitleActions.js +12 -20
  8. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatToolActions.d.ts +14 -0
  9. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatToolActions.js +208 -0
  10. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatToolPicker.d.ts +22 -0
  11. package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatToolPicker.js +637 -0
  12. package/vscode/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionApprovalModel.d.ts +1 -0
  13. package/vscode/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionApprovalModel.js +1 -0
  14. package/vscode/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionHoverWidget.js +8 -8
  15. package/vscode/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsControl.d.ts +9 -1
  16. package/vscode/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsControl.js +202 -13
  17. package/vscode/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsFilter.d.ts +4 -0
  18. package/vscode/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsFilter.js +17 -8
  19. package/vscode/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsOpener.js +1 -1
  20. package/vscode/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsViewer.d.ts +53 -5
  21. package/vscode/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsViewer.js +296 -63
  22. package/vscode/src/vs/workbench/contrib/chat/browser/agentSessions/media/agentsessionsviewer.css +59 -23
  23. package/vscode/src/vs/workbench/contrib/chat/browser/attachments/chatAttachmentWidgets.js +55 -42
  24. package/vscode/src/vs/workbench/contrib/chat/browser/attachments/implicitContextAttachment.js +12 -12
  25. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingActions.js +110 -59
  26. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingEditorActions.js +14 -14
  27. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingEditorOverlay.js +7 -7
  28. package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingExplanationWidget.js +12 -12
  29. package/vscode/src/vs/workbench/contrib/chat/browser/chatSessions/chatSessionPickerActionItem.js +1 -1
  30. package/vscode/src/vs/workbench/contrib/chat/browser/chatSessions/searchableOptionPickerActionItem.js +5 -4
  31. package/vscode/src/vs/workbench/contrib/chat/browser/tools/toolSetsContribution.d.ts +24 -0
  32. package/vscode/src/vs/workbench/contrib/chat/browser/tools/toolSetsContribution.js +384 -0
  33. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatAgentHover.js +2 -2
  34. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatArtifactsWidget.d.ts +12 -7
  35. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatArtifactsWidget.js +220 -61
  36. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentMarkdownRenderer.js +1 -2
  37. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatAgentCommandContentPart.js +1 -1
  38. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatAnonymousRateLimitedPart.js +2 -2
  39. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatAttachmentsContentPart.d.ts +6 -0
  40. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatAttachmentsContentPart.js +14 -1
  41. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatChangesSummaryPart.js +1 -1
  42. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatCodeCitationContentPart.js +1 -1
  43. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatCommandContentPart.js +1 -1
  44. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatConfirmationContentPart.js +2 -2
  45. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatConfirmationWidget.js +1 -1
  46. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatContentCodePools.js +5 -4
  47. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatDisabledClaudeHooksContentPart.js +3 -3
  48. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatExtensionsContentPart.js +1 -1
  49. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatHookContentPart.js +1 -1
  50. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatInlineAnchorWidget.d.ts +5 -0
  51. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatInlineAnchorWidget.js +14 -14
  52. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatMarkdownContentPart.d.ts +11 -0
  53. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatMarkdownContentPart.js +40 -12
  54. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatMcpServersInteractionContentPart.js +8 -8
  55. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatMultiDiffContentPart.js +4 -4
  56. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatProgressContentPart.js +2 -2
  57. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatQuestionCarouselPart.d.ts +1 -0
  58. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatQuestionCarouselPart.js +97 -54
  59. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatQuotaExceededPart.js +5 -4
  60. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatReferencesContentPart.js +6 -6
  61. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatResourceGroupWidget.js +5 -5
  62. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatSubagentContentPart.js +6 -6
  63. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatSuggestNextWidget.js +8 -7
  64. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatTextEditContentPart.js +1 -1
  65. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatThinkingContentPart.d.ts +15 -2
  66. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatThinkingContentPart.js +155 -22
  67. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatTipContentPart.js +9 -9
  68. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatTodoListWidget.d.ts +3 -1
  69. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatTodoListWidget.js +36 -19
  70. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatToolInputOutputContentPart.js +2 -2
  71. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatTreeContentPart.js +1 -1
  72. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatWorkspaceEditContentPart.js +3 -3
  73. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/codeBlockPart.js +14 -14
  74. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/media/chatThinkingContent.css +13 -0
  75. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/abstractToolConfirmationSubPart.js +1 -1
  76. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatExtensionsInstallToolSubPart.js +4 -4
  77. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatMcpAppModel.js +1 -1
  78. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatMcpAppSubPart.js +3 -3
  79. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatMissingSandboxDepsConfirmationSubPart.d.ts +17 -0
  80. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatMissingSandboxDepsConfirmationSubPart.js +68 -0
  81. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatModifiedFilesConfirmationSubPart.js +6 -6
  82. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatTerminalToolConfirmationSubPart.js +16 -16
  83. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatTerminalToolProgressPart.js +33 -25
  84. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatToolConfirmationSubPart.js +7 -7
  85. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatToolInvocationPart.js +12 -3
  86. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatToolOutputPart.js +2 -2
  87. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatToolPartUtilities.js +5 -5
  88. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatToolPostExecuteConfirmationPart.js +5 -5
  89. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatDragAndDrop.js +11 -11
  90. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatListRenderer.d.ts +4 -13
  91. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatListRenderer.js +37 -113
  92. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatListWidget.js +1 -1
  93. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatWidget.d.ts +10 -3
  94. package/vscode/src/vs/workbench/contrib/chat/browser/widget/chatWidget.js +66 -39
  95. package/vscode/src/vs/workbench/contrib/chat/browser/widget/input/chatFollowups.js +1 -1
  96. package/vscode/src/vs/workbench/contrib/chat/browser/widget/input/chatInputPart.d.ts +13 -2
  97. package/vscode/src/vs/workbench/contrib/chat/browser/widget/input/chatInputPart.js +103 -61
  98. package/vscode/src/vs/workbench/contrib/chat/browser/widget/input/chatModelPicker.d.ts +2 -1
  99. package/vscode/src/vs/workbench/contrib/chat/browser/widget/input/chatModelPicker.js +35 -23
  100. package/vscode/src/vs/workbench/contrib/chat/browser/widget/input/delegationSessionPickerActionItem.d.ts +4 -4
  101. package/vscode/src/vs/workbench/contrib/chat/browser/widget/input/delegationSessionPickerActionItem.js +6 -6
  102. package/vscode/src/vs/workbench/contrib/chat/browser/widget/input/modePickerActionItem.js +5 -5
  103. package/vscode/src/vs/workbench/contrib/chat/browser/widget/input/modelPickerActionItem2.d.ts +1 -0
  104. package/vscode/src/vs/workbench/contrib/chat/browser/widget/input/modelPickerActionItem2.js +4 -1
  105. package/vscode/src/vs/workbench/contrib/chat/browser/widget/input/permissionPickerActionItem.d.ts +2 -1
  106. package/vscode/src/vs/workbench/contrib/chat/browser/widget/input/permissionPickerActionItem.js +39 -24
  107. package/vscode/src/vs/workbench/contrib/chat/browser/widget/input/sessionTargetPickerActionItem.d.ts +6 -5
  108. package/vscode/src/vs/workbench/contrib/chat/browser/widget/input/sessionTargetPickerActionItem.js +44 -18
  109. package/vscode/src/vs/workbench/contrib/chat/browser/widget/input/workspacePickerActionItem.js +3 -3
  110. package/vscode/src/vs/workbench/contrib/chat/browser/widget/media/chat.css +60 -10
  111. package/vscode/src/vs/workbench/contrib/chat/browser/widgetHosts/viewPane/chatContextUsageDetails.js +7 -7
  112. package/vscode/src/vs/workbench/contrib/chat/browser/widgetHosts/viewPane/chatContextUsageWidget.js +2 -2
  113. package/vscode/src/vs/workbench/contrib/chat/common/chatImageExtraction.js +6 -6
  114. package/vscode/src/vs/workbench/contrib/chat/common/widget/chatColors.js +15 -15
  115. package/vscode/src/vs/workbench/contrib/chat/common/widget/codeBlockModelCollection.js +4 -0
  116. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.js +4 -4
  117. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatOverlayWidget.js +5 -5
  118. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatSessionService.d.ts +4 -1
  119. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatSessionService.js +5 -2
  120. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatWidget.js +6 -11
  121. package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatZoneWidget.js +1 -1
  122. package/vscode/src/vs/workbench/contrib/inlineChat/common/inlineChat.js +39 -39
  123. package/vscode/src/vs/workbench/contrib/interactive/browser/replInputHintContentWidget.js +3 -3
  124. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/executionStatusBarItemController.js +7 -7
  125. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindWidget.js +2 -2
  126. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/cellOperations.d.ts +26 -0
  127. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/cellOperations.js +746 -0
  128. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/insertCellActions.d.ts +13 -0
  129. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/insertCellActions.js +300 -0
  130. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffCellEditorOptions.d.ts +8 -0
  131. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffCellEditorOptions.js +55 -0
  132. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffComponents.d.ts +273 -0
  133. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffComponents.js +1963 -0
  134. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffElementOutputs.d.ts +50 -0
  135. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffElementOutputs.js +314 -0
  136. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffElementViewModel.d.ts +258 -0
  137. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffElementViewModel.js +886 -0
  138. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffNestedCellViewModel.d.ts +41 -0
  139. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffNestedCellViewModel.js +118 -0
  140. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/editorHeightCalculator.d.ts +17 -0
  141. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/editorHeightCalculator.js +71 -0
  142. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/eventDispatcher.d.ts +27 -0
  143. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/eventDispatcher.js +40 -0
  144. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookCellDiffDecorator.d.ts +23 -0
  145. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookCellDiffDecorator.js +313 -0
  146. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookDeletedCellDecorator.d.ts +51 -0
  147. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookDeletedCellDecorator.js +265 -0
  148. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookInlineDiff.d.ts +24 -0
  149. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookInlineDiff.js +185 -0
  150. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookInlineDiffWidget.d.ts +28 -0
  151. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookInlineDiffWidget.js +104 -0
  152. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookInsertedCellDecorator.d.ts +10 -0
  153. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookInsertedCellDecorator.js +43 -0
  154. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookOriginalCellModelFactory.d.ts +21 -0
  155. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookOriginalCellModelFactory.js +41 -0
  156. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookOriginalModelRefFactory.d.ts +25 -0
  157. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookOriginalModelRefFactory.js +69 -0
  158. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiff.css +469 -0
  159. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.d.ts +149 -0
  160. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.js +933 -0
  161. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser.d.ts +180 -0
  162. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser.js +32 -0
  163. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffList.d.ts +102 -0
  164. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffList.js +643 -0
  165. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffOverviewRuler.d.ts +30 -0
  166. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffOverviewRuler.js +197 -0
  167. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffViewModel.d.ts +75 -0
  168. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffViewModel.js +539 -0
  169. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/unchangedEditorRegions.d.ts +13 -0
  170. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/unchangedEditorRegions.js +39 -0
  171. package/vscode/src/vs/workbench/contrib/notebook/common/model/notebookMetadataTextModel.d.ts +19 -0
  172. package/vscode/src/vs/workbench/contrib/notebook/common/model/notebookMetadataTextModel.js +90 -0
  173. package/vscode/src/vs/workbench/contrib/notebook/common/notebookDiff.d.ts +26 -0
  174. package/vscode/src/vs/workbench/contrib/notebook/common/notebookDiff.js +92 -0
  175. package/vscode/src/vs/workbench/contrib/replNotebook/browser/replEditor.js +1 -1
  176. package/vscode/src/vs/workbench/contrib/replNotebook/browser/replEditorInput.js +1 -1
  177. package/vscode/src/vs/workbench/contrib/chat/browser/chatSessions/chatSessions.contribution.d.ts +0 -152
  178. package/vscode/src/vs/workbench/contrib/chat/browser/chatSessions/chatSessions.contribution.js +0 -1317
  179. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/internalCustomizations/internalPromptFileSystem.d.ts +0 -47
  180. package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/internalCustomizations/internalPromptFileSystem.js +0 -95
@@ -0,0 +1,746 @@
1
+
2
+ import { ResourceTextEdit } from '@codingame/monaco-vscode-api/vscode/vs/editor/browser/services/bulkEditService';
3
+ import { Position } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/core/position';
4
+ import { Range } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/core/range';
5
+ import { EndOfLinePreference } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/model';
6
+ import { PLAINTEXT_LANGUAGE_ID } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/languages/modesRegistry';
7
+ import { ResourceNotebookCellEdit } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/bulkEdit/browser/bulkCellEdits';
8
+ import { CellEditState, expandCellRangesWithHiddenCells, CellFocusMode } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/browser/notebookBrowser';
9
+ import { cloneNotebookCellTextModel } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
10
+ import { CellEditType, SelectionStateType, CellKind } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookCommon';
11
+ import { cellRangeContains, cellRangesToIndexes } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookRange';
12
+ import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls';
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(11084, "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(11085, "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 };