mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Add collapsed argument to insertCell extension method. (#7635)
This commit is contained in:
3
src/sql/azdata.d.ts
vendored
3
src/sql/azdata.d.ts
vendored
@@ -4440,8 +4440,9 @@ declare module 'azdata' {
|
|||||||
*
|
*
|
||||||
* @param index The position where the new text should be inserted.
|
* @param index The position where the new text should be inserted.
|
||||||
* @param value The new text this operation should insert.
|
* @param value The new text this operation should insert.
|
||||||
|
* @param collapsed The collapsed state of the new cell. Default value is `false` if not provided.
|
||||||
*/
|
*/
|
||||||
insertCell(value: ICellContents, index?: number): void;
|
insertCell(value: ICellContents, index?: number, collapsed?: boolean): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a certain cell.
|
* Delete a certain cell.
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { readonly } from 'vs/base/common/errors';
|
|||||||
import { MainThreadNotebookDocumentsAndEditorsShape } from 'sql/workbench/api/common/sqlExtHost.protocol';
|
import { MainThreadNotebookDocumentsAndEditorsShape } from 'sql/workbench/api/common/sqlExtHost.protocol';
|
||||||
import { ExtHostNotebookDocumentData } from 'sql/workbench/api/common/extHostNotebookDocumentData';
|
import { ExtHostNotebookDocumentData } from 'sql/workbench/api/common/extHostNotebookDocumentData';
|
||||||
import { CellRange, ISingleNotebookEditOperation, ICellRange } from 'sql/workbench/api/common/sqlExtHostTypes';
|
import { CellRange, ISingleNotebookEditOperation, ICellRange } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||||
|
import { HideInputTag } from 'sql/workbench/parts/notebook/browser/models/cell';
|
||||||
|
|
||||||
export interface INotebookEditOperation {
|
export interface INotebookEditOperation {
|
||||||
range: azdata.nb.CellRange;
|
range: azdata.nb.CellRange;
|
||||||
@@ -80,12 +81,21 @@ export class NotebookEditorEdit {
|
|||||||
return range;
|
return range;
|
||||||
}
|
}
|
||||||
|
|
||||||
insertCell(value: Partial<azdata.nb.ICellContents>, location?: number): void {
|
insertCell(value: Partial<azdata.nb.ICellContents>, index?: number, collapsed?: boolean): void {
|
||||||
if (location === null || location === undefined) {
|
if (index === null || index === undefined) {
|
||||||
// If not specified, assume adding to end of list
|
// If not specified, assume adding to end of list
|
||||||
location = this._document.cells.length;
|
index = this._document.cells.length;
|
||||||
}
|
}
|
||||||
this._pushEdit(new CellRange(location, location), value, true);
|
if (!!collapsed) {
|
||||||
|
if (!value.metadata) {
|
||||||
|
value.metadata = { tags: [HideInputTag] };
|
||||||
|
} else if (!value.metadata.tags) {
|
||||||
|
value.metadata.tags = [HideInputTag];
|
||||||
|
} else if (!value.metadata.tags.includes(HideInputTag)) {
|
||||||
|
value.metadata.tags.push(HideInputTag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this._pushEdit(new CellRange(index, index), value, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteCell(index: number): void {
|
deleteCell(index: number): void {
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ import { generateUuid } from 'vs/base/common/uuid';
|
|||||||
import { IModelContentChangedEvent } from 'vs/editor/common/model/textModelEvents';
|
import { IModelContentChangedEvent } from 'vs/editor/common/model/textModelEvents';
|
||||||
let modelId = 0;
|
let modelId = 0;
|
||||||
|
|
||||||
|
export const HideInputTag = 'hide_input';
|
||||||
|
|
||||||
export class CellModel implements ICellModel {
|
export class CellModel implements ICellModel {
|
||||||
public id: string;
|
public id: string;
|
||||||
|
|
||||||
@@ -52,8 +54,6 @@ export class CellModel implements ICellModel {
|
|||||||
private _onCollapseStateChanged = new Emitter<boolean>();
|
private _onCollapseStateChanged = new Emitter<boolean>();
|
||||||
private _modelContentChangedEvent: IModelContentChangedEvent;
|
private _modelContentChangedEvent: IModelContentChangedEvent;
|
||||||
|
|
||||||
private readonly _hideInputTag = 'hide_input';
|
|
||||||
|
|
||||||
constructor(cellData: nb.ICellContents,
|
constructor(cellData: nb.ICellContents,
|
||||||
private _options: ICellModelOptions,
|
private _options: ICellModelOptions,
|
||||||
@optional(INotebookService) private _notebookService?: INotebookService
|
@optional(INotebookService) private _notebookService?: INotebookService
|
||||||
@@ -112,7 +112,7 @@ export class CellModel implements ICellModel {
|
|||||||
|
|
||||||
let tagIndex = -1;
|
let tagIndex = -1;
|
||||||
if (this._metadata.tags) {
|
if (this._metadata.tags) {
|
||||||
tagIndex = this._metadata.tags.findIndex(tag => tag === this._hideInputTag);
|
tagIndex = this._metadata.tags.findIndex(tag => tag === HideInputTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._isCollapsed) {
|
if (this._isCollapsed) {
|
||||||
@@ -120,7 +120,7 @@ export class CellModel implements ICellModel {
|
|||||||
if (!this._metadata.tags) {
|
if (!this._metadata.tags) {
|
||||||
this._metadata.tags = [];
|
this._metadata.tags = [];
|
||||||
}
|
}
|
||||||
this._metadata.tags.push(this._hideInputTag);
|
this._metadata.tags.push(HideInputTag);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (tagIndex > -1) {
|
if (tagIndex > -1) {
|
||||||
@@ -605,7 +605,7 @@ export class CellModel implements ICellModel {
|
|||||||
this._source = this.getMultilineSource(cell.source);
|
this._source = this.getMultilineSource(cell.source);
|
||||||
this._metadata = cell.metadata || {};
|
this._metadata = cell.metadata || {};
|
||||||
|
|
||||||
if (this._metadata.tags && this._metadata.tags.includes(this._hideInputTag)) {
|
if (this._metadata.tags && this._metadata.tags.includes(HideInputTag)) {
|
||||||
this._isCollapsed = true;
|
this._isCollapsed = true;
|
||||||
} else {
|
} else {
|
||||||
this._isCollapsed = false;
|
this._isCollapsed = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user