Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes running cells and jump to active cell #38

Merged
merged 2 commits into from
Jul 24, 2023
Merged
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
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 @@ -82,7 +87,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 @@ -273,7 +278,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 @@ -296,14 +302,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 @@ -1039,6 +1046,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