Skip to content

Commit 1fe14a9

Browse files
authored
create editor integration for Code editors within notebooks (microsoft#257911)
* create editor integration for Code editors within notebooks * push notebook function into notebook file
1 parent ed9f03c commit 1fe14a9

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import { IChatAttachmentResolveService } from '../../chat/browser/chatAttachment
6464
import { INotebookService } from '../../notebook/common/notebookService.js';
6565
import { ICellEditOperation } from '../../notebook/common/notebookCommon.js';
6666
import { INotebookEditor } from '../../notebook/browser/notebookBrowser.js';
67+
import { isNotebookContainingCellEditor as isNotebookWithCellEditor } from '../../notebook/browser/notebookEditor.js';
6768

6869
export const enum State {
6970
CREATE_SESSION = 'CREATE_SESSION',
@@ -1425,7 +1426,7 @@ export class InlineChatController2 implements IEditorContribution {
14251426

14261427
const session = visibleSessionObs.read(r);
14271428
const entry = session?.editingSession.readEntry(session.uri, r);
1428-
const pane = this._editorService.visibleEditorPanes.find(candidate => candidate.getControl() === this._editor);
1429+
const pane = this._editorService.visibleEditorPanes.find(candidate => candidate.getControl() === this._editor || isNotebookWithCellEditor(candidate, this._editor));
14291430
if (pane && entry) {
14301431
entry?.getEditorIntegration(pane);
14311432
}

src/vs/workbench/contrib/notebook/browser/notebookEditor.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { ITelemetryService } from '../../../../platform/telemetry/common/telemet
2424
import { IThemeService } from '../../../../platform/theme/common/themeService.js';
2525
import { Selection } from '../../../../editor/common/core/selection.js';
2626
import { EditorPane } from '../../../browser/parts/editor/editorPane.js';
27-
import { DEFAULT_EDITOR_ASSOCIATION, EditorPaneSelectionChangeReason, EditorPaneSelectionCompareResult, EditorResourceAccessor, IEditorMemento, IEditorOpenContext, IEditorPaneScrollPosition, IEditorPaneSelection, IEditorPaneSelectionChangeEvent, IEditorPaneWithScrolling, createEditorOpenError, createTooLargeFileError, isEditorOpenError } from '../../../common/editor.js';
27+
import { DEFAULT_EDITOR_ASSOCIATION, EditorPaneSelectionChangeReason, EditorPaneSelectionCompareResult, EditorResourceAccessor, IEditorMemento, IEditorOpenContext, IEditorPane, IEditorPaneScrollPosition, IEditorPaneSelection, IEditorPaneSelectionChangeEvent, IEditorPaneWithScrolling, createEditorOpenError, createTooLargeFileError, isEditorOpenError } from '../../../common/editor.js';
2828
import { EditorInput } from '../../../common/editor/editorInput.js';
2929
import { SELECT_KERNEL_ID } from './controller/coreActions.js';
3030
import { INotebookEditorOptions, INotebookEditorPane, INotebookEditorViewState } from './notebookBrowser.js';
@@ -48,6 +48,7 @@ import { ILogService } from '../../../../platform/log/common/log.js';
4848
import { IPreferencesService } from '../../../services/preferences/common/preferences.js';
4949
import { IActionViewItemOptions } from '../../../../base/browser/ui/actionbar/actionViewItems.js';
5050
import { StopWatch } from '../../../../base/common/stopwatch.js';
51+
import { ICodeEditor } from '../../../../editor/browser/editorBrowser.js';
5152

5253
const NOTEBOOK_EDITOR_VIEW_STATE_PREFERENCE_KEY = 'NotebookEditorViewState';
5354

@@ -658,3 +659,17 @@ class NotebookEditorSelection implements IEditorPaneSelection {
658659
return this.cellUri.fragment;
659660
}
660661
}
662+
663+
export function isNotebookContainingCellEditor(editor: IEditorPane | undefined, codeEditor: ICodeEditor): boolean {
664+
if (editor?.getId() === NotebookEditor.ID) {
665+
const notebookWidget = editor.getControl() as NotebookEditorWidget;
666+
if (notebookWidget) {
667+
for (const [_, editor] of notebookWidget.codeEditors) {
668+
if (editor === codeEditor) {
669+
return true;
670+
}
671+
}
672+
}
673+
}
674+
return false;
675+
}

0 commit comments

Comments
 (0)