Skip to content

Commit 58127c4

Browse files
committed
re microsoft#99354. Focus editor only when the cell has focus.
1 parent ca7cd12 commit 58127c4

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/vs/workbench/contrib/notebook/browser/view/renderers/markdownCell.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ export class StatefullMarkdownCell extends Disposable {
6262

6363
// not first time, we don't need to create editor or bind listeners
6464
viewCell.attachTextEditor(this.editor);
65-
if (notebookEditor.getActiveCell() === viewCell) {
66-
this.editor.focus();
67-
}
65+
this.tryFocusEditor();
6866

6967
this.bindEditorListeners(this.editor.getModel()!);
7068
} else {
@@ -97,9 +95,7 @@ export class StatefullMarkdownCell extends Disposable {
9795
}
9896

9997
this.editor!.setModel(model);
100-
if (notebookEditor.getActiveCell() === viewCell) {
101-
this.editor!.focus();
102-
}
98+
this.tryFocusEditor();
10399

104100
const realContentHeight = this.editor!.getContentHeight();
105101
if (realContentHeight !== editorHeight) {
@@ -115,7 +111,7 @@ export class StatefullMarkdownCell extends Disposable {
115111
viewCell.attachTextEditor(this.editor!);
116112

117113
if (viewCell.editState === CellEditState.Editing) {
118-
this.editor!.focus();
114+
this.tryFocusEditor();
119115
}
120116

121117
this.bindEditorListeners(model, {
@@ -135,7 +131,7 @@ export class StatefullMarkdownCell extends Disposable {
135131
const totalHeight = editorHeight + 32 + clientHeight + CELL_STATUSBAR_HEIGHT;
136132
this.viewCell.totalHeight = totalHeight;
137133
notebookEditor.layoutNotebookCell(viewCell, totalHeight);
138-
this.editor.focus();
134+
this.tryFocusEditor();
139135
renderedEditors.set(this.viewCell, this.editor!);
140136
} else {
141137
this.viewCell.detachTextEditor();
@@ -205,7 +201,7 @@ export class StatefullMarkdownCell extends Disposable {
205201

206202
const updateForFocusMode = () => {
207203
if (viewCell.focusMode === CellFocusMode.Editor) {
208-
this.editor?.focus();
204+
this.tryFocusEditor();
209205
}
210206

211207
toggleClass(templateData.container, 'cell-editor-focus', viewCell.focusMode === CellFocusMode.Editor);
@@ -247,6 +243,12 @@ export class StatefullMarkdownCell extends Disposable {
247243
viewUpdate();
248244
}
249245

246+
private tryFocusEditor() {
247+
if (this.notebookEditor.getActiveCell() === this.viewCell) {
248+
this.editor?.focus();
249+
}
250+
}
251+
250252
private layoutEditor(dimension: IDimension): void {
251253
this.editor?.layout(dimension);
252254
this.templateData.statusBarContainer.style.width = `${dimension.width}px`;

0 commit comments

Comments
 (0)