Skip to content

Commit 8605410

Browse files
authored
Keep track of the last fragment or sub-slide displayed when moving back or forward (#11)
* Keep current fragment or subslide in memory when moving back or forward * add tests * lint
1 parent 3394fac commit 8605410

File tree

4 files changed

+112
-12
lines changed

4 files changed

+112
-12
lines changed

atest/resources/Deck.resource

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Filter Visible Elements
112112
RETURN ${visible}
113113
[Teardown] Resume Screenshots
114114

115-
Advance Notebook Deck With Keyboard
115+
Advance Notebook Deck With Space
116116
[Documentation] Go to the down/forward slide with space, wait a bit, then screenshot.
117117
[Arguments] ${screenshot}=${EMPTY} ${expect}=${EMPTY} ${backup}=${FALSE}
118118
${index} = Get Active Cell Index
@@ -130,18 +130,47 @@ Advance Notebook Deck With Keyboard
130130
IF ${screenshot.__len__()} Capture Page Screenshot ${screenshot}
131131
[Teardown] Resume Screenshots
132132

133+
Back Or Forward Notebook Deck With Arrows
134+
[Documentation] Go to the back/forward slide with arrows, wait a bit, then screenshot.
135+
[Arguments] ${screenshot}=${EMPTY} ${expect}=${EMPTY} ${backup}=${FALSE}
136+
${index} = Get Active Cell Index
137+
Send Error Screenshots To Trash
138+
IF ${backup}
139+
Press Keys css:body ARROW_LEFT
140+
ELSE
141+
Press Keys css:body ARROW_RIGHT
142+
END
143+
Wait Until Cell Is Not Active ${index} 1s
144+
IF ${expect.__len__()}
145+
Wait Until Element Contains css:${JLAB CSS ACTIVE CELL} ${expect}
146+
END
147+
Resume Screenshots
148+
IF ${screenshot.__len__()} Capture Page Screenshot ${screenshot}
149+
[Teardown] Resume Screenshots
150+
133151
Back Up Deck With Keyboard
134152
[Documentation] Go to the up/back slide with space, wait a bit, then screenshot.
135153
[Arguments] ${screenshot}=${EMPTY} ${expect}=${EMPTY}
136-
Advance Notebook Deck With Keyboard ${screenshot} ${expect} backup=${TRUE}
154+
Advance Notebook Deck With Space ${screenshot} ${expect} backup=${TRUE}
137155

138-
Really Advance Notebook Deck With Keyboard
156+
Really Advance Notebook Deck With Space
139157
[Documentation] REALLY go to the down/forward slide with space, wait a bit, then screenshot.
140158
[Arguments] ${screenshot}=${EMPTY} ${expect}=${EMPTY} ${backup}=${FALSE}
141159
Wait Until Keyword Succeeds 5x 0.5s
142-
... Advance Notebook Deck With Keyboard ${screenshot} ${expect} ${backup}
160+
... Advance Notebook Deck With Space ${screenshot} ${expect} ${backup}
143161

144-
Really Back Up Deck With Keyboard
162+
Really Back Up Deck With Space
145163
[Documentation] REALLY go to the up/back slide with space, wait a bit, then screenshot.
146164
[Arguments] ${screenshot}=${EMPTY} ${expect}=${EMPTY}
147-
Really Advance Notebook Deck With Keyboard ${screenshot} ${expect} backup=${TRUE}
165+
Really Advance Notebook Deck With Space ${screenshot} ${expect} backup=${TRUE}
166+
167+
Really Move Forward Deck With Arrow
168+
[Documentation] REALLY go to back or forward slide with arrow, wait a bit, then screenshot.
169+
[Arguments] ${screenshot}=${EMPTY} ${expect}=${EMPTY} ${backup}=${FALSE}
170+
Wait Until Keyword Succeeds 5x 0.5s
171+
... Back Or Forward Notebook Deck With Arrows ${screenshot} ${expect} ${backup}
172+
173+
Really Move Back Deck With Arrow
174+
[Documentation] REALLY go to back slide with arrow, wait a bit, then screenshot.
175+
[Arguments] ${screenshot}=${EMPTY} ${expect}=${EMPTY}
176+
Really Move Forward Deck With Arrow ${screenshot} ${expect} backup=${TRUE}

atest/resources/Docs.resource

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ Start Notebook Deck With Subslides
3939
Make Markdown Cell subslide 2 subslide 2
4040
Select A Slide Type 5 subslide s2-02-new-subslide.png
4141

42+
Start Advanced Notebook Deck
43+
[Documentation] Make a few cells with fragments and subslides
44+
Execute JupyterLab Command Close All Tabs
45+
Start Empty Notebook Deck
46+
Click Element css:${JLAB CSS ACTIVE CELL}
47+
Make Markdown Cell \# Slide 1 Slide 1 new=${FALSE} screenshot=s2-00-slide1.png
48+
Make Markdown Cell - Fragment 1.1 Fragment 1.1 screenshot=s2-01-fragment1.png
49+
Make Markdown Cell \# Slide 2 Slide 2 screenshot=s2-02-slide2.png
50+
Make Markdown Cell - Fragment 2.1 Fragment 2.1 screenshot=s2-03-fragment2.png
51+
4252
Tear Down Interactive Suite
4353
[Documentation] Clean up after this suite.
4454
Execute JupyterLab Command Close All Tabs

atest/suites/lab/02-navigate.robot

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ Build and Navigate a Notebook Slide With Keyboard
2222
[Documentation] Build and navigate a basic slide.
2323
Set Attempt Screenshot Directory lab${/}navigate${/}keyboard
2424
Start Basic Notebook Deck
25-
Really Back Up Deck With Keyboard s0-03-backup.png item1234
26-
Really Back Up Deck With Keyboard s0-04-backup.png World
27-
Really Advance Notebook Deck With Keyboard s0-05-advance.png item1234
28-
Really Advance Notebook Deck With Keyboard s0-06-advance.png item4567
25+
Really Back Up Deck With Space s0-03-backup.png item1234
26+
Really Back Up Deck With Space s0-04-backup.png World
27+
Really Advance Notebook Deck With Space s0-05-advance.png item1234
28+
Really Advance Notebook Deck With Space s0-06-advance.png item4567
2929

3030
Build and Navigate a Notebook Slide With Anchors
3131
[Documentation] Build and navigate a basic slide.
@@ -43,3 +43,12 @@ Build and Navigate a Notebook Slide With Subslides
4343
Really Back Up Deck With Keyboard s2-04-backup.png item4567
4444
Really Advance Notebook Deck With Keyboard s2-05-advance.png subslide 1
4545
Really Advance Notebook Deck With Keyboard s2-06-advance.png subslide 2
46+
47+
Build and Navigate an Advanced Notebook Deck With Arrows
48+
[Documentation] Build and navigate a basic slide.
49+
Set Attempt Screenshot Directory lab${/}navigate${/}arrows
50+
Start Advanced Notebook Deck
51+
Really Move Back Deck With Arrow s2-04-back.png Slide 1
52+
Really Advance Notebook Deck With Space s2-05-advance.png Fragment 1
53+
Really Move Forward Deck With Arrow s2-06-advance.png Fragment 2
54+
Really Move Back Deck With Arrow s2-07-back.png Fragment 1

js/jupyterlab-slideshow/src/notebook/presenter.ts

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,17 @@ export class NotebookPresenter implements IPresenter<NotebookPanel> {
382382
const fromExtentAlternate = alternate && activeExtent && activeExtent[alternate];
383383

384384
if (fromExtent != null) {
385-
panel.content.activeCellIndex = fromExtent;
385+
let moveTo = fromExtent;
386+
if (['back', 'forward'].includes(direction)) {
387+
moveTo = this._slideBackup(extents, activeCellIndex, fromExtent);
388+
}
389+
panel.content.activeCellIndex = moveTo;
386390
} else if (fromExtentAlternate != null) {
387-
panel.content.activeCellIndex = fromExtentAlternate;
391+
let moveTo = fromExtentAlternate;
392+
if (['back', 'forward'].includes(direction)) {
393+
moveTo = this._slideBackup(extents, activeCellIndex, fromExtentAlternate);
394+
}
395+
panel.content.activeCellIndex = moveTo;
388396
} else {
389397
console.warn(
390398
EMOJI,
@@ -575,6 +583,7 @@ export class NotebookPresenter implements IPresenter<NotebookPanel> {
575583
back: null,
576584
up: null,
577585
down: null,
586+
redirect: null,
578587
...extent,
579588
index,
580589
slideType,
@@ -903,6 +912,48 @@ export class NotebookPresenter implements IPresenter<NotebookPanel> {
903912

904913
return extents;
905914
}
915+
916+
/**
917+
* This function must be called only when moving back or forward.
918+
* It will backup the current fragment or subslide in the parent slide extent,
919+
* to go back to it on a future use of back or forward move.
920+
*
921+
* @param extents - the extents for the current NotebookModel.
922+
* @param current - the index of the current active cell.
923+
* @param target - the index of the targeted cell (should be a slide).
924+
* @returns - the index of the next active cell to move to if there was a redirection
925+
* set up.
926+
*/
927+
protected _slideBackup(
928+
extents: NotebookPresenter.TExtentMap,
929+
current: number,
930+
target: number,
931+
) {
932+
// Set parent slide redirection
933+
let parentSlide = extents.get(current);
934+
while (parentSlide && parentSlide?.slideType !== 'slide') {
935+
if (parentSlide.up !== null) {
936+
parentSlide = extents.get(parentSlide.up);
937+
} else {
938+
break;
939+
}
940+
}
941+
// Do not set redirection on parent slide if the target is the parent slide,
942+
// or if the current is a slide.
943+
if (parentSlide?.index === current || parentSlide?.index === target) {
944+
parentSlide.redirect = null;
945+
} else if (parentSlide?.slideType === 'slide') {
946+
parentSlide.redirect = current;
947+
}
948+
949+
// Return target redirection (if exist)
950+
const targetExtent = extents.get(target);
951+
if (targetExtent?.redirect) {
952+
return targetExtent.redirect;
953+
} else {
954+
return target;
955+
}
956+
}
906957
}
907958

908959
export namespace NotebookPresenter {
@@ -923,6 +974,7 @@ export namespace NotebookPresenter {
923974
onScreen: number[];
924975
visible: number[];
925976
notes: number[];
977+
redirect: number | null;
926978
}
927979
export type TExtentMap = Map<number, IExtent>;
928980
/** a map of active slide to active layers */

0 commit comments

Comments
 (0)