Skip to content

Commit 5abdd6c

Browse files
authored
Merge pull request #8473 from sagemathinc/jupyter-celltype-cellmenu-8472
frontend/jupyter: add cell-type switches to the button menu of a cell
2 parents e4792e6 + 51b2432 commit 5abdd6c

31 files changed

+209
-122
lines changed

src/packages/frontend/cspell.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
"timetravel",
4242
"tolerations",
4343
"undelete",
44-
"undeleting"
44+
"undeleting",
45+
"revealjs"
4546
],
4647
"ignoreWords": [
4748
"antd",
@@ -64,7 +65,9 @@
6465
"vertexai",
6566
"vfill",
6667
"xsmall",
67-
"flyouts"
68+
"flyouts",
69+
"buttonbar",
70+
"noconf"
6871
],
6972
"flagWords": [],
7073
"ignorePaths": ["node_modules/**", "dist/**", "dist-ts/**", "build/**"],

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

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ import {
1414
} from "@cocalc/frontend/jupyter/commands";
1515
import { create_key_handler } from "@cocalc/frontend/jupyter/keyboard";
1616
import Fragment from "@cocalc/frontend/misc/fragment-id";
17-
import { Cell, CellType, Scroll } from "@cocalc/jupyter/types";
17+
import { Cell, Scroll } from "@cocalc/jupyter/types";
1818
import { move_selected_cells } from "@cocalc/jupyter/util/cell-utils";
19+
import { CellType } from "@cocalc/util/jupyter/types";
1920
import {
2021
bind_methods,
2122
close,
@@ -214,7 +215,7 @@ export class NotebookFrameActions {
214215
}
215216

216217
/***
217-
* Debugging related functioanlity
218+
* Debugging related functionality
218219
***/
219220

220221
private dbg(f: string, ...args): void {
@@ -281,7 +282,7 @@ export class NotebookFrameActions {
281282
}
282283

283284
/* Run the selected cells; triggered by either clicking the play button or
284-
press shift+enter. Note that this has weird and inconsitent
285+
press shift+enter. Note that this has weird and inconsistent
285286
behavior in official Jupyter for usability reasons and due to
286287
their "modal" approach.
287288
In particular, if the selections goes to the end of the document, we
@@ -421,8 +422,7 @@ export class NotebookFrameActions {
421422
undefined,
422423
false,
423424
);
424-
let md_edit_ids = this.store.get("md_edit_ids");
425-
if (md_edit_ids == null) md_edit_ids = Set();
425+
const md_edit_ids = this.store.get("md_edit_ids", Set());
426426
if (md_edit_ids.contains(id)) {
427427
return;
428428
}
@@ -487,7 +487,7 @@ export class NotebookFrameActions {
487487
const cell = this.get_cell_by_id(id);
488488
if (cell == null) return;
489489

490-
if (cell.getIn(["metadata", "editable"]) === false) {
490+
if (!this.jupyter_actions.store.is_cell_editable(id)) {
491491
// TODO: NEVER ever silently fail!
492492
return;
493493
}
@@ -496,6 +496,29 @@ export class NotebookFrameActions {
496496
this.set_mode("edit");
497497
}
498498

499+
public cell_md_is_editing(id): boolean {
500+
const md_edit_ids = this.store.get("md_edit_ids", Set());
501+
return md_edit_ids.contains(id);
502+
}
503+
504+
public toggle_md_cell_edit(id: string): void {
505+
const cell = this.get_cell_by_id(id);
506+
if (cell == null) return;
507+
if (!this.jupyter_actions.store.is_cell_editable(id)) {
508+
// TODO: NEVER ever silently fail!
509+
return;
510+
}
511+
512+
if (this.cell_md_is_editing(id)) {
513+
this.set_md_cell_not_editing(id);
514+
this.set_mode("escape");
515+
} else {
516+
this.switch_md_cell_to_edit(id);
517+
this.set_mode("edit");
518+
}
519+
this.set_cur_id(id);
520+
}
521+
499522
public switch_code_cell_to_edit(id: string): void {
500523
const cell = this.get_cell_by_id(id);
501524
if (cell == null) return;
@@ -594,7 +617,7 @@ export class NotebookFrameActions {
594617
}
595618

596619
// select all cells, possibly of a given type.
597-
select_all_cells = (cell_type?: "code" | "markdown" | "raw") => {
620+
select_all_cells = (cell_type?: CellType) => {
598621
let sel_ids;
599622
if (cell_type) {
600623
sel_ids =

src/packages/frontend/frame-editors/jupyter-editor/editor.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55

66
/*
77
Spec for editing Jupyter notebooks via a frame tree.
8+
9+
cSpell:ignore JSONIPynb
810
*/
911

1012
import { createElement } from "react";
13+
1114
import type { Command } from "@cocalc/frontend/frame-editors/frame-tree/commands";
1215
import { addEditorMenus } from "@cocalc/frontend/frame-editors/frame-tree/commands";
1316
import { FORMAT_SOURCE_ICON } from "@cocalc/frontend/frame-editors/frame-tree/config";
@@ -25,10 +28,10 @@ import { Introspect } from "./introspect/introspect";
2528
import JSONIPynb from "./json-ipynb";
2629
import KernelMenuItem from "./kernel-menu-item";
2730
import { RawIPynb } from "./raw-ipynb";
31+
import { search } from "./search";
2832
import { Slideshow } from "./slideshow-revealjs/slideshow";
2933
import { JupyterSnippets } from "./snippets";
3034
import { TableOfContents } from "./table-of-contents";
31-
import { search } from "./search";
3235

3336
const SNIPPET_ICON_NAME = "magic";
3437

src/packages/frontend/i18n/common.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,20 @@ export const jupyter = {
12801280
defaultMessage: "None",
12811281
description: "Jupyter Notebook cell toolbar 'None' hides the toolbar",
12821282
},
1283+
change_cell_to_code: {
1284+
id: "jupyter.commands.change_cell_to_code.label",
1285+
defaultMessage: "Change Cell to Code",
1286+
},
1287+
change_cell_to_markdown: {
1288+
id: "jupyter.commands.change_cell_to_markdown.label",
1289+
defaultMessage: "Change Cell to Markdown",
1290+
description: "Cell in a Jupyter Notebook",
1291+
},
1292+
change_cell_to_raw: {
1293+
id: "jupyter.commands.change_cell_to_raw.label",
1294+
defaultMessage: "Change Cell to Raw",
1295+
description: "Cell in a Jupyter Notebook",
1296+
},
12831297
restart_kernel_noconf_menu: {
12841298
id: "jupyter.commands.restart_kernel_noconf.menu",
12851299
defaultMessage: "Restart kernel",

src/packages/frontend/i18n/trans/ar_EG.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@
664664
"jupyter.commands.change_cell_to_heading_5.label": "تغيير Markdown إلى Heading 5",
665665
"jupyter.commands.change_cell_to_heading_6.label": "تغيير Markdown إلى العنوان 6",
666666
"jupyter.commands.change_cell_to_markdown.label": "تغيير الخلية إلى Markdown",
667-
"jupyter.commands.change_cell_to_row.label": "تغيير الخلية إلى خام",
667+
"jupyter.commands.change_cell_to_raw.label": "تغيير الخلية إلى خام",
668668
"jupyter.commands.change_kernel": "تغيير النواة...",
669669
"jupyter.commands.change_kernel_title": "اختر من أي من النوى المتاحة",
670670
"jupyter.commands.clear_all_cells_output.label": "مسح جميع مخرجات الخلايا",

src/packages/frontend/i18n/trans/de_DE.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@
664664
"jupyter.commands.change_cell_to_heading_5.label": "Ändern Sie Markdown in Überschrift 5",
665665
"jupyter.commands.change_cell_to_heading_6.label": "Ändern Sie Markdown in Überschrift 6",
666666
"jupyter.commands.change_cell_to_markdown.label": "Ändere Zelle zu Markdown",
667-
"jupyter.commands.change_cell_to_row.label": "Zelle in Rohdaten ändern",
667+
"jupyter.commands.change_cell_to_raw.label": "Zelle in Rohdaten ändern",
668668
"jupyter.commands.change_kernel": "Kernel ändern...",
669669
"jupyter.commands.change_kernel_title": "Wählen Sie aus den verfügbaren Kernels.",
670670
"jupyter.commands.clear_all_cells_output.label": "Alle Zellausgaben löschen",

src/packages/frontend/i18n/trans/es_ES.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@
664664
"jupyter.commands.change_cell_to_heading_5.label": "Cambiar Markdown a Encabezado 5",
665665
"jupyter.commands.change_cell_to_heading_6.label": "Cambiar Markdown a Encabezado 6",
666666
"jupyter.commands.change_cell_to_markdown.label": "Cambiar Celda a Markdown",
667-
"jupyter.commands.change_cell_to_row.label": "Cambiar Celda a Raw",
667+
"jupyter.commands.change_cell_to_raw.label": "Cambiar Celda a Raw",
668668
"jupyter.commands.change_kernel": "Cambiar Kernel...",
669669
"jupyter.commands.change_kernel_title": "Seleccionar de cualquiera de los kernels disponibles",
670670
"jupyter.commands.clear_all_cells_output.label": "Borrar todas las salidas de celdas",

src/packages/frontend/i18n/trans/es_PV.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@
664664
"jupyter.commands.change_cell_to_heading_5.label": "Aldatu Markdown 5. goiburura",
665665
"jupyter.commands.change_cell_to_heading_6.label": "Aldatu Markdown 6. Izenburura",
666666
"jupyter.commands.change_cell_to_markdown.label": "Aldatu Zela Markdown-era",
667-
"jupyter.commands.change_cell_to_row.label": "Aldatu Zelaia Gordin bihurtzeko",
667+
"jupyter.commands.change_cell_to_raw.label": "Aldatu Zelaia Gordin bihurtzeko",
668668
"jupyter.commands.change_kernel": "Aldatu Kernel...",
669669
"jupyter.commands.change_kernel_title": "Hautatu eskuragarri dauden kernel batetik.",
670670
"jupyter.commands.clear_all_cells_output.label": "Garbitu Gelaxka Irteera Guztiak",

src/packages/frontend/i18n/trans/fr_FR.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@
664664
"jupyter.commands.change_cell_to_heading_5.label": "Changer Markdown en Titre 5",
665665
"jupyter.commands.change_cell_to_heading_6.label": "Changer Markdown en Titre 6",
666666
"jupyter.commands.change_cell_to_markdown.label": "Changer la cellule en Markdown",
667-
"jupyter.commands.change_cell_to_row.label": "Changer la cellule en brut",
667+
"jupyter.commands.change_cell_to_raw.label": "Changer la cellule en brut",
668668
"jupyter.commands.change_kernel": "Changer de noyau...",
669669
"jupyter.commands.change_kernel_title": "Sélectionnez parmi les noyaux disponibles.",
670670
"jupyter.commands.clear_all_cells_output.label": "Effacer tous les résultats des cellules",

src/packages/frontend/i18n/trans/he_IL.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@
664664
"jupyter.commands.change_cell_to_heading_5.label": "שנה את Markdown לכותרת 5",
665665
"jupyter.commands.change_cell_to_heading_6.label": "שנה את Markdown לכותרת 6",
666666
"jupyter.commands.change_cell_to_markdown.label": "שנה תא למרקדאון",
667-
"jupyter.commands.change_cell_to_row.label": "שנה תא לתא גולמי",
667+
"jupyter.commands.change_cell_to_raw.label": "שנה תא לתא גולמי",
668668
"jupyter.commands.change_kernel": "שנה קרנל...",
669669
"jupyter.commands.change_kernel_title": "בחר מתוך כל הליבות הזמינות",
670670
"jupyter.commands.clear_all_cells_output.label": "נקה את כל הפלטים של התאים",

0 commit comments

Comments
 (0)