Skip to content

Commit bb5f139

Browse files
committed
jupyter stable html: support disabling virtualization while having stable html
1 parent b27be3e commit bb5f139

File tree

3 files changed

+38
-29
lines changed

3 files changed

+38
-29
lines changed

src/packages/frontend/account/editor-settings/checkboxes.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const EDITOR_SETTINGS_CHECKBOXES: { [setting: string]: string | Rendered } = {
3030
build_on_save: "build LaTex/Rmd files whenever it is saved to disk",
3131
show_exec_warning: "warn that certain files are not directly executable",
3232
ask_jupyter_kernel: "ask which kernel to use for a new Jupyter Notebook",
33+
disable_jupyter_virtualization:
34+
"render entire notebook instead of just visible part (slower and not recommended)",
3335
jupyter_classic: (
3436
<span>
3537
<A href="https://github.com/sagemathinc/cocalc/issues/7706">

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

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
143143
frame_actions.cell_list_div = $(cell_list_node.current);
144144

145145
return () => {
146-
save_scroll();
146+
saveScroll();
147147
// handle focus via an event handler on window.
148148
// We have to do this since, e.g., codemirror editors
149149
// involve spans that aren't even children, etc...
@@ -180,7 +180,7 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
180180
return render_loading();
181181
}
182182

183-
function save_scroll(): void {
183+
const saveScroll = useCallback(() => {
184184
if (use_windowed_list) {
185185
// TODO -- virtuoso
186186
// We don't actually need to do anything though since our virtuoso
@@ -190,7 +190,11 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
190190
frameActions.current?.set_scrollTop(cell_list_node.current.scrollTop);
191191
}
192192
}
193-
}
193+
}, [use_windowed_list]);
194+
195+
const saveScrollDebounce = useMemo(() => {
196+
return debounce(saveScroll, 2000);
197+
}, [use_windowed_list]);
194198

195199
async function restore_scroll(): Promise<void> {
196200
if (scrollTop == null || use_windowed_list) return;
@@ -543,12 +547,13 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
543547
const scrollOrResize = useMemo(() => {
544548
return {};
545549
}, []);
546-
useEffect(() => {
547-
if (!use_windowed_list) return;
550+
const updateScrollOrResize = useCallback(() => {
548551
for (const key in scrollOrResize) {
549552
scrollOrResize[key]();
550553
}
551-
}, [cells]);
554+
}, []);
555+
556+
useEffect(updateScrollOrResize, [cells]);
552557

553558
const fileContext = useFileContext();
554559

@@ -559,17 +564,14 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
559564

560565
const cellListResize = useResizeObserver({ ref: cellListDivRef });
561566
useEffect(() => {
562-
if (!use_windowed_list) return;
563567
for (const key in scrollOrResize) {
564568
scrollOrResize[key]();
565569
}
566570
}, [cellListResize]);
567571

568572
if (use_windowed_list) {
569573
body = (
570-
<StableHtmlContext.Provider
571-
value={{ cellListDivRef, scrollOrResize }}
572-
>
574+
<StableHtmlContext.Provider value={{ cellListDivRef, scrollOrResize }}>
573575
<div ref={cellListDivRef} className="smc-vfill">
574576
<Virtuoso
575577
ref={virtuosoRef}
@@ -658,24 +660,27 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
658660
v.push(BOTTOM_PADDING_CELL);
659661

660662
body = (
661-
<div
662-
key="cells"
663-
className="smc-vfill"
664-
style={{
665-
fontSize: `${font_size}px`,
666-
paddingLeft: "5px",
667-
flex: 1,
668-
overflowY: "auto",
669-
overflowX: "hidden",
670-
}}
671-
ref={handleCellListRef}
672-
onClick={actions != null && complete != null ? on_click : undefined}
673-
onScroll={debounce(() => {
674-
save_scroll();
675-
}, 3000)}
676-
>
677-
{v}
678-
</div>
663+
<StableHtmlContext.Provider value={{ cellListDivRef, scrollOrResize }}>
664+
<div
665+
key="cells"
666+
className="smc-vfill"
667+
style={{
668+
fontSize: `${font_size}px`,
669+
paddingLeft: "5px",
670+
flex: 1,
671+
overflowY: "auto",
672+
overflowX: "hidden",
673+
}}
674+
ref={cellListDivRef}
675+
onClick={actions != null && complete != null ? on_click : undefined}
676+
onScroll={() => {
677+
updateScrollOrResize();
678+
saveScrollDebounce();
679+
}}
680+
>
681+
{v}
682+
</div>
683+
</StableHtmlContext.Provider>
679684
);
680685
}
681686

src/packages/frontend/jupyter/output-messages/stable-unsafe-html.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ export default function StableUnsafeHtml({
146146
// scroll work in there though -- if you want to see the whole thing, you
147147
// must not collapse it.
148148
const containerRect = cellOutputDivRef.current?.getBoundingClientRect();
149+
//console.log({ containerRect, parentRect, eltRect });
150+
149151
const bottom = Math.max(
150152
top,
151153
Math.min(
@@ -257,7 +259,7 @@ export default function StableUnsafeHtml({
257259
}, []);
258260

259261
useEffect(() => {
260-
// This is "ugly jquery"... but I did try passing this info
262+
// This is "old fashioned jquery"... but I tried passing this info
261263
// down via stableHtmlContext and it gets REALLY complicated.
262264
// Also this only happens once on mount, so it's not a problem
263265
// regarding efficiency.

0 commit comments

Comments
 (0)