Skip to content

Commit

Permalink
Disallow edit mode for readonly markdown cells (#126870)
Browse files Browse the repository at this point in the history
* Disallow edit mode for readonly markdown cells

* Disable in a different spot

* Revert "Disable in a different spot"

This reverts commit 0f37408.

* Don't toggle markdown cell preview for readonly notebooks

* Add NOTEBOOK_EDITOR_EDITABLE to keybinding when clause
  • Loading branch information
joyceerhl authored Jun 22, 2021
1 parent c80fba9 commit 75f0d5b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,10 @@ registerAction2(class EditCellAction extends NotebookCellAction {
id: EDIT_CELL_COMMAND_ID,
title: localize('notebookActions.editCell', "Edit Cell"),
keybinding: {
when: ContextKeyExpr.and(NOTEBOOK_CELL_LIST_FOCUSED, ContextKeyExpr.not(InputFocusedContextKey)),
when: ContextKeyExpr.and(
NOTEBOOK_CELL_LIST_FOCUSED,
ContextKeyExpr.not(InputFocusedContextKey),
NOTEBOOK_EDITOR_EDITABLE.isEqualTo(true)),
primary: KeyCode.Enter,
weight: KeybindingWeight.WorkbenchContrib
},
Expand All @@ -1308,6 +1311,11 @@ registerAction2(class EditCellAction extends NotebookCellAction {
}

async runWithContext(accessor: ServicesAccessor, context: INotebookCellActionContext): Promise<void> {
const viewModel = context.notebookEditor.viewModel;
if (!viewModel || viewModel.options.isReadOnly) {
return;
}

context.notebookEditor.focusNotebookCell(context.cell, 'editor');
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> implements ID
this._localDisposableStore.add(this.view.onMouseDblClick(() => {
const focus = this.getFocusedElements()[0];

if (focus && focus.cellKind === CellKind.Markup && !focus.metadata.inputCollapsed) {
if (focus && focus.cellKind === CellKind.Markup && !focus.metadata.inputCollapsed && !this._viewModel?.options.isReadOnly) {
focus.updateEditState(CellEditState.Editing, 'dbclick');
focus.focusMode = CellFocusMode.Editor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ var requirejs = (function() {
case 'toggleMarkupPreview':
{
const cell = this.notebookEditor.getCellById(data.cellId);
if (cell) {
if (cell && !this.notebookEditor.creationOptions.isReadOnly) {
this.notebookEditor.setMarkupCellEditState(data.cellId, CellEditState.Editing);
this.notebookEditor.focusNotebookCell(cell, 'editor', { skipReveal: true });
}
Expand Down

0 comments on commit 75f0d5b

Please sign in to comment.