提交 541ff182 编写于 作者: R Rob Lourens

Add cell collapse state to cell metadata

This needs more discussion - is collapse state metadata or view state?
上级 a3dd5c3b
......@@ -1357,6 +1357,16 @@ declare module 'vscode' {
*/
lastRunDuration?: number;
/**
* Whether a code cell's editor is collapsed
*/
inputCollapsed?: boolean;
/**
* Whether a code cell's outputs are collapsed
*/
outputCollapsed?: boolean;
/**
* Additional attributes of a cell metadata.
*/
......
......@@ -18,7 +18,7 @@ import { InputFocusedContext, InputFocusedContextKey } from 'vs/platform/context
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { IQuickInputService, IQuickPickItem, QuickPickInput } from 'vs/platform/quickinput/common/quickInput';
import { BaseCellRenderTemplate, CellCollapseState, CellEditState, CellFocusMode, ICellViewModel, INotebookEditor, NOTEBOOK_CELL_CONTENT_COLLAPSED, NOTEBOOK_CELL_EDITABLE, NOTEBOOK_CELL_HAS_OUTPUTS, NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, NOTEBOOK_CELL_OUTPUT_COLLAPSED, NOTEBOOK_CELL_TYPE, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_EDITOR_EXECUTING_NOTEBOOK, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_EDITOR_RUNNABLE, NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_OUTPUT_FOCUSED } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { BaseCellRenderTemplate, CellCollapseState, CellEditState, CellFocusMode, ICellViewModel, INotebookEditor, NOTEBOOK_CELL_INPUT_COLLAPSED, NOTEBOOK_CELL_EDITABLE, NOTEBOOK_CELL_HAS_OUTPUTS, NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, NOTEBOOK_CELL_OUTPUT_COLLAPSED, NOTEBOOK_CELL_TYPE, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_EDITOR_EXECUTING_NOTEBOOK, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_EDITOR_RUNNABLE, NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_OUTPUT_FOCUSED } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { CellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel';
import { CellKind, CellUri, NotebookCellRunState, NOTEBOOK_EDITOR_CURSOR_BOUNDARY } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
......@@ -72,7 +72,7 @@ const CENTER_ACTIVE_CELL = 'notebook.centerActiveCell';
const FOCUS_IN_OUTPUT_COMMAND_ID = 'notebook.cell.focusInOutput';
const FOCUS_OUT_OUTPUT_COMMAND_ID = 'notebook.cell.focusOutOutput';
const COLLAPSE_CELL_CONTENT_COMMAND_ID = 'notebook.cell.collapseCellContent';
const COLLAPSE_CELL_INPUT_COMMAND_ID = 'notebook.cell.collapseCellContent';
const COLLAPSE_CELL_OUTPUT_COMMAND_ID = 'notebook.cell.collapseCellOutput';
const EXPAND_CELL_CONTENT_COMMAND_ID = 'notebook.cell.expandCellContent';
const EXPAND_CELL_OUTPUT_COMMAND_ID = 'notebook.cell.expandCellOutput';
......@@ -1461,16 +1461,16 @@ registerAction2(class extends NotebookCellAction {
registerAction2(class extends NotebookCellAction {
constructor() {
super({
id: COLLAPSE_CELL_CONTENT_COMMAND_ID,
title: localize('notebookActions.collapseCellContent', "Collapse Cell Content"),
id: COLLAPSE_CELL_INPUT_COMMAND_ID,
title: localize('notebookActions.collapseCellInput', "Collapse Cell Input"),
keybinding: {
when: ContextKeyExpr.and(NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_CONTENT_COLLAPSED.toNegated(), InputFocusedContext.toNegated()),
when: ContextKeyExpr.and(NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_INPUT_COLLAPSED.toNegated(), InputFocusedContext.toNegated()),
primary: KeyChord(KeyCode.KEY_C, KeyCode.KEY_C),
weight: KeybindingWeight.WorkbenchContrib
},
menu: {
id: MenuId.NotebookCellTitle,
when: ContextKeyExpr.and(NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_CONTENT_COLLAPSED.toNegated()),
when: ContextKeyExpr.and(NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_INPUT_COLLAPSED.toNegated()),
group: '3_collapse',
}
});
......@@ -1487,13 +1487,13 @@ registerAction2(class extends NotebookCellAction {
id: EXPAND_CELL_CONTENT_COMMAND_ID,
title: localize('notebookActions.expandCellContent', "Expand Cell Content"),
keybinding: {
when: ContextKeyExpr.and(NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_CONTENT_COLLAPSED),
when: ContextKeyExpr.and(NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_INPUT_COLLAPSED),
primary: KeyChord(KeyCode.KEY_C, KeyCode.KEY_C),
weight: KeybindingWeight.WorkbenchContrib
},
menu: {
id: MenuId.NotebookCellTitle,
when: ContextKeyExpr.and(NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_CONTENT_COLLAPSED),
when: ContextKeyExpr.and(NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_INPUT_COLLAPSED),
group: '3_collapse',
}
});
......
......@@ -48,7 +48,7 @@ export const NOTEBOOK_CELL_RUNNABLE = new RawContextKey<boolean>('notebookCellRu
export const NOTEBOOK_CELL_MARKDOWN_EDIT_MODE = new RawContextKey<boolean>('notebookCellMarkdownEditMode', false); // bool
export const NOTEBOOK_CELL_RUN_STATE = new RawContextKey<string>('notebookCellRunState', undefined); // idle, running
export const NOTEBOOK_CELL_HAS_OUTPUTS = new RawContextKey<boolean>('notebookCellHasOutputs', false); // bool
export const NOTEBOOK_CELL_CONTENT_COLLAPSED = new RawContextKey<boolean>('notebookCellContentIsCollapsed', false); // bool
export const NOTEBOOK_CELL_INPUT_COLLAPSED = new RawContextKey<boolean>('notebookCellInputIsCollapsed', false); // bool
export const NOTEBOOK_CELL_OUTPUT_COLLAPSED = new RawContextKey<boolean>('notebookCellOutputIsCollapsed', false); // bool
// Kernels
......@@ -569,7 +569,6 @@ export interface CellViewModelStateChangeEvent {
focusModeChanged?: boolean;
editStateChanged?: boolean;
languageChanged?: boolean;
collapseStateChanged?: boolean;
foldingStateChanged?: boolean;
contentChanged?: boolean;
outputIsHoveredChanged?: boolean;
......
......@@ -6,7 +6,7 @@
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { INotebookTextModel, NotebookCellRunState } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { BaseCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/baseCellViewModel';
import { NOTEBOOK_CELL_TYPE, NOTEBOOK_VIEW_TYPE, NOTEBOOK_CELL_EDITABLE, NOTEBOOK_CELL_RUNNABLE, NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, NOTEBOOK_CELL_RUN_STATE, NOTEBOOK_CELL_HAS_OUTPUTS, CellViewModelStateChangeEvent, CellEditState, NOTEBOOK_CELL_CONTENT_COLLAPSED, CellCollapseState, NOTEBOOK_CELL_OUTPUT_COLLAPSED } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { NOTEBOOK_CELL_TYPE, NOTEBOOK_VIEW_TYPE, NOTEBOOK_CELL_EDITABLE, NOTEBOOK_CELL_RUNNABLE, NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, NOTEBOOK_CELL_RUN_STATE, NOTEBOOK_CELL_HAS_OUTPUTS, CellViewModelStateChangeEvent, CellEditState, NOTEBOOK_CELL_INPUT_COLLAPSED, CellCollapseState, NOTEBOOK_CELL_OUTPUT_COLLAPSED } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { CodeCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel';
import { MarkdownCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/markdownCellViewModel';
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
......@@ -41,7 +41,7 @@ export class CellContextKeyManager extends Disposable {
this.markdownEditMode = NOTEBOOK_CELL_MARKDOWN_EDIT_MODE.bindTo(this.contextKeyService);
this.cellRunState = NOTEBOOK_CELL_RUN_STATE.bindTo(this.contextKeyService);
this.cellHasOutputs = NOTEBOOK_CELL_HAS_OUTPUTS.bindTo(this.contextKeyService);
this.cellContentCollapsed = NOTEBOOK_CELL_CONTENT_COLLAPSED.bindTo(this.contextKeyService);
this.cellContentCollapsed = NOTEBOOK_CELL_INPUT_COLLAPSED.bindTo(this.contextKeyService);
this.cellOutputCollapsed = NOTEBOOK_CELL_OUTPUT_COLLAPSED.bindTo(this.contextKeyService);
this.updateForElement(element);
......@@ -56,6 +56,8 @@ export class CellContextKeyManager extends Disposable {
this.elementDisposables.add(element.onDidChangeOutputs(() => this.updateForOutputs()));
}
this.elementDisposables.add(element.model.onDidChangeMetadata(() => this.updateForCollapseState()));
this.element = element;
if (this.element instanceof MarkdownCellViewModel) {
this.cellType.set('markdown');
......@@ -83,9 +85,9 @@ export class CellContextKeyManager extends Disposable {
this.updateForEditState();
}
if (e.collapseStateChanged) {
this.updateForCollapseState();
}
// if (e.collapseStateChanged) {
// this.updateForCollapseState();
// }
});
}
......
......@@ -91,10 +91,6 @@ export class CodeCell extends Disposable {
if (e.focusModeChanged) {
updateForFocusMode();
}
if (e.collapseStateChanged) {
updateForCollapseState();
}
}));
updateForFocusMode();
......@@ -102,6 +98,11 @@ export class CodeCell extends Disposable {
this._register(viewCell.onDidChangeState((e) => {
if (e.metadataChanged) {
templateData.editor?.updateOptions({ readOnly: !(viewCell.getEvaluatedMetadata(notebookEditor.viewModel!.metadata).editable) });
// TODO@rob this isn't nice
this.viewCell.layoutChange({});
updateForCollapseState();
this.relayoutCell();
}
}));
......@@ -110,11 +111,6 @@ export class CodeCell extends Disposable {
const mode = this._modeService.create(viewCell.language);
templateData.editor?.getModel()?.setMode(mode.languageIdentifier);
}
if (e.collapseStateChanged) {
this.viewCell.layoutChange({});
this.relayoutCell();
}
}));
this._register(viewCell.onDidChangeLayout((e) => {
......
......@@ -50,11 +50,15 @@ export class StatefulMarkdownCell extends Disposable {
if (e.editStateChanged) {
this.localDisposables.clear();
this.viewUpdate();
} else if (e.contentChanged || e.collapseStateChanged) {
} else if (e.contentChanged) {
this.viewUpdate();
}
}));
this._register(viewCell.model.onDidChangeMetadata(() => {
this.viewUpdate();
}));
this._register(getResizesObserver(this.markdownContainer, undefined, () => {
if (viewCell.editState === CellEditState.Preview) {
this.viewCell.renderedMarkdownHeight = templateData.container.clientHeight;
......
......@@ -60,24 +60,26 @@ export abstract class BaseCellViewModel extends Disposable {
}
}
private _collapseState: CellCollapseState = CellCollapseState.Normal;
public get collapseState(): CellCollapseState {
return this._collapseState;
return this.metadata?.inputCollapsed ? CellCollapseState.Collapsed : CellCollapseState.Normal;
}
public set collapseState(v: CellCollapseState) {
this._collapseState = v;
this._onDidChangeState.fire({ collapseStateChanged: true });
this.model.metadata = {
...this.metadata,
...{ inputCollapsed: v === CellCollapseState.Collapsed }
};
}
private _outputCollapseState: CellCollapseState = CellCollapseState.Normal;
public get outputCollapseState(): CellCollapseState {
return this._outputCollapseState;
return this.metadata?.outputCollapsed ? CellCollapseState.Collapsed : CellCollapseState.Normal;
}
public set outputCollapseState(v: CellCollapseState) {
this._outputCollapseState = v;
this._onDidChangeState.fire({ collapseStateChanged: true });
this.model.metadata = {
...this.metadata,
...{ outputCollapsed: v === CellCollapseState.Collapsed }
};
}
private _focusMode: CellFocusMode = CellFocusMode.Container;
......
......@@ -97,6 +97,8 @@ export interface NotebookCellMetadata {
runState?: NotebookCellRunState;
runStartTime?: number;
lastRunDuration?: number;
inputCollapsed?: boolean;
outputCollapsed?: boolean;
custom?: { [key: string]: unknown };
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册