提交 24c65476 编写于 作者: R rebornix

cell state instead of isEditing boolean

上级 f48e190b
......@@ -154,7 +154,7 @@ registerAction2(class extends Action2 {
let activeCell = editor.getActiveCell();
if (activeCell) {
if (activeCell.cellKind === CellKind.Markdown) {
activeCell.state = CellState.Read;
activeCell.state = CellState.Preview;
}
editor.focusNotebookCell(activeCell, false);
......
......@@ -79,7 +79,7 @@ export class NotebookFindWidget extends SimpleFindWidget {
}
private revealCellRange(cellIndex: number, matchIndex: number) {
this._findMatches[cellIndex].cell.state = CellState.PreviewContent;
this._findMatches[cellIndex].cell.state = CellState.Editing;
this._notebookEditor.selectElement(this._findMatches[cellIndex].cell);
this._notebookEditor.setCellSelection(this._findMatches[cellIndex].cell, this._findMatches[cellIndex].matches[matchIndex].range);
this._notebookEditor.revealRangeInCenterIfOutsideViewport(this._findMatches[cellIndex].cell, this._findMatches[cellIndex].matches[matchIndex].range);
......
......@@ -206,14 +206,7 @@ export enum CellState {
* For markdown cell, it's Markdown preview.
* For code cell, the browser focus should be on the container instead of the editor
*/
Read,
/**
* Content preview mode.
* For markdown cell, the source is now rendered in the editor. When the cell is not longer focsued/selected, it will fall back to Read mode.
* For code cell, this state is the same as Editing
*/
PreviewContent,
Preview,
/**
* Eding mode. Source for markdown or code is rendered in editors and the state will be persistent.
......
......@@ -579,7 +579,7 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor {
}
saveNotebookCell(cell: CellViewModel): void {
cell.state = CellState.Read;
cell.state = CellState.Preview;
}
getActiveCell() {
......@@ -600,7 +600,7 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor {
this.list?.setSelection([index]);
this.list?.focusView();
cell.state = CellState.PreviewContent;
cell.state = CellState.Editing;
cell.focusMode = CellFocusMode.Editor;
} else {
let itemDOM = this.list?.domElementAtIndex(index);
......
......@@ -10,7 +10,7 @@ import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { getResizesObserver } from 'vs/workbench/contrib/notebook/browser/view/renderers/sizeObserver';
import { CELL_MARGIN, EDITOR_TOP_PADDING, EDITOR_BOTTOM_PADDING } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookEditor, CellRenderTemplate, CellFocusMode } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { INotebookEditor, CellRenderTemplate, CellFocusMode, CellState } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { CancellationTokenSource } from 'vs/base/common/cancellation';
import { raceCancellation } from 'vs/base/common/async';
......@@ -36,7 +36,7 @@ export class StatefullMarkdownCell extends Disposable {
this._register(this.localDisposables);
const viewUpdate = () => {
if (viewCell.isEditing) {
if (viewCell.state === CellState.Editing) {
// switch to editing mode
let width: number;
const listDimension = notebookEditor.getLayoutInfo();
......@@ -106,7 +106,7 @@ export class StatefullMarkdownCell extends Disposable {
notebookEditor.layoutNotebookCell(viewCell, this.editor!.getContentHeight() + 32 + clientHeight);
}));
if (viewCell.isEditing) {
if (viewCell.state === CellState.Editing) {
this.editor!.focus();
}
});
......@@ -189,7 +189,7 @@ export class StatefullMarkdownCell extends Disposable {
}
};
this._register(viewCell.onDidChangeEditingState(() => {
this._register(viewCell.onDidChangeCellState(() => {
this.localDisposables.clear();
viewUpdate();
}));
......
......@@ -24,8 +24,8 @@ export class CellViewModel extends Disposable {
private _html: HTMLElement | null = null;
protected readonly _onDidDispose = new Emitter<void>();
readonly onDidDispose = this._onDidDispose.event;
protected readonly _onDidChangeEditingState = new Emitter<void>();
readonly onDidChangeEditingState = this._onDidChangeEditingState.event;
protected readonly _onDidChangeCellState = new Emitter<void>();
readonly onDidChangeCellState = this._onDidChangeCellState.event;
protected readonly _onDidChangeFocusMode = new Emitter<void>();
readonly onDidChangeFocusMode = this._onDidChangeFocusMode.event;
protected readonly _onDidChangeOutputs = new Emitter<NotebookCellOutputsSplice[]>();
......@@ -47,33 +47,19 @@ export class CellViewModel extends Disposable {
return this.cell.outputs;
}
private _isEditing: boolean;
get isEditing(): boolean {
return this._isEditing;
}
private _state: CellState = CellState.Read;
private _state: CellState = CellState.Preview;
get state(): CellState {
return this._state;
}
set state(newState: CellState) {
// no downgrade from Editing to PreviewContent
if (this._state === CellState.Editing && newState === CellState.PreviewContent) {
if (newState === this._state) {
return;
}
this._state = newState;
if (newState !== CellState.Read) {
this._isEditing = true;
} else {
this._isEditing = false;
}
this._onDidChangeEditingState.fire();
this._onDidChangeCellState.fire();
}
private _focusMode: CellFocusMode = CellFocusMode.Container;
......@@ -145,7 +131,6 @@ export class CellViewModel extends Disposable {
this._outputCollection = new Array(this.cell.outputs.length);
this._buffer = null;
this._editorViewStates = null;
this._isEditing = false;
}
restoreEditorViewState(editorViewStates: editorCommon.ICodeEditorViewState | null) {
......@@ -252,7 +237,7 @@ export class CellViewModel extends Disposable {
this._html = null;
}
save() {
if (this._textModel && !this._textModel.isDisposed() && (this.cell.isDirty || this.isEditing)) {
if (this._textModel && !this._textModel.isDisposed() && (this.cell.isDirty || this.state === CellState.Editing)) {
let cnt = this._textModel.getLineCount();
this.cell.source = this._textModel.getLinesContent().map((str, index) => str + (index !== cnt - 1 ? '\n' : ''));
}
......@@ -393,11 +378,7 @@ export class CellViewModel extends Disposable {
}
onDeselect() {
if (this.cellKind === CellKind.Code) {
this.state = CellState.Read;
} else if (this.state === CellState.PreviewContent) {
this.state = CellState.Read;
}
this.state = CellState.Preview;
}
cursorAtBoundary(): CursorAtBoundary {
......
......@@ -89,7 +89,7 @@ export class NotebookViewModel extends Disposable {
hide() {
this.viewCells.forEach(cell => {
if (cell.getText() !== '') {
cell.state = CellState.Read;
cell.state = CellState.Preview;
}
});
}
......@@ -131,7 +131,7 @@ export class NotebookViewModel extends Disposable {
saveEditorViewState(): INotebookEditorViewState {
const state: { [key: number]: boolean } = {};
this.viewCells.filter(cell => cell.isEditing).forEach(cell => state[cell.cell.handle] = true);
this.viewCells.filter(cell => cell.state === CellState.Editing).forEach(cell => state[cell.cell.handle] = true);
const editorViewStates: { [key: number]: editorCommon.ICodeEditorViewState } = {};
this.viewCells.map(cell => ({ handle: cell.cell.handle, state: cell.saveEditorViewState() })).forEach(viewState => {
if (viewState.state) {
......@@ -154,7 +154,7 @@ export class NotebookViewModel extends Disposable {
const isEditing = viewState.editingCells && viewState.editingCells[cell.handle];
const editorViewState = viewState.editorViewStates && viewState.editorViewStates[cell.handle];
cell.state = isEditing ? CellState.Editing : CellState.Read;
cell.state = isEditing ? CellState.Editing : CellState.Preview;
cell.restoreEditorViewState(editorViewState);
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册