Skip to content

Commit

Permalink
Fixes running cells and jump to active cell (#38)
Browse files Browse the repository at this point in the history
* Fixes running cells and jump to active cell

* Review
  • Loading branch information
hbcarlos committed Jul 24, 2023
1 parent efac74f commit ce1e1f0
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions packages/application/src/plugins/rise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import { ICellModel } from '@jupyterlab/cells';
import { Mode } from '@jupyterlab/codemirror';
import { IChangedArgs, PageConfig, PathExt } from '@jupyterlab/coreutils';
import { IDocumentManager } from '@jupyterlab/docmanager';
import { INotebookModel, Notebook, NotebookPanel } from '@jupyterlab/notebook';
import {
INotebookModel,
Notebook,
NotebookActions,
NotebookPanel
} from '@jupyterlab/notebook';
import { ISettingRegistry } from '@jupyterlab/settingregistry';
import {
TranslationBundle,
Expand Down Expand Up @@ -85,7 +90,7 @@ export const plugin: JupyterFrontEndPlugin<void> = {
const notebookPath = PageConfig.getOption('notebookPath');
const notebookPanel = documentManager.open(notebookPath) as NotebookPanel;

Rise.registerCommands(app.commands, trans);
Rise.registerCommands(app.commands, notebookPanel, trans);
if (palette) {
[
CommandIDs.riseFullScreen,
Expand Down Expand Up @@ -276,7 +281,8 @@ namespace Rise {
}

/* Register commands */
function smartExec() {
function smartExec(panel: NotebookPanel) {
NotebookActions.runAndAdvance(panel.content, panel.context.sessionContext);
// TODO
// is it really the selected cell that matters ?
// let smart_exec = Jupyter.notebook.get_selected_cell().smart_exec;
Expand All @@ -299,14 +305,15 @@ namespace Rise {

export function registerCommands(
commands: CommandRegistry,
panel: NotebookPanel,
trans: TranslationBundle
): void {
// register main action
commands.addCommand(CommandIDs.riseSmartExec, {
caption: trans.__(
'execute cell, and move to the next if on the same slide'
),
execute: smartExec
execute: () => smartExec(panel)
});

// mostly for debug / information
Expand Down Expand Up @@ -1042,6 +1049,16 @@ namespace Rise {
/* safer, and nicer too, to wait for reveal extensions to start */
setTimeout(toggleAllRiseButtons, 2000);
}

panel.content.activeCellChanged.connect((sender, cell) => {
// Move to active cell
const slides = Reveal.getSlides();
const slide = slides.find(s => s.contains(cell.node));
if (slide) {
const i = Reveal.getIndices(slide as HTMLElement);
Reveal.slide(i.h, i.v, i.f);
}
});
}

function Unselecter(notebook: Notebook) {
Expand Down

0 comments on commit ce1e1f0

Please sign in to comment.