Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Jul 13, 2021
1 parent bd22520 commit 547b311
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,6 @@ registerAction2(class ExecuteCellSelectBelow extends NotebookCellAction {
}
return;
} else {
const executionP = runCell(accessor, context);

// Try to select below, fall back on inserting
const nextCell = context.notebookEditor.viewModel.cellAt(idx + 1);
if (nextCell) {
Expand All @@ -700,7 +698,7 @@ registerAction2(class ExecuteCellSelectBelow extends NotebookCellAction {
}
}

return executionP;
return runCell(accessor, context);
}
}
});
Expand Down
5 changes: 4 additions & 1 deletion src/vs/workbench/contrib/notebook/browser/notebookEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ export class NotebookEditor extends EditorPane {

private readonly inputListener = this._register(new MutableDisposable());

// todo@rebornix is there a reason that `super.fireOnDidFocus` isn't used?
// override onDidFocus and onDidBlur to be based on the NotebookEditorWidget element
private readonly _onDidFocusWidget = this._register(new Emitter<void>());
override get onDidFocus(): Event<void> { return this._onDidFocusWidget.event; }
private readonly _onDidBlurWidget = this._register(new Emitter<void>());
override get onDidBlur(): Event<void> { return this._onDidBlurWidget.event; }

private readonly _onDidChangeModel = this._register(new Emitter<void>());
readonly onDidChangeModel: Event<void> = this._onDidChangeModel.event;
Expand Down Expand Up @@ -226,6 +228,7 @@ export class NotebookEditor extends EditorPane {
const isReadOnly = input.hasCapability(EditorInputCapabilities.Readonly);
await this._widget.value!.setOptions({ ...options, isReadOnly });
this._widgetDisposableStore.add(this._widget.value!.onDidFocus(() => this._onDidFocusWidget.fire()));
this._widgetDisposableStore.add(this._widget.value!.onDidBlur(() => this._onDidBlurWidget.fire()));

this._widgetDisposableStore.add(this._editorDropService.createEditorDropTarget(this._widget.value!.getDomNode(), {
containsGroup: (group) => this.group?.id === group.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1621,12 +1621,15 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
updateEditorFocus() {
// Note - focus going to the webview will fire 'blur', but the webview element will be
// a descendent of the notebook editor root.
const focused = DOM.isAncestor(document.activeElement, this._overlayContainer);
const focused = this._overlayContainer.contains(document.activeElement);
this._editorFocus.set(focused);
this.viewModel?.setEditorFocus(focused);
}

hasEditorFocus() {
// _editorFocus is driven by the FocusTracker, which is only guaranteed to _eventually_ fire blur.
// If we need to know whether we have focus at this instant, we need to check the DOM manually.
this.updateEditorFocus();
return this._editorFocus.get() || false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,19 @@ export class CodeCell extends Disposable {
if (model && templateData.editor) {
templateData.editor.setModel(model);
viewCell.attachTextEditor(templateData.editor);
if (notebookEditor.getActiveCell() === viewCell && viewCell.focusMode === CellFocusMode.Editor && this.notebookEditor.hasEditorFocus()) {
templateData.editor?.focus();
}
const focusEditorIfNeeded = () => {
if (notebookEditor.getActiveCell() === viewCell && viewCell.focusMode === CellFocusMode.Editor && this.notebookEditor.hasEditorFocus()) {
templateData.editor?.focus();
}
};
focusEditorIfNeeded();

const realContentHeight = templateData.editor?.getContentHeight();
if (realContentHeight !== undefined && realContentHeight !== editorHeight) {
this.onCellHeightChange(realContentHeight);
}

if (this.notebookEditor.getActiveCell() === this.viewCell && viewCell.focusMode === CellFocusMode.Editor && this.notebookEditor.hasEditorFocus()) {
templateData.editor?.focus();
}
focusEditorIfNeeded();
}
});

Expand Down

0 comments on commit 547b311

Please sign in to comment.