Skip to content

Commit bcbdd8e

Browse files
authored
Fix cell selection state bugs (microsoft#223794)
fix selection bugs
1 parent 4dfbe67 commit bcbdd8e

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/vs/workbench/contrib/notebook/browser/controller/coreActions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,14 @@ export abstract class NotebookMultiCellAction extends Action2 {
250250
// no parsed args, try handle active editor
251251
const editor = getEditorFromArgsOrActivePane(accessor);
252252
if (editor) {
253+
const selectedCellRange: ICellRange[] = editor.getSelections().length === 0 ? [editor.getFocus()] : editor.getSelections();
254+
253255
telemetryService.publicLog2<WorkbenchActionExecutedEvent, WorkbenchActionExecutedClassification>('workbenchActionExecuted', { id: this.desc.id, from: from });
254256

255257
return this.runWithContext(accessor, {
256258
ui: false,
257259
notebookEditor: editor,
258-
selectedCells: cellRangeToViewCells(editor, editor.getSelections())
260+
selectedCells: cellRangeToViewCells(editor, selectedCellRange)
259261
});
260262
}
261263
}

src/vs/workbench/contrib/notebook/browser/controller/editActions.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,10 +634,8 @@ registerAction2(class CommentSelectedCellsAction extends NotebookMultiCellAction
634634
keybinding: {
635635
when: ContextKeyExpr.and(
636636
NOTEBOOK_EDITOR_FOCUSED,
637-
NOTEBOOK_CELL_LIST_FOCUSED,
638-
ContextKeyExpr.not(InputFocusedContextKey),
639637
NOTEBOOK_EDITOR_EDITABLE,
640-
NOTEBOOK_CELL_EDITABLE
638+
ContextKeyExpr.not(InputFocusedContextKey),
641639
),
642640
primary: KeyMod.CtrlCmd | KeyCode.Slash,
643641
weight: KeybindingWeight.WorkbenchContrib
@@ -657,6 +655,7 @@ registerAction2(class CommentSelectedCellsAction extends NotebookMultiCellAction
657655
}
658656
});
659657

658+
660659
selectedCellEditors.forEach(editor => {
661660
if (!editor.hasModel()) {
662661
return;
@@ -667,6 +666,8 @@ registerAction2(class CommentSelectedCellsAction extends NotebookMultiCellAction
667666
const modelOptions = model.getOptions();
668667
const commentsOptions = editor.getOption(EditorOption.comments);
669668

669+
const selection = editor.getSelection();
670+
670671
commands.push(new LineCommentCommand(
671672
languageConfigurationService,
672673
new Selection(1, 1, model.getLineCount(), model.getLineMaxColumn(model.getLineCount())),
@@ -680,6 +681,8 @@ registerAction2(class CommentSelectedCellsAction extends NotebookMultiCellAction
680681
editor.pushUndoStop();
681682
editor.executeCommands(COMMENT_SELECTED_CELLS_ID, commands);
682683
editor.pushUndoStop();
684+
685+
editor.setSelection(selection);
683686
});
684687
}
685688

0 commit comments

Comments
 (0)