Skip to content

Commit

Permalink
Fix cell selection state bugs (microsoft#223794)
Browse files Browse the repository at this point in the history
fix selection bugs
  • Loading branch information
Yoyokrazy authored Jul 25, 2024
1 parent 4dfbe67 commit bcbdd8e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<WorkbenchActionExecutedEvent, WorkbenchActionExecutedClassification>('workbenchActionExecuted', { id: this.desc.id, from: from });

return this.runWithContext(accessor, {
ui: false,
notebookEditor: editor,
selectedCells: cellRangeToViewCells(editor, editor.getSelections())
selectedCells: cellRangeToViewCells(editor, selectedCellRange)
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -657,6 +655,7 @@ registerAction2(class CommentSelectedCellsAction extends NotebookMultiCellAction
}
});


selectedCellEditors.forEach(editor => {
if (!editor.hasModel()) {
return;
Expand All @@ -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())),
Expand All @@ -680,6 +681,8 @@ registerAction2(class CommentSelectedCellsAction extends NotebookMultiCellAction
editor.pushUndoStop();
editor.executeCommands(COMMENT_SELECTED_CELLS_ID, commands);
editor.pushUndoStop();

editor.setSelection(selection);
});
}

Expand Down

0 comments on commit bcbdd8e

Please sign in to comment.