@codingame/monaco-vscode-katex-common 26.1.2 → 26.2.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 (17) hide show
  1. package/package.json +2 -2
  2. package/vscode/src/vs/workbench/contrib/interactive/browser/interactiveCommon.d.ts +7 -0
  3. package/vscode/src/vs/workbench/contrib/interactive/browser/interactiveCommon.js +11 -0
  4. package/vscode/src/vs/workbench/contrib/interactive/browser/replInputHintContentWidget.d.ts +20 -0
  5. package/vscode/src/vs/workbench/contrib/interactive/browser/replInputHintContentWidget.js +150 -0
  6. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/executionStatusBarItemController.d.ts +22 -0
  7. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/executionStatusBarItemController.js +338 -0
  8. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/notebookVisibleCellObserver.d.ts +18 -0
  9. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/notebookVisibleCellObserver.js +58 -0
  10. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindWidget.d.ts +75 -0
  11. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindWidget.js +364 -0
  12. package/vscode/src/vs/workbench/contrib/replNotebook/browser/interactiveEditor.css +21 -0
  13. package/vscode/src/vs/workbench/contrib/replNotebook/browser/media/interactive.css +36 -0
  14. package/vscode/src/vs/workbench/contrib/replNotebook/browser/replEditor.d.ts +110 -0
  15. package/vscode/src/vs/workbench/contrib/replNotebook/browser/replEditor.js +692 -0
  16. package/vscode/src/vs/workbench/contrib/replNotebook/browser/replEditorInput.d.ts +40 -0
  17. package/vscode/src/vs/workbench/contrib/replNotebook/browser/replEditorInput.js +158 -0
@@ -0,0 +1,692 @@
1
+
2
+ import { registerCss } from '@codingame/monaco-vscode-api/css';
3
+ import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
4
+ import * as interactive from './media/interactive.css';
5
+ import { $, append, Dimension } from '@codingame/monaco-vscode-api/vscode/vs/base/browser/dom';
6
+ import { createStyleSheet } from '@codingame/monaco-vscode-api/vscode/vs/base/browser/domStylesheets';
7
+ import { Emitter, Event } from '@codingame/monaco-vscode-api/vscode/vs/base/common/event';
8
+ import { DisposableStore, MutableDisposable } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
9
+ import { CodeEditorWidget } from '@codingame/monaco-vscode-api/vscode/vs/editor/browser/widget/codeEditor/codeEditorWidget';
10
+ import { IContextKeyService } from '@codingame/monaco-vscode-api/vscode/vs/platform/contextkey/common/contextkey.service';
11
+ import { IInstantiationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation';
12
+ import { IStorageService } from '@codingame/monaco-vscode-api/vscode/vs/platform/storage/common/storage.service';
13
+ import { ITelemetryService } from '@codingame/monaco-vscode-api/vscode/vs/platform/telemetry/common/telemetry.service';
14
+ import { IThemeService } from '@codingame/monaco-vscode-api/vscode/vs/platform/theme/common/themeService.service';
15
+ import { EditorPane } from '@codingame/monaco-vscode-api/vscode/vs/workbench/browser/parts/editor/editorPane';
16
+ import { EditorPaneSelectionChangeReason } from '@codingame/monaco-vscode-api/vscode/vs/workbench/common/editor';
17
+ import { getSimpleEditorOptions } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/codeEditor/browser/simpleEditorOptions';
18
+ import { NotebookEditorExtensionsRegistry } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/browser/notebookEditorExtensions';
19
+ import { INotebookEditorService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/browser/services/notebookEditorService.service';
20
+ import { getDefaultNotebookCreationOptions, NotebookEditorWidget } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/browser/notebookEditorWidget';
21
+ import { GroupsOrder } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorGroupsService';
22
+ import { IEditorGroupsService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorGroupsService.service';
23
+ import { ExecutionStateCellStatusBarContrib, TimerCellStatusBarContrib } from '../../notebook/browser/contrib/cellStatusBar/executionStatusBarItemController.js';
24
+ import { INotebookKernelService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookKernelService.service';
25
+ import { ILanguageService } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/languages/language.service';
26
+ import { MenuId } from '@codingame/monaco-vscode-api/vscode/vs/platform/actions/common/actions';
27
+ import { IMenuService } from '@codingame/monaco-vscode-api/vscode/vs/platform/actions/common/actions.service';
28
+ import { IKeybindingService } from '@codingame/monaco-vscode-api/vscode/vs/platform/keybinding/common/keybinding.service';
29
+ import { INTERACTIVE_INPUT_CURSOR_BOUNDARY, ReplEditorSettings } from '../../interactive/browser/interactiveCommon.js';
30
+ import { IConfigurationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configuration.service';
31
+ import { NotebookOptions } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/browser/notebookOptions';
32
+ import { ToolBar } from '@codingame/monaco-vscode-api/vscode/vs/base/browser/ui/toolbar/toolbar';
33
+ import { IContextMenuService } from '@codingame/monaco-vscode-api/vscode/vs/platform/contextview/browser/contextView.service';
34
+ import { createActionViewItem, getActionBarActions } from '@codingame/monaco-vscode-api/vscode/vs/platform/actions/browser/menuEntryActionViewItem';
35
+ import { EditorExtensionsRegistry } from '@codingame/monaco-vscode-api/vscode/vs/editor/browser/editorExtensions';
36
+ import { SelectionClipboardContributionID } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/codeEditor/browser/selectionClipboard';
37
+ import { ContextMenuController } from '@codingame/monaco-vscode-api/vscode/vs/editor/contrib/contextmenu/browser/contextmenu';
38
+ import { SuggestController } from '@codingame/monaco-vscode-api/vscode/vs/editor/contrib/suggest/browser/suggestController';
39
+ import { MarkerController } from '@codingame/monaco-vscode-api/vscode/vs/editor/contrib/gotoError/browser/gotoError';
40
+ import { ITextResourceConfigurationService } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/services/textResourceConfiguration.service';
41
+ import { TextEditorSelectionSource } from '@codingame/monaco-vscode-api/vscode/vs/platform/editor/common/editor';
42
+ import { NotebookExecutionType } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookExecutionStateService';
43
+ import { INotebookExecutionStateService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookExecutionStateService.service';
44
+ import { NOTEBOOK_KERNEL } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookContextKeys';
45
+ import { IExtensionService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/extensions/common/extensions.service';
46
+ import { isEqual } from '@codingame/monaco-vscode-api/vscode/vs/base/common/resources';
47
+ import { NotebookFindContrib } from '../../notebook/browser/contrib/find/notebookFindWidget.js';
48
+ import { REPL_EDITOR_ID } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookCommon';
49
+ import * as interactiveEditor from './interactiveEditor.css';
50
+ import { deepClone } from '@codingame/monaco-vscode-api/vscode/vs/base/common/objects';
51
+ import { GlyphHoverController } from '@codingame/monaco-vscode-api/vscode/vs/editor/contrib/hover/browser/glyphHoverController';
52
+ import { ContentHoverController } from '@codingame/monaco-vscode-api/vscode/vs/editor/contrib/hover/browser/contentHoverController';
53
+ import { ReplEditorInput } from './replEditorInput.js';
54
+ import { ReplInputHintContentWidget } from '../../interactive/browser/replInputHintContentWidget.js';
55
+ import { ServiceCollection } from '@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/serviceCollection';
56
+ import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls';
57
+ import { IAccessibilityService } from '@codingame/monaco-vscode-api/vscode/vs/platform/accessibility/common/accessibility.service';
58
+
59
+ registerCss(interactive);
60
+ registerCss(interactiveEditor);
61
+ const INTERACTIVE_EDITOR_VIEW_STATE_PREFERENCE_KEY = "InteractiveEditorViewState";
62
+ const INPUT_CELL_VERTICAL_PADDING = 8;
63
+ const INPUT_CELL_HORIZONTAL_PADDING_RIGHT = 10;
64
+ const INPUT_EDITOR_PADDING = 8;
65
+ let ReplEditor = class ReplEditor extends EditorPane {
66
+ get onDidFocus() {
67
+ return this._onDidFocusWidget.event;
68
+ }
69
+ constructor(
70
+ group,
71
+ telemetryService,
72
+ themeService,
73
+ storageService,
74
+ instantiationService,
75
+ notebookWidgetService,
76
+ contextKeyService,
77
+ notebookKernelService,
78
+ languageService,
79
+ keybindingService,
80
+ configurationService,
81
+ menuService,
82
+ contextMenuService,
83
+ editorGroupService,
84
+ textResourceConfigurationService,
85
+ notebookExecutionStateService,
86
+ extensionService,
87
+ _accessibilityService
88
+ ) {
89
+ super(REPL_EDITOR_ID, group, telemetryService, themeService, storageService);
90
+ this._accessibilityService = _accessibilityService;
91
+ this._notebookWidget = {
92
+ value: undefined
93
+ };
94
+ this._widgetDisposableStore = this._register(( new DisposableStore()));
95
+ this._groupListener = this._register(( new MutableDisposable()));
96
+ this._onDidFocusWidget = this._register(( new Emitter()));
97
+ this._onDidChangeSelection = this._register(( new Emitter()));
98
+ this.onDidChangeSelection = this._onDidChangeSelection.event;
99
+ this._onDidChangeScroll = this._register(( new Emitter()));
100
+ this.onDidChangeScroll = this._onDidChangeScroll.event;
101
+ this._notebookWidgetService = notebookWidgetService;
102
+ this._configurationService = configurationService;
103
+ this._notebookKernelService = notebookKernelService;
104
+ this._languageService = languageService;
105
+ this._keybindingService = keybindingService;
106
+ this._menuService = menuService;
107
+ this._contextMenuService = contextMenuService;
108
+ this._editorGroupService = editorGroupService;
109
+ this._extensionService = extensionService;
110
+ this._rootElement = $(".interactive-editor");
111
+ this._contextKeyService = this._register(contextKeyService.createScoped(this._rootElement));
112
+ this._contextKeyService.createKey("isCompositeNotebook", true);
113
+ this._instantiationService = this._register(instantiationService.createChild(( new ServiceCollection([IContextKeyService, this._contextKeyService]))));
114
+ this._editorOptions = this._computeEditorOptions();
115
+ this._register(this._configurationService.onDidChangeConfiguration(e => {
116
+ if (e.affectsConfiguration("editor") || e.affectsConfiguration("notebook")) {
117
+ this._editorOptions = this._computeEditorOptions();
118
+ }
119
+ }));
120
+ this._notebookOptions = instantiationService.createInstance(NotebookOptions, this.window, true, {
121
+ cellToolbarInteraction: "hover",
122
+ globalToolbar: true,
123
+ stickyScrollEnabled: false,
124
+ dragAndDropEnabled: false,
125
+ disableRulers: true
126
+ });
127
+ this._editorMemento = this.getEditorMemento(
128
+ editorGroupService,
129
+ textResourceConfigurationService,
130
+ INTERACTIVE_EDITOR_VIEW_STATE_PREFERENCE_KEY
131
+ );
132
+ this._register(
133
+ this._keybindingService.onDidUpdateKeybindings(this._updateInputHint, this)
134
+ );
135
+ this._register(notebookExecutionStateService.onDidChangeExecution(e => {
136
+ if (e.type === NotebookExecutionType.cell && isEqual(e.notebook, this._notebookWidget.value?.viewModel?.notebookDocument.uri)) {
137
+ const cell = this._notebookWidget.value?.getCellByHandle(e.cellHandle);
138
+ if (cell && e.changed?.state) {
139
+ this._scrollIfNecessary(cell);
140
+ }
141
+ }
142
+ }));
143
+ }
144
+ get inputCellContainerHeight() {
145
+ return 19 + 2 + INPUT_CELL_VERTICAL_PADDING * 2 + INPUT_EDITOR_PADDING * 2;
146
+ }
147
+ get inputCellEditorHeight() {
148
+ return 19 + INPUT_EDITOR_PADDING * 2;
149
+ }
150
+ createEditor(parent) {
151
+ append(parent, this._rootElement);
152
+ this._rootElement.style.position = "relative";
153
+ this._notebookEditorContainer = append(this._rootElement, $(".notebook-editor-container"));
154
+ this._inputCellContainer = append(this._rootElement, $(".input-cell-container"));
155
+ this._inputCellContainer.style.position = "absolute";
156
+ this._inputCellContainer.style.height = `${this.inputCellContainerHeight}px`;
157
+ this._inputFocusIndicator = append(this._inputCellContainer, $(".input-focus-indicator"));
158
+ this._inputRunButtonContainer = append(this._inputCellContainer, $(".run-button-container"));
159
+ this._setupRunButtonToolbar(this._inputRunButtonContainer);
160
+ this._inputEditorContainer = append(this._inputCellContainer, $(".input-editor-container"));
161
+ this._createLayoutStyles();
162
+ }
163
+ _setupRunButtonToolbar(runButtonContainer) {
164
+ const menu = this._register(
165
+ this._menuService.createMenu(MenuId.ReplInputExecute, this._contextKeyService)
166
+ );
167
+ this._runbuttonToolbar = this._register(( new ToolBar(runButtonContainer, this._contextMenuService, {
168
+ getKeyBinding: action => this._keybindingService.lookupKeybinding(action.id),
169
+ actionViewItemProvider: (action, options) => {
170
+ return createActionViewItem(this._instantiationService, action, options);
171
+ },
172
+ renderDropdownAsChildElement: true
173
+ })));
174
+ const {
175
+ primary,
176
+ secondary
177
+ } = getActionBarActions(menu.getActions({
178
+ shouldForwardArgs: true
179
+ }));
180
+ this._runbuttonToolbar.setActions([...primary, ...secondary]);
181
+ }
182
+ _createLayoutStyles() {
183
+ this._styleElement = createStyleSheet(this._rootElement);
184
+ const styleSheets = [];
185
+ const {
186
+ codeCellLeftMargin,
187
+ cellRunGutter
188
+ } = this._notebookOptions.getLayoutConfiguration();
189
+ const {
190
+ focusIndicator
191
+ } = this._notebookOptions.getDisplayOptions();
192
+ const leftMargin = this._notebookOptions.getCellEditorContainerLeftMargin();
193
+ styleSheets.push(`
194
+ .interactive-editor .input-cell-container {
195
+ padding: ${INPUT_CELL_VERTICAL_PADDING}px ${INPUT_CELL_HORIZONTAL_PADDING_RIGHT}px ${INPUT_CELL_VERTICAL_PADDING}px ${leftMargin}px;
196
+ }
197
+ `);
198
+ if (focusIndicator === "gutter") {
199
+ styleSheets.push(`
200
+ .interactive-editor .input-cell-container:focus-within .input-focus-indicator::before {
201
+ border-color: var(--vscode-notebook-focusedCellBorder) !important;
202
+ }
203
+ .interactive-editor .input-focus-indicator::before {
204
+ border-color: var(--vscode-notebook-inactiveFocusedCellBorder) !important;
205
+ }
206
+ .interactive-editor .input-cell-container .input-focus-indicator {
207
+ display: block;
208
+ top: ${INPUT_CELL_VERTICAL_PADDING}px;
209
+ }
210
+ .interactive-editor .input-cell-container {
211
+ border-top: 1px solid var(--vscode-notebook-inactiveFocusedCellBorder);
212
+ }
213
+ `);
214
+ } else {
215
+ styleSheets.push(`
216
+ .interactive-editor .input-cell-container {
217
+ border-top: 1px solid var(--vscode-notebook-inactiveFocusedCellBorder);
218
+ }
219
+ .interactive-editor .input-cell-container .input-focus-indicator {
220
+ display: none;
221
+ }
222
+ `);
223
+ }
224
+ styleSheets.push(`
225
+ .interactive-editor .input-cell-container .run-button-container {
226
+ width: ${cellRunGutter}px;
227
+ left: ${codeCellLeftMargin}px;
228
+ margin-top: ${INPUT_EDITOR_PADDING - 2}px;
229
+ }
230
+ `);
231
+ this._styleElement.textContent = styleSheets.join("\n");
232
+ }
233
+ _computeEditorOptions() {
234
+ let overrideIdentifier = undefined;
235
+ if (this._codeEditorWidget) {
236
+ overrideIdentifier = this._codeEditorWidget.getModel()?.getLanguageId();
237
+ }
238
+ const editorOptions = deepClone(this._configurationService.getValue("editor", {
239
+ overrideIdentifier
240
+ }));
241
+ const editorOptionsOverride = getSimpleEditorOptions(this._configurationService);
242
+ const computed = ( Object.freeze({
243
+ ...editorOptions,
244
+ ...editorOptionsOverride,
245
+ ...{
246
+ ariaLabel: ( localize(10927, "REPL Input")),
247
+ glyphMargin: true,
248
+ padding: {
249
+ top: INPUT_EDITOR_PADDING,
250
+ bottom: INPUT_EDITOR_PADDING
251
+ },
252
+ hover: {
253
+ enabled: "on"
254
+ },
255
+ rulers: []
256
+ }
257
+ }));
258
+ return computed;
259
+ }
260
+ saveState() {
261
+ this._saveEditorViewState(this.input);
262
+ super.saveState();
263
+ }
264
+ getViewState() {
265
+ const input = this.input;
266
+ if (!(input instanceof ReplEditorInput)) {
267
+ return undefined;
268
+ }
269
+ this._saveEditorViewState(input);
270
+ return this._loadNotebookEditorViewState(input);
271
+ }
272
+ _saveEditorViewState(input) {
273
+ if (this._notebookWidget.value && input instanceof ReplEditorInput) {
274
+ if (this._notebookWidget.value.isDisposed) {
275
+ return;
276
+ }
277
+ const state = this._notebookWidget.value.getEditorViewState();
278
+ const editorState = this._codeEditorWidget.saveViewState();
279
+ this._editorMemento.saveEditorState(this.group, input.resource, {
280
+ notebook: state,
281
+ input: editorState
282
+ });
283
+ }
284
+ }
285
+ _loadNotebookEditorViewState(input) {
286
+ const result = this._editorMemento.loadEditorState(this.group, input.resource);
287
+ if (result) {
288
+ return result;
289
+ }
290
+ for (const group of this._editorGroupService.getGroups(GroupsOrder.MOST_RECENTLY_ACTIVE)) {
291
+ if (group.activeEditorPane !== this && group.activeEditorPane === this && group.activeEditor?.matches(input)) {
292
+ const notebook = this._notebookWidget.value?.getEditorViewState();
293
+ const input = this._codeEditorWidget.saveViewState();
294
+ return {
295
+ notebook,
296
+ input
297
+ };
298
+ }
299
+ }
300
+ return;
301
+ }
302
+ async setInput(input, options, context, token) {
303
+ this._notebookWidget.value?.onWillHide();
304
+ this._codeEditorWidget?.dispose();
305
+ this._widgetDisposableStore.clear();
306
+ this._notebookWidget = this._instantiationService.invokeFunction(this._notebookWidgetService.retrieveWidget, this.group.id, input, {
307
+ isReplHistory: true,
308
+ isReadOnly: true,
309
+ contributions: NotebookEditorExtensionsRegistry.getSomeEditorContributions([
310
+ ExecutionStateCellStatusBarContrib.id,
311
+ TimerCellStatusBarContrib.id,
312
+ NotebookFindContrib.id
313
+ ]),
314
+ menuIds: {
315
+ notebookToolbar: MenuId.InteractiveToolbar,
316
+ cellTitleToolbar: MenuId.InteractiveCellTitle,
317
+ cellDeleteToolbar: MenuId.InteractiveCellDelete,
318
+ cellInsertToolbar: MenuId.NotebookCellBetween,
319
+ cellTopInsertToolbar: MenuId.NotebookCellListTop,
320
+ cellExecuteToolbar: MenuId.InteractiveCellExecute,
321
+ cellExecutePrimary: undefined
322
+ },
323
+ cellEditorContributions: EditorExtensionsRegistry.getSomeEditorContributions([
324
+ SelectionClipboardContributionID,
325
+ ContextMenuController.ID,
326
+ ContentHoverController.ID,
327
+ GlyphHoverController.ID,
328
+ MarkerController.ID
329
+ ]),
330
+ options: this._notebookOptions,
331
+ codeWindow: this.window
332
+ }, undefined, this.window);
333
+ const skipContributions = [
334
+ "workbench.notebook.cellToolbar",
335
+ "editor.contrib.inlineCompletionsController"
336
+ ];
337
+ const inputContributions = getDefaultNotebookCreationOptions().cellEditorContributions?.filter(c => skipContributions.indexOf(c.id) === -1);
338
+ this._codeEditorWidget = this._instantiationService.createInstance(CodeEditorWidget, this._inputEditorContainer, this._editorOptions, {
339
+ ...{
340
+ isSimpleWidget: false,
341
+ contributions: inputContributions
342
+ }
343
+ });
344
+ if (this._lastLayoutDimensions) {
345
+ this._notebookEditorContainer.style.height = `${this._lastLayoutDimensions.dimension.height - this.inputCellContainerHeight}px`;
346
+ this._notebookWidget.value.layout(new Dimension(
347
+ this._lastLayoutDimensions.dimension.width,
348
+ this._lastLayoutDimensions.dimension.height - this.inputCellContainerHeight
349
+ ), this._notebookEditorContainer);
350
+ const leftMargin = this._notebookOptions.getCellEditorContainerLeftMargin();
351
+ const maxHeight = Math.min(
352
+ this._lastLayoutDimensions.dimension.height / 2,
353
+ this.inputCellEditorHeight
354
+ );
355
+ this._codeEditorWidget.layout(this._validateDimension(
356
+ this._lastLayoutDimensions.dimension.width - leftMargin - INPUT_CELL_HORIZONTAL_PADDING_RIGHT,
357
+ maxHeight
358
+ ));
359
+ this._inputFocusIndicator.style.height = `${this.inputCellEditorHeight}px`;
360
+ this._inputCellContainer.style.top = `${this._lastLayoutDimensions.dimension.height - this.inputCellContainerHeight}px`;
361
+ this._inputCellContainer.style.width = `${this._lastLayoutDimensions.dimension.width}px`;
362
+ }
363
+ await super.setInput(input, options, context, token);
364
+ const model = await input.resolve();
365
+ if (this._runbuttonToolbar) {
366
+ this._runbuttonToolbar.context = input.resource;
367
+ }
368
+ if (model === null) {
369
+ throw ( new Error("The REPL model could not be resolved"));
370
+ }
371
+ this._notebookWidget.value?.setParentContextKeyService(this._contextKeyService);
372
+ const viewState = options?.viewState ?? this._loadNotebookEditorViewState(input);
373
+ await this._extensionService.whenInstalledExtensionsRegistered();
374
+ await this._notebookWidget.value.setModel(model.notebook, viewState?.notebook, undefined, "repl");
375
+ model.notebook.setCellCollapseDefault(this._notebookOptions.getCellCollapseDefault());
376
+ this._notebookWidget.value.setOptions({
377
+ isReadOnly: true
378
+ });
379
+ this._widgetDisposableStore.add(this._notebookWidget.value.onDidResizeOutput(cvm => {
380
+ this._scrollIfNecessary(cvm);
381
+ }));
382
+ this._widgetDisposableStore.add(
383
+ this._notebookWidget.value.onDidFocusWidget(() => this._onDidFocusWidget.fire())
384
+ );
385
+ this._widgetDisposableStore.add(this._notebookOptions.onDidChangeOptions(e => {
386
+ if (e.compactView || e.focusIndicator) {
387
+ this._styleElement?.remove();
388
+ this._createLayoutStyles();
389
+ }
390
+ if (this._lastLayoutDimensions && this.isVisible()) {
391
+ this.layout(this._lastLayoutDimensions.dimension, this._lastLayoutDimensions.position);
392
+ }
393
+ if (e.interactiveWindowCollapseCodeCells) {
394
+ model.notebook.setCellCollapseDefault(this._notebookOptions.getCellCollapseDefault());
395
+ }
396
+ }));
397
+ const editorModel = await input.resolveInput(model.notebook);
398
+ this._codeEditorWidget.setModel(editorModel);
399
+ if (viewState?.input) {
400
+ this._codeEditorWidget.restoreViewState(viewState.input);
401
+ }
402
+ this._editorOptions = this._computeEditorOptions();
403
+ this._codeEditorWidget.updateOptions(this._editorOptions);
404
+ this._widgetDisposableStore.add(
405
+ this._codeEditorWidget.onDidFocusEditorWidget(() => this._onDidFocusWidget.fire())
406
+ );
407
+ this._widgetDisposableStore.add(this._codeEditorWidget.onDidContentSizeChange(e => {
408
+ if (!e.contentHeightChanged) {
409
+ return;
410
+ }
411
+ if (this._lastLayoutDimensions) {
412
+ this._layoutWidgets(this._lastLayoutDimensions.dimension, this._lastLayoutDimensions.position);
413
+ }
414
+ }));
415
+ this._widgetDisposableStore.add(
416
+ this._codeEditorWidget.onDidChangeCursorPosition(e => this._onDidChangeSelection.fire({
417
+ reason: this._toEditorPaneSelectionChangeReason(e)
418
+ }))
419
+ );
420
+ this._widgetDisposableStore.add(
421
+ this._codeEditorWidget.onDidChangeModelContent(() => this._onDidChangeSelection.fire({
422
+ reason: EditorPaneSelectionChangeReason.EDIT
423
+ }))
424
+ );
425
+ this._widgetDisposableStore.add(
426
+ this._notebookKernelService.onDidChangeNotebookAffinity(this._syncWithKernel, this)
427
+ );
428
+ this._widgetDisposableStore.add(
429
+ this._notebookKernelService.onDidChangeSelectedNotebooks(this._syncWithKernel, this)
430
+ );
431
+ this._widgetDisposableStore.add(this.themeService.onDidColorThemeChange(() => {
432
+ if (this.isVisible()) {
433
+ this._updateInputHint();
434
+ }
435
+ }));
436
+ this._widgetDisposableStore.add(this._codeEditorWidget.onDidChangeModelContent(() => {
437
+ if (this.isVisible()) {
438
+ this._updateInputHint();
439
+ }
440
+ }));
441
+ this._widgetDisposableStore.add(this._codeEditorWidget.onDidChangeModelDecorations(() => {
442
+ if (this.isVisible()) {
443
+ this._updateInputHint();
444
+ }
445
+ }));
446
+ const cursorAtBoundaryContext = INTERACTIVE_INPUT_CURSOR_BOUNDARY.bindTo(this._contextKeyService);
447
+ if (input.resource && ( input.historyService.has(input.resource))) {
448
+ cursorAtBoundaryContext.set("top");
449
+ } else {
450
+ cursorAtBoundaryContext.set("none");
451
+ }
452
+ this._widgetDisposableStore.add(this._codeEditorWidget.onDidChangeCursorPosition((
453
+ {
454
+ position
455
+ }
456
+ ) => {
457
+ const viewModel = this._codeEditorWidget._getViewModel();
458
+ const lastLineNumber = viewModel.getLineCount();
459
+ const lastLineCol = viewModel.getLineLength(lastLineNumber) + 1;
460
+ const viewPosition = viewModel.coordinatesConverter.convertModelPositionToViewPosition(position);
461
+ const firstLine = viewPosition.lineNumber === 1 && viewPosition.column === 1;
462
+ const lastLine = viewPosition.lineNumber === lastLineNumber && viewPosition.column === lastLineCol;
463
+ if (firstLine) {
464
+ if (lastLine) {
465
+ cursorAtBoundaryContext.set("both");
466
+ } else {
467
+ cursorAtBoundaryContext.set("top");
468
+ }
469
+ } else {
470
+ if (lastLine) {
471
+ cursorAtBoundaryContext.set("bottom");
472
+ } else {
473
+ cursorAtBoundaryContext.set("none");
474
+ }
475
+ }
476
+ }));
477
+ this._widgetDisposableStore.add(editorModel.onDidChangeContent(() => {
478
+ const value = editorModel.getValue();
479
+ if (this.input?.resource && value !== "") {
480
+ const historyService = this.input.historyService;
481
+ if (!historyService.matchesCurrent(this.input.resource, value)) {
482
+ historyService.replaceLast(this.input.resource, value);
483
+ }
484
+ }
485
+ }));
486
+ this._widgetDisposableStore.add(
487
+ this._notebookWidget.value.onDidScroll(() => this._onDidChangeScroll.fire())
488
+ );
489
+ this._widgetDisposableStore.add(
490
+ this._notebookWidget.value.onDidChangeViewCells(this.handleViewCellChange, this)
491
+ );
492
+ this._updateInputHint();
493
+ this._syncWithKernel();
494
+ }
495
+ handleViewCellChange(e) {
496
+ const notebookWidget = this._notebookWidget.value;
497
+ if (!notebookWidget) {
498
+ return;
499
+ }
500
+ for (const splice of e.splices) {
501
+ const [_start, _delete, addedCells] = splice;
502
+ if (addedCells.length) {
503
+ const viewModel = notebookWidget.viewModel;
504
+ if (viewModel) {
505
+ this.handleAppend(notebookWidget, viewModel);
506
+ break;
507
+ }
508
+ }
509
+ }
510
+ }
511
+ handleAppend(notebookWidget, viewModel) {
512
+ this._notebookWidgetService.updateReplContextKey(( viewModel.notebookDocument.uri.toString()));
513
+ const navigateToCell = this._configurationService.getValue("accessibility.replEditor.autoFocusReplExecution");
514
+ if (this._accessibilityService.isScreenReaderOptimized()) {
515
+ if (navigateToCell === "lastExecution") {
516
+ setTimeout(() => {
517
+ const lastCellIndex = viewModel.length - 1;
518
+ if (lastCellIndex >= 0) {
519
+ const cell = viewModel.viewCells[lastCellIndex];
520
+ notebookWidget.focusNotebookCell(cell, "container");
521
+ }
522
+ }, 0);
523
+ } else if (navigateToCell === "input") {
524
+ this._codeEditorWidget.focus();
525
+ }
526
+ }
527
+ }
528
+ setOptions(options) {
529
+ this._notebookWidget.value?.setOptions(options);
530
+ super.setOptions(options);
531
+ }
532
+ _toEditorPaneSelectionChangeReason(e) {
533
+ switch (e.source) {
534
+ case TextEditorSelectionSource.PROGRAMMATIC:
535
+ return EditorPaneSelectionChangeReason.PROGRAMMATIC;
536
+ case TextEditorSelectionSource.NAVIGATION:
537
+ return EditorPaneSelectionChangeReason.NAVIGATION;
538
+ case TextEditorSelectionSource.JUMP:
539
+ return EditorPaneSelectionChangeReason.JUMP;
540
+ default:
541
+ return EditorPaneSelectionChangeReason.USER;
542
+ }
543
+ }
544
+ _cellAtBottom(cell) {
545
+ const visibleRanges = this._notebookWidget.value?.visibleRanges || [];
546
+ const cellIndex = this._notebookWidget.value?.getCellIndex(cell);
547
+ if (cellIndex === Math.max(...( visibleRanges.map(range => range.end - 1)))) {
548
+ return true;
549
+ }
550
+ return false;
551
+ }
552
+ _scrollIfNecessary(cvm) {
553
+ const index = this._notebookWidget.value.getCellIndex(cvm);
554
+ if (index === this._notebookWidget.value.getLength() - 1) {
555
+ if (this._configurationService.getValue(ReplEditorSettings.interactiveWindowAlwaysScrollOnNewCell) || this._cellAtBottom(cvm)) {
556
+ this._notebookWidget.value.scrollToBottom();
557
+ }
558
+ }
559
+ }
560
+ _syncWithKernel() {
561
+ const notebook = this._notebookWidget.value?.textModel;
562
+ const textModel = this._codeEditorWidget.getModel();
563
+ if (notebook && textModel) {
564
+ const info = this._notebookKernelService.getMatchingKernel(notebook);
565
+ const selectedOrSuggested = info.selected ?? (info.suggestions.length === 1 ? info.suggestions[0] : undefined) ?? (info.all.length === 1 ? info.all[0] : undefined);
566
+ if (selectedOrSuggested) {
567
+ const language = selectedOrSuggested.supportedLanguages[0];
568
+ if (language && language !== "plaintext") {
569
+ const newMode = this._languageService.createById(language).languageId;
570
+ textModel.setLanguage(newMode);
571
+ }
572
+ NOTEBOOK_KERNEL.bindTo(this._contextKeyService).set(selectedOrSuggested.id);
573
+ }
574
+ }
575
+ }
576
+ layout(dimension, position) {
577
+ this._rootElement.classList.toggle("mid-width", dimension.width < 1000 && dimension.width >= 600);
578
+ this._rootElement.classList.toggle("narrow-width", dimension.width < 600);
579
+ const editorHeightChanged = dimension.height !== this._lastLayoutDimensions?.dimension.height;
580
+ this._lastLayoutDimensions = {
581
+ dimension,
582
+ position
583
+ };
584
+ if (!this._notebookWidget.value) {
585
+ return;
586
+ }
587
+ if (editorHeightChanged && this._codeEditorWidget) {
588
+ SuggestController.get(this._codeEditorWidget)?.cancelSuggestWidget();
589
+ }
590
+ this._notebookEditorContainer.style.height = `${this._lastLayoutDimensions.dimension.height - this.inputCellContainerHeight}px`;
591
+ this._layoutWidgets(dimension, position);
592
+ }
593
+ _layoutWidgets(dimension, position) {
594
+ const contentHeight = this._codeEditorWidget.hasModel() ? this._codeEditorWidget.getContentHeight() : this.inputCellEditorHeight;
595
+ const maxHeight = Math.min(dimension.height / 2, contentHeight);
596
+ const leftMargin = this._notebookOptions.getCellEditorContainerLeftMargin();
597
+ const inputCellContainerHeight = maxHeight + INPUT_CELL_VERTICAL_PADDING * 2;
598
+ this._notebookEditorContainer.style.height = `${dimension.height - inputCellContainerHeight}px`;
599
+ this._notebookWidget.value.layout(
600
+ dimension.with(dimension.width, dimension.height - inputCellContainerHeight),
601
+ this._notebookEditorContainer,
602
+ position
603
+ );
604
+ this._codeEditorWidget.layout(this._validateDimension(
605
+ dimension.width - leftMargin - INPUT_CELL_HORIZONTAL_PADDING_RIGHT,
606
+ maxHeight
607
+ ));
608
+ this._inputFocusIndicator.style.height = `${contentHeight}px`;
609
+ this._inputCellContainer.style.top = `${dimension.height - inputCellContainerHeight}px`;
610
+ this._inputCellContainer.style.width = `${dimension.width}px`;
611
+ }
612
+ _validateDimension(width, height) {
613
+ return new Dimension(Math.max(0, width), Math.max(0, height));
614
+ }
615
+ _hasConflictingDecoration() {
616
+ return Boolean(this._codeEditorWidget.getLineDecorations(1)?.find(
617
+ d => d.options.beforeContentClassName || d.options.afterContentClassName || d.options.before?.content || d.options.after?.content
618
+ ));
619
+ }
620
+ _updateInputHint() {
621
+ if (!this._codeEditorWidget) {
622
+ return;
623
+ }
624
+ const shouldHide = !this._codeEditorWidget.hasModel() || this._configurationService.getValue(ReplEditorSettings.showExecutionHint) === false || this._codeEditorWidget.getModel().getValueLength() !== 0 || this._hasConflictingDecoration();
625
+ if (!this._hintElement && !shouldHide) {
626
+ this._hintElement = this._instantiationService.createInstance(ReplInputHintContentWidget, this._codeEditorWidget);
627
+ } else if (this._hintElement && shouldHide) {
628
+ this._hintElement.dispose();
629
+ this._hintElement = undefined;
630
+ }
631
+ }
632
+ getScrollPosition() {
633
+ return {
634
+ scrollTop: this._notebookWidget.value?.scrollTop ?? 0,
635
+ scrollLeft: 0
636
+ };
637
+ }
638
+ setScrollPosition(position) {
639
+ this._notebookWidget.value?.setScrollTop(position.scrollTop);
640
+ }
641
+ focus() {
642
+ super.focus();
643
+ this._notebookWidget.value?.onShow();
644
+ this._codeEditorWidget.focus();
645
+ }
646
+ focusHistory() {
647
+ this._notebookWidget.value.focus();
648
+ }
649
+ setEditorVisible(visible) {
650
+ super.setEditorVisible(visible);
651
+ this._groupListener.value = this.group.onWillCloseEditor(e => this._saveEditorViewState(e.editor));
652
+ if (!visible) {
653
+ this._saveEditorViewState(this.input);
654
+ if (this.input && this._notebookWidget.value) {
655
+ this._notebookWidget.value.onWillHide();
656
+ }
657
+ }
658
+ this._updateInputHint();
659
+ }
660
+ clearInput() {
661
+ if (this._notebookWidget.value) {
662
+ this._saveEditorViewState(this.input);
663
+ this._notebookWidget.value.onWillHide();
664
+ }
665
+ this._codeEditorWidget?.dispose();
666
+ this._notebookWidget = {
667
+ value: undefined
668
+ };
669
+ this._widgetDisposableStore.clear();
670
+ super.clearInput();
671
+ }
672
+ getControl() {
673
+ return {
674
+ notebookEditor: this._notebookWidget.value,
675
+ activeCodeEditor: this.getActiveCodeEditor(),
676
+ onDidChangeActiveEditor: Event.None
677
+ };
678
+ }
679
+ getActiveCodeEditor() {
680
+ if (!this._codeEditorWidget) {
681
+ return undefined;
682
+ }
683
+ return this._codeEditorWidget.hasWidgetFocus() || !this._notebookWidget.value?.activeCodeEditor ? this._codeEditorWidget : this._notebookWidget.value.activeCodeEditor;
684
+ }
685
+ };
686
+ ReplEditor = ( __decorate([( __param(1, ITelemetryService)), ( __param(2, IThemeService)), ( __param(3, IStorageService)), ( __param(4, IInstantiationService)), ( __param(5, INotebookEditorService)), ( __param(6, IContextKeyService)), ( __param(7, INotebookKernelService)), ( __param(8, ILanguageService)), ( __param(9, IKeybindingService)), ( __param(10, IConfigurationService)), ( __param(11, IMenuService)), ( __param(12, IContextMenuService)), ( __param(13, IEditorGroupsService)), ( __param(14, ITextResourceConfigurationService)), ( __param(15, INotebookExecutionStateService)), ( __param(16, IExtensionService)), ( __param(17, IAccessibilityService))], ReplEditor));
687
+ function isReplEditorControl(control) {
688
+ const candidate = control;
689
+ return candidate?.activeCodeEditor instanceof CodeEditorWidget && candidate?.notebookEditor instanceof NotebookEditorWidget;
690
+ }
691
+
692
+ export { ReplEditor, isReplEditorControl };