From ca01229a2ff1e20ad0b9405bff82b44cc050d056 Mon Sep 17 00:00:00 2001 From: Michael Lively Date: Thu, 25 Jul 2024 15:21:17 -0700 Subject: [PATCH] fix selection bugs --- .../contrib/notebook/browser/controller/coreActions.ts | 4 +++- .../contrib/notebook/browser/controller/editActions.ts | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/contrib/notebook/browser/controller/coreActions.ts b/src/vs/workbench/contrib/notebook/browser/controller/coreActions.ts index 8ef65e7a12137..4a8192b5e2461 100644 --- a/src/vs/workbench/contrib/notebook/browser/controller/coreActions.ts +++ b/src/vs/workbench/contrib/notebook/browser/controller/coreActions.ts @@ -250,12 +250,14 @@ export abstract class NotebookMultiCellAction extends Action2 { // no parsed args, try handle active editor const editor = getEditorFromArgsOrActivePane(accessor); if (editor) { + const selectedCellRange: ICellRange[] = editor.getSelections().length === 0 ? [editor.getFocus()] : editor.getSelections(); + telemetryService.publicLog2('workbenchActionExecuted', { id: this.desc.id, from: from }); return this.runWithContext(accessor, { ui: false, notebookEditor: editor, - selectedCells: cellRangeToViewCells(editor, editor.getSelections()) + selectedCells: cellRangeToViewCells(editor, selectedCellRange) }); } } diff --git a/src/vs/workbench/contrib/notebook/browser/controller/editActions.ts b/src/vs/workbench/contrib/notebook/browser/controller/editActions.ts index 4baa123f7af89..5fde252d05256 100644 --- a/src/vs/workbench/contrib/notebook/browser/controller/editActions.ts +++ b/src/vs/workbench/contrib/notebook/browser/controller/editActions.ts @@ -634,10 +634,8 @@ registerAction2(class CommentSelectedCellsAction extends NotebookMultiCellAction keybinding: { when: ContextKeyExpr.and( NOTEBOOK_EDITOR_FOCUSED, - NOTEBOOK_CELL_LIST_FOCUSED, - ContextKeyExpr.not(InputFocusedContextKey), NOTEBOOK_EDITOR_EDITABLE, - NOTEBOOK_CELL_EDITABLE + ContextKeyExpr.not(InputFocusedContextKey), ), primary: KeyMod.CtrlCmd | KeyCode.Slash, weight: KeybindingWeight.WorkbenchContrib @@ -657,6 +655,7 @@ registerAction2(class CommentSelectedCellsAction extends NotebookMultiCellAction } }); + selectedCellEditors.forEach(editor => { if (!editor.hasModel()) { return; @@ -667,6 +666,8 @@ registerAction2(class CommentSelectedCellsAction extends NotebookMultiCellAction const modelOptions = model.getOptions(); const commentsOptions = editor.getOption(EditorOption.comments); + const selection = editor.getSelection(); + commands.push(new LineCommentCommand( languageConfigurationService, new Selection(1, 1, model.getLineCount(), model.getLineMaxColumn(model.getLineCount())), @@ -680,6 +681,8 @@ registerAction2(class CommentSelectedCellsAction extends NotebookMultiCellAction editor.pushUndoStop(); editor.executeCommands(COMMENT_SELECTED_CELLS_ID, commands); editor.pushUndoStop(); + + editor.setSelection(selection); }); }