Split notebookcell (#17185)

* Initial Split code

* minor change

* minor changes

* Added split cell button to initActionBar, created split cell class to pss cell context.

* added changes

* fixed index

* Split Cell Working in markdown mode

* Fixed highlighting

* Preserve the edit state

* Added new icon and updated styles and cellToolbar component with new icon name.

* Addressed PR

* Addressed PR

* Added back isEditMode flag

* Moved split action to after edit toggle.

* Fixed typo

* Addressed PR

* Addressed PR

* Removed deletion of the cell

* fixed the comments

Co-authored-by: Hale Rankin <harankin@microsoft.com>
This commit is contained in:
rajeshka
2021-10-06 18:18:22 -07:00
committed by GitHub
parent 95a4366edb
commit 671c062e59
10 changed files with 172 additions and 12 deletions

View File

@@ -18,7 +18,6 @@ import { INotebookService } from 'sql/workbench/services/notebook/browser/notebo
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { MoveDirection } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
const moreActionsLabel = localize('moreActionsLabel', "More");
export class EditCellAction extends ToggleableAction {
@@ -58,6 +57,29 @@ export class EditCellAction extends ToggleableAction {
}
}
export class SplitCellAction extends CellActionBase {
public cellType: CellType;
constructor(
id: string,
label: string,
cssClass: string,
@INotificationService notificationService: INotificationService,
@INotebookService private notebookService: INotebookService,
) {
super(id, label, cssClass, notificationService);
this._cssClass = cssClass;
this._tooltip = label;
this._label = '';
}
doRun(context: CellContext): Promise<void> {
let model = context.model;
let index = model.cells.findIndex((cell) => cell.id === context.cell.id);
context.model?.splitCell(context.cell.cellType, this.notebookService, index);
return Promise.resolve();
}
}
export class MoveCellAction extends CellActionBase {
constructor(
id: string,

View File

@@ -10,7 +10,7 @@ import { localize } from 'vs/nls';
import { Taskbar, ITaskbarContent } from 'sql/base/browser/ui/taskbar/taskbar';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { DeleteCellAction, EditCellAction, CellToggleMoreActions, MoveCellAction } from 'sql/workbench/contrib/notebook/browser/cellToolbarActions';
import { DeleteCellAction, EditCellAction, CellToggleMoreActions, MoveCellAction, SplitCellAction } from 'sql/workbench/contrib/notebook/browser/cellToolbarActions';
import { AddCellAction } from 'sql/workbench/contrib/notebook/browser/notebookActions';
import { CellTypes } from 'sql/workbench/services/notebook/common/contracts';
import { DropdownMenuActionViewItem } from 'sql/base/browser/ui/buttonMenu/buttonMenu';
@@ -33,6 +33,7 @@ export class CellToolbarComponent {
public buttonMoveDown = localize('buttonMoveDown', "Move cell down");
public buttonMoveUp = localize('buttonMoveUp', "Move cell up");
public buttonDelete = localize('buttonDelete', "Delete");
public buttonSplitCell = localize('splitCell', "Split cell");
@Input() cellModel: ICellModel;
@Input() model: NotebookModel;
@@ -58,6 +59,8 @@ export class CellToolbarComponent {
this._actionBar = new Taskbar(taskbar);
this._actionBar.context = context;
let splitCellButton = this.instantiationService.createInstance(SplitCellAction, 'notebook.SplitCellAtCursor', this.buttonSplitCell, 'masked-icon icon-split-cell');
let addCellsButton = this.instantiationService.createInstance(AddCellAction, 'notebook.AddCodeCell', localize('codeCellsPreview', "Add cell"), 'masked-pseudo code');
let addCodeCellButton = this.instantiationService.createInstance(AddCellAction, 'notebook.AddCodeCell', localize('codePreview', "Code cell"), 'masked-pseudo code');
@@ -96,9 +99,12 @@ export class CellToolbarComponent {
let taskbarContent: ITaskbarContent[] = [];
if (this.cellModel?.cellType === CellTypes.Markdown) {
taskbarContent.push({ action: this._editCellAction });
taskbarContent.push(
{ action: this._editCellAction }
);
}
taskbarContent.push(
{ action: splitCellButton },
{ element: addCellDropdownContainer },
{ action: moveCellDownButton },
{ action: moveCellUpButton },

View File

@@ -271,7 +271,7 @@ suite('NotebookViewModel', function (): void {
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(contents));
defaultModelOptions.contentLoader = mockContentManager.object;
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService, undefined);
await model.loadContents();
await model.requestModelLoad();

View File

@@ -196,7 +196,7 @@ suite('Notebook Views Actions', function (): void {
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(contents));
defaultModelOptions.contentLoader = mockContentManager.object;
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService, undefined);
await model.loadContents();
await model.requestModelLoad();

View File

@@ -163,7 +163,7 @@ suite('NotebookViews', function (): void {
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(initialNotebookContent));
defaultModelOptions.contentLoader = mockContentManager.object;
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService, undefined);
await model.loadContents();
await model.requestModelLoad();

View File

@@ -978,7 +978,7 @@ suite('Notebook Editor Model', function (): void {
let options: INotebookModelOptions = Object.assign({}, defaultModelOptions, <Partial<INotebookModelOptions>><unknown>{
factory: mockModelFactory.object
});
notebookModel = new NotebookModel(options, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
notebookModel = new NotebookModel(options, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService, undefined);
await notebookModel.loadContents();
}

View File

@@ -439,7 +439,7 @@ suite('Notebook Find Model', function (): void {
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(contents));
defaultModelOptions.contentLoader = mockContentManager.object;
// Initialize the model
model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService, undefined);
await model.loadContents();
await model.requestModelLoad();
}