From 07bc5e2de9bd59fadc73110e7fced6f7bbd74c18 Mon Sep 17 00:00:00 2001 From: Yurong He <43652751+YurongHe@users.noreply.github.com> Date: Wed, 24 Apr 2019 09:04:15 -0700 Subject: [PATCH] Fixed #3244 (#5166) --- .../workbench/parts/notebook/cellViews/code.component.ts | 8 ++++++-- src/sql/workbench/parts/notebook/models/cell.ts | 8 ++++++++ src/sql/workbench/parts/notebook/notebook.component.ts | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/sql/workbench/parts/notebook/cellViews/code.component.ts b/src/sql/workbench/parts/notebook/cellViews/code.component.ts index b800be5bf0..f78c4d686e 100644 --- a/src/sql/workbench/parts/notebook/cellViews/code.component.ts +++ b/src/sql/workbench/parts/notebook/cellViews/code.component.ts @@ -9,7 +9,7 @@ import { OnInit, Component, Input, Inject, ElementRef, ViewChild, Output, EventE import { AngularDisposable } from 'sql/base/node/lifecycle'; import { QueryTextEditor } from 'sql/workbench/electron-browser/modelComponents/queryTextEditor'; import { CellToggleMoreActions } from 'sql/workbench/parts/notebook/cellToggleMoreActions'; -import { ICellModel, notebookConstants } from 'sql/workbench/parts/notebook/models/modelInterfaces'; +import { ICellModel, notebookConstants, CellExecutionState } from 'sql/workbench/parts/notebook/models/modelInterfaces'; import { Taskbar } from 'sql/base/browser/ui/taskbar/taskbar'; import { RunCellAction, CellContext } from 'sql/workbench/parts/notebook/cellViews/codeActions'; import { NotebookModel } from 'sql/workbench/parts/notebook/models/notebookModel'; @@ -229,6 +229,11 @@ export class CodeComponent extends AngularDisposable implements OnInit, OnChange } })); this._register(this.model.layoutChanged(() => this._layoutEmitter.fire(), this)); + this._register(this.cellModel.onExecutionStateChange(event => { + if (event === CellExecutionState.Running) { + this.setFocusAndScroll(); + } + })); this.layout(); } @@ -249,7 +254,6 @@ export class CodeComponent extends AngularDisposable implements OnInit, OnChange this._actionBar.setContent([ { action: runCellAction } ]); - this._cellToggleMoreActions.onInit(this.moreActionsElementRef, this.model, this.cellModel); } diff --git a/src/sql/workbench/parts/notebook/models/cell.ts b/src/sql/workbench/parts/notebook/models/cell.ts index feb6d19bf2..7575e0e659 100644 --- a/src/sql/workbench/parts/notebook/models/cell.ts +++ b/src/sql/workbench/parts/notebook/models/cell.ts @@ -187,6 +187,14 @@ export class CellModel implements ICellModel { public async runCell(notificationService?: INotificationService, connectionManagementService?: IConnectionManagementService): Promise { try { + if (!this.active && this !== this.notebookModel.activeCell) { + if (this.notebookModel.activeCell) { + this.notebookModel.activeCell.active = false; + } + this.active = true; + this.notebookModel.activeCell = this; + } + if (connectionManagementService) { this._connectionManagementService = connectionManagementService; } diff --git a/src/sql/workbench/parts/notebook/notebook.component.ts b/src/sql/workbench/parts/notebook/notebook.component.ts index 586e069543..4b44418b90 100644 --- a/src/sql/workbench/parts/notebook/notebook.component.ts +++ b/src/sql/workbench/parts/notebook/notebook.component.ts @@ -480,6 +480,7 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe await this.modelReady; let uriString = cell.cellUri.toString(); if (this._model.cells.findIndex(c => c.cellUri.toString() === uriString) > -1) { + this.selectCell(cell); return cell.runCell(this.notificationService, this.connectionManagementService); } else { return Promise.reject(new Error(localize('cellNotFound', 'cell with URI {0} was not found in this model', uriString)));