From 22a31b3f95dedb8db7e2c7fb74a9b1512d66f920 Mon Sep 17 00:00:00 2001 From: Marcos Alves Date: Wed, 26 Jun 2024 14:18:02 -0300 Subject: [PATCH] feat: adding run cells to markdown cells also #247 --- packages/react/src/components/cell/CellAdapter.ts | 5 ++--- packages/react/src/components/cell/CellCommands.ts | 12 +++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/react/src/components/cell/CellAdapter.ts b/packages/react/src/components/cell/CellAdapter.ts index f402ec52..d8970509 100755 --- a/packages/react/src/components/cell/CellAdapter.ts +++ b/packages/react/src/components/cell/CellAdapter.ts @@ -303,9 +303,7 @@ export class CellAdapter { }); handler.editor = editor; - if (this._type === 'code') { - CellCommands(commands, (this._codeCell as CodeCell)!, this._sessionContext, handler); - } + CellCommands(commands, this._codeCell!, this._sessionContext, handler); completer.hide(); completer.addClass('jp-Completer-Cell'); Widget.attach(completer, document.body); @@ -347,6 +345,7 @@ export class CellAdapter { this._panel.spacing = 0; this._panel.addWidget(toolbar); this._panel.addWidget(this._codeCell); + BoxPanel.setStretch(toolbar, 0); BoxPanel.setStretch(this._codeCell, 1); window.addEventListener('resize', () => { diff --git a/packages/react/src/components/cell/CellCommands.ts b/packages/react/src/components/cell/CellCommands.ts index bc93f421..35c2eb6d 100644 --- a/packages/react/src/components/cell/CellCommands.ts +++ b/packages/react/src/components/cell/CellCommands.ts @@ -6,7 +6,7 @@ import { CommandRegistry } from '@lumino/commands'; import { CompletionHandler } from '@jupyterlab/completer'; -import { CodeCell } from '@jupyterlab/cells'; +import { CodeCell, MarkdownCell, RawCell } from '@jupyterlab/cells'; import { SessionContext } from '@jupyterlab/apputils'; const cmdIds = { @@ -16,7 +16,7 @@ const cmdIds = { export const CellCommands = ( commandRegistry: CommandRegistry, - codeCell: CodeCell, + codeCell: CodeCell | MarkdownCell | RawCell, sessionContext: SessionContext, completerHandler: CompletionHandler ): void => { @@ -29,7 +29,13 @@ export const CellCommands = ( execute: () => completerHandler.completer.selectActive(), }); commandRegistry.addCommand('run:cell', { - execute: () => CodeCell.execute(codeCell, sessionContext), + execute: () => { + if (codeCell instanceof CodeCell) { + CodeCell.execute(codeCell, sessionContext) + } else if (codeCell instanceof MarkdownCell) { + (codeCell as MarkdownCell).rendered = true; + } + }, }); commandRegistry.addKeyBinding({ selector: '.jp-InputArea-editor.jp-mod-completer-enabled',