diff --git a/src/vs/workbench/contrib/positronNotebook/browser/IPositronNotebookInstance.ts b/src/vs/workbench/contrib/positronNotebook/browser/IPositronNotebookInstance.ts index 807f2599109..84a0e1adf03 100644 --- a/src/vs/workbench/contrib/positronNotebook/browser/IPositronNotebookInstance.ts +++ b/src/vs/workbench/contrib/positronNotebook/browser/IPositronNotebookInstance.ts @@ -162,6 +162,15 @@ export interface IPositronNotebookInstance { */ insertCodeCellAndFocusContainer(aboveOrBelow: 'above' | 'below', referenceCell?: IPositronNotebookCell): void; + /** + * Inserts a new markdown cell either above or below the current selection + * and focuses the container. + * + * @param aboveOrBelow Whether to insert the cell above or below the current selection + * @param referenceCell Optional cell to insert relative to. If not provided, uses the currently selected cell + */ + insertMarkdownCellAndFocusContainer(aboveOrBelow: 'above' | 'below', referenceCell?: IPositronNotebookCell): void; + /** * Removes a cell from the notebook. * diff --git a/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookCells/IPositronNotebookCell.ts b/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookCells/IPositronNotebookCell.ts index 925011458a8..ae860d57461 100644 --- a/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookCells/IPositronNotebookCell.ts +++ b/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookCells/IPositronNotebookCell.ts @@ -98,6 +98,16 @@ export interface IPositronNotebookCell extends Disposable { */ insertCodeCellBelow(): void; + /** + * Insert a new markdown cell above this cell + */ + insertMarkdownCellAbove(): void; + + /** + * Insert a new markdown cell below this cell + */ + insertMarkdownCellBelow(): void; + /** * Type guard for checking if cell is a markdown cell */ diff --git a/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookCells/PositronNotebookCell.ts b/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookCells/PositronNotebookCell.ts index ce40bc69cc3..569318daf5e 100644 --- a/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookCells/PositronNotebookCell.ts +++ b/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookCells/PositronNotebookCell.ts @@ -222,7 +222,11 @@ export abstract class PositronNotebookCellGeneral extends Disposable implements this._instance.insertCodeCellAndFocusContainer('below', this); } -} - - + insertMarkdownCellAbove(): void { + this._instance.insertMarkdownCellAndFocusContainer('above', this); + } + insertMarkdownCellBelow(): void { + this._instance.insertMarkdownCellAndFocusContainer('below', this); + } +} diff --git a/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookInstance.ts b/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookInstance.ts index 08354d05478..8d39b9e358a 100644 --- a/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookInstance.ts +++ b/src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookInstance.ts @@ -523,12 +523,7 @@ export class PositronNotebookInstance extends Disposable implements IPositronNot this._onDidChangeContent.fire(); } - /** - * Inserts a new code cell above or below the reference cell (or selected cell if no reference is provided). - * @param aboveOrBelow Whether to insert the cell above or below the reference - * @param referenceCell Optional reference cell. If not provided, uses the currently selected cell - */ - insertCodeCellAndFocusContainer(aboveOrBelow: 'above' | 'below', referenceCell?: IPositronNotebookCell): void { + private _insertCellAndFocusContainer(type: CellKind, aboveOrBelow: 'above' | 'below', referenceCell?: IPositronNotebookCell): void { let index: number | undefined; this._assertTextModel(); @@ -544,7 +539,20 @@ export class PositronNotebookInstance extends Disposable implements IPositronNot return; } - this.addCell(CellKind.Code, index + (aboveOrBelow === 'above' ? 0 : 1)); + this.addCell(type, index + (aboveOrBelow === 'above' ? 0 : 1)); + } + + /** + * Inserts a new code cell above or below the reference cell (or selected cell if no reference is provided). + * @param aboveOrBelow Whether to insert the cell above or below the reference + * @param referenceCell Optional reference cell. If not provided, uses the currently selected cell + */ + insertCodeCellAndFocusContainer(aboveOrBelow: 'above' | 'below', referenceCell?: IPositronNotebookCell): void { + this._insertCellAndFocusContainer(CellKind.Code, aboveOrBelow, referenceCell); + } + + insertMarkdownCellAndFocusContainer(aboveOrBelow: 'above' | 'below', referenceCell?: IPositronNotebookCell): void { + this._insertCellAndFocusContainer(CellKind.Markup, aboveOrBelow, referenceCell); } /** diff --git a/src/vs/workbench/contrib/positronNotebook/browser/positronNotebook.contribution.ts b/src/vs/workbench/contrib/positronNotebook/browser/positronNotebook.contribution.ts index 1193d63bd7e..c0c477abc23 100644 --- a/src/vs/workbench/contrib/positronNotebook/browser/positronNotebook.contribution.ts +++ b/src/vs/workbench/contrib/positronNotebook/browser/positronNotebook.contribution.ts @@ -423,7 +423,7 @@ registerCellCommand({ category: 'Cell' }, metadata: { - description: localize('positronNotebook.cell.insertAbove', "Insert code cell above") + description: localize('positronNotebook.codeCell.insertAbove', "Insert code cell above") } }); @@ -440,7 +440,35 @@ registerCellCommand({ category: 'Cell' }, metadata: { - description: localize('positronNotebook.cell.insertBelow', "Insert code cell below") + description: localize('positronNotebook.codeCell.insertBelow', "Insert code cell below") + } +}); + +registerCellCommand({ + commandId: 'positronNotebook.cell.insertMarkdownCellAboveAndFocusContainer', + handler: (cell) => cell.insertMarkdownCellAbove(), + actionBar: { + icon: 'codicon-arrow-up', + position: 'menu', + order: 100, + category: 'Cell' + }, + metadata: { + description: localize('positronNotebook.markdownCell.insertAbove', "Insert markdown cell above") + } +}); + +registerCellCommand({ + commandId: 'positronNotebook.cell.insertMarkdownCellBelowAndFocusContainer', + handler: (cell) => cell.insertMarkdownCellBelow(), + actionBar: { + icon: 'codicon-arrow-down', + position: 'menu', + order: 100, + category: 'Cell' + }, + metadata: { + description: localize('positronNotebook.markdownCell.insertBelow', "Insert markdown cell below") } }); @@ -462,8 +490,7 @@ registerCellCommand({ metadata: { description: localize('positronNotebook.cell.delete.description', "Delete the selected cell(s)"), } -} -); +}); // Make sure the run and stop commands are in the same place so they replace one another. const CELL_EXECUTION_POSITION = 10;