Skip to content

Commit 51b2432

Browse files
committed
frontend/jupyter: add run button to markdown cells as well
1 parent 3e0373d commit 51b2432

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

src/packages/frontend/frame-editors/jupyter-editor/cell-notebook/actions.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,7 @@ export class NotebookFrameActions {
422422
undefined,
423423
false,
424424
);
425-
let md_edit_ids = this.store.get("md_edit_ids");
426-
if (md_edit_ids == null) md_edit_ids = Set();
425+
const md_edit_ids = this.store.get("md_edit_ids", Set());
427426
if (md_edit_ids.contains(id)) {
428427
return;
429428
}
@@ -497,9 +496,8 @@ export class NotebookFrameActions {
497496
this.set_mode("edit");
498497
}
499498

500-
cell_md_is_editing(id): boolean {
501-
let md_edit_ids = this.store.get("md_edit_ids");
502-
if (md_edit_ids == null) md_edit_ids = Set();
499+
public cell_md_is_editing(id): boolean {
500+
const md_edit_ids = this.store.get("md_edit_ids", Set());
503501
return md_edit_ids.contains(id);
504502
}
505503

@@ -511,14 +509,14 @@ export class NotebookFrameActions {
511509
return;
512510
}
513511

514-
this.set_cur_id(id);
515512
if (this.cell_md_is_editing(id)) {
516513
this.set_md_cell_not_editing(id);
517514
this.set_mode("escape");
518515
} else {
519516
this.switch_md_cell_to_edit(id);
520517
this.set_mode("edit");
521518
}
519+
this.set_cur_id(id);
522520
}
523521

524522
public switch_code_cell_to_edit(id: string): void {

src/packages/frontend/jupyter/browser-actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export class JupyterActions extends JupyterActions0 {
221221
}
222222

223223
const cell_type = cell.get("cell_type", "code");
224-
if (cell_type == "code") {
224+
if (cell_type === "code") {
225225
const code = this.get_cell_input(id).trim();
226226
if (!code) {
227227
this.clear_cell(id, save);

src/packages/frontend/jupyter/cell-buttonbar.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,14 @@ export const CellButtonBar: React.FC<Props> = React.memo(
111111
tooltip: "Run this cell",
112112
label: "Run",
113113
icon: "step-forward",
114-
onClick: () => actions?.run_cell(id),
114+
onClick: () => frameActions.current?.run_cell(id),
115115
};
116116
}
117117
}
118118

119119
function renderCodeBarRunStop() {
120120
if (
121-
!isCodeCell ||
121+
!(isCodeCell || isMarkdownCell) ||
122122
id == null ||
123123
actions == null ||
124124
actions.is_closed() ||
@@ -262,16 +262,21 @@ export const CellButtonBar: React.FC<Props> = React.memo(
262262
return;
263263
}
264264

265+
const editing = frameActions.current?.cell_md_is_editing(id);
266+
265267
return (
266268
<Button
267269
style={CODE_BAR_BTN_STYLE}
268270
size="small"
269271
type="text"
270272
onClick={() => {
271-
frameActions.current?.toggle_md_cell_edit(cell.get("id"));
273+
frameActions.current?.toggle_md_cell_edit(id);
272274
}}
273275
>
274-
<Icon name="edit" /> {intl.formatMessage(labels.edit)}
276+
<Icon name={editing ? "save" : "edit"} />{" "}
277+
{editing
278+
? intl.formatMessage(labels.save)
279+
: intl.formatMessage(labels.edit)}
275280
</Button>
276281
);
277282
}

0 commit comments

Comments
 (0)