Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I'm always lazy about this.

let index: number | undefined;

this._assertTextModel();
Expand All @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
});

Expand All @@ -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")
}
});

Expand All @@ -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;
Expand Down