Skip to content

Commit 7acc989

Browse files
committed
fix bug in jupyter scroll when windowing is disabled
1 parent 6db5759 commit 7acc989

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
122122
read_only,
123123
} = props;
124124

125-
const cell_list_node = useRef<HTMLElement | null>(null);
125+
const cellListDivRef = useRef<any>(null);
126126
const is_mounted = useIsMountedRef();
127127
const frameActions = useNotebookFrameActions();
128128

@@ -140,7 +140,7 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
140140
frame_actions.focus(true);
141141
// setup a click handler so we can manage focus
142142
$(window).on("click", window_click);
143-
frame_actions.cell_list_div = $(cell_list_node.current);
143+
frame_actions.cell_list_div = $(cellListDivRef.current);
144144

145145
return () => {
146146
saveScroll();
@@ -172,7 +172,7 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
172172
}, [cur_id, scroll, scroll_seq]);
173173

174174
const handleCellListRef = useCallback((node: any) => {
175-
cell_list_node.current = node;
175+
cellListDivRef.current = node;
176176
frameActions.current?.set_cell_list_div(node);
177177
}, []);
178178

@@ -186,8 +186,8 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
186186
// We don't actually need to do anything though since our virtuoso
187187
// integration automatically solves this same problem.
188188
} else {
189-
if (cell_list_node.current != null) {
190-
frameActions.current?.set_scrollTop(cell_list_node.current.scrollTop);
189+
if (cellListDivRef.current != null) {
190+
frameActions.current?.set_scrollTop(cellListDivRef.current.scrollTop);
191191
}
192192
}
193193
}, [use_windowed_list]);
@@ -206,7 +206,7 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
206206
let scrollHeight: number = 0;
207207
for (const tm of [0, 1, 100, 250, 500, 1000]) {
208208
if (!is_mounted.current) return;
209-
const elt = cell_list_node.current;
209+
const elt = cellListDivRef.current;
210210
if (elt != null && elt.scrollHeight !== scrollHeight) {
211211
// dynamically rendering actually changed something
212212
elt.scrollTop = scrollTop;
@@ -218,7 +218,7 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
218218

219219
function window_click(event: any): void {
220220
// if click in the cell list, focus the cell list; otherwise, blur it.
221-
const elt = $(cell_list_node.current);
221+
const elt = $(cellListDivRef.current);
222222
// list no longer exists, nothing left to do
223223
// Maybe elt can be null? https://github.com/sagemathinc/cocalc/issues/3580
224224
if (elt.length == 0) return;
@@ -242,8 +242,8 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
242242
}
243243
}
244244

245-
async function scroll_cell_list_not_windowed(scroll: Scroll): Promise<void> {
246-
const node = $(cell_list_node.current);
245+
async function scrollCellListNotWindowed(scroll: Scroll): Promise<void> {
246+
const node = $(cellListDivRef.current);
247247
if (node.length == 0) return;
248248
if (typeof scroll === "number") {
249249
node.scrollTop(node.scrollTop() + scroll);
@@ -307,7 +307,7 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
307307
align = "end";
308308
isNotVisible = true;
309309
} else {
310-
const scroller = $(cell_list_node.current);
310+
const scroller = $(cellListDivRef.current);
311311
const cell = scroller.find(`#${cur_id}`);
312312
if (scroller[0] == null) return;
313313
if (cell[0] == null) return;
@@ -384,7 +384,7 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
384384
scrollCellListVirtuoso(scroll);
385385
} else {
386386
// scroll not using windowed list
387-
scroll_cell_list_not_windowed(scroll);
387+
scrollCellListNotWindowed(scroll);
388388
}
389389
}
390390

@@ -562,7 +562,6 @@ export const CellList: React.FC<CellListProps> = (props: CellListProps) => {
562562

563563
let body;
564564

565-
const cellListDivRef = useRef<HTMLDivElement>(null);
566565
const virtuosoHeightsRef = useRef<{ [index: number]: number }>({});
567566

568567
const cellListResize = useResizeObserver({ ref: cellListDivRef });

0 commit comments

Comments
 (0)