mirror of
https://github.com/Microsoft/vscode
synced 2024-10-30 03:25:38 +00:00
Focus cell editor if there is only one code cell in the document.
This commit is contained in:
parent
4dfc14b846
commit
fdf1ab38a8
4 changed files with 21 additions and 0 deletions
|
@ -110,6 +110,7 @@ export interface ICellViewModel {
|
|||
currentTokenSource: CancellationTokenSource | undefined;
|
||||
focusMode: CellFocusMode;
|
||||
getText(): string;
|
||||
getTextLength(): number;
|
||||
metadata: NotebookCellMetadata | undefined;
|
||||
textModel: ITextModel | undefined;
|
||||
hasModel(): this is IEditableCellViewModel;
|
||||
|
|
|
@ -440,6 +440,18 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
|
|||
}
|
||||
}
|
||||
}
|
||||
} else if (this.notebookViewModel!.viewCells.length === 1 && this.notebookViewModel!.viewCells[0].cellKind === CellKind.Code) {
|
||||
// there is only one code cell in the document
|
||||
const cell = this.notebookViewModel!.viewCells[0];
|
||||
if (cell.getTextLength() === 0) {
|
||||
// the cell is empty, very likely a template cell, focus it
|
||||
this.selectElement(cell);
|
||||
await this.revealLineInCenterAsync(cell, 1);
|
||||
const editor = this.renderedEditors.get(cell)!;
|
||||
if (editor) {
|
||||
editor.focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -197,6 +197,10 @@ export abstract class BaseCellViewModel extends Disposable {
|
|||
return this.model.getValue();
|
||||
}
|
||||
|
||||
getTextLength(): number {
|
||||
return this.model.getTextLength();
|
||||
}
|
||||
|
||||
private saveViewState(): void {
|
||||
if (!this._textEditor) {
|
||||
return;
|
||||
|
|
|
@ -93,6 +93,10 @@ export class NotebookCellTextModel extends Disposable implements ICell {
|
|||
}
|
||||
}
|
||||
|
||||
getTextLength(): number {
|
||||
return this.textBuffer.getLength();
|
||||
}
|
||||
|
||||
getFullModelRange() {
|
||||
const lineCount = this.textBuffer.getLineCount();
|
||||
return new Range(1, 1, lineCount, this.textBuffer.getLineLength(lineCount) + 1);
|
||||
|
|
Loading…
Reference in a new issue