Skip to content

Commit 5c0a3aa

Browse files
committed
Remove .jp-mod-commandMode:focus select from undo and redo selectors, use sharedModels Yjs undo manager to redo and undo instead of NotebookActions
1 parent 3ac5b26 commit 5c0a3aa

File tree

1 file changed

+43
-17
lines changed

1 file changed

+43
-17
lines changed

packages/react/src/components/notebook/NotebookCommands.ts

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
} from '@jupyterlab/documentsearch';
2121
import { Widget } from '@lumino/widgets';
2222
import { nullTranslator } from '@jupyterlab/translation';
23+
import { IYText } from '@jupyter/ydoc';
2324

2425
/**
2526
* The map of command ids used by the notebook.
@@ -274,13 +275,38 @@ export const NotebookCommands = (
274275
execute: () => NotebookActions.splitCell(notebookPanel.content),
275276
});
276277
commandRegistry.addCommand(cmdIds.undo, {
277-
label: 'Undo',
278-
execute: () => NotebookActions.undo(notebookPanel.content),
279-
});
280-
commandRegistry.addCommand(cmdIds.redo, {
281-
label: 'Redo',
282-
execute: () => NotebookActions.redo(notebookPanel.content),
283-
});
278+
label: 'Undo',
279+
execute: () => {
280+
const activeCell = notebookPanel.content.activeCell;
281+
if (activeCell) {
282+
const sharedModel = activeCell.model
283+
.sharedModel as any as IYText;
284+
if (sharedModel.undoManager) {
285+
sharedModel.undoManager.undo();
286+
} else {
287+
// Fallback to default undo if Yjs undo manager is not available
288+
NotebookActions.undo(notebookPanel.content);
289+
}
290+
}
291+
},
292+
});
293+
294+
commandRegistry.addCommand(cmdIds.redo, {
295+
label: 'Redo',
296+
execute: () => {
297+
const activeCell = notebookPanel.content.activeCell;
298+
if (activeCell) {
299+
const sharedModel = activeCell.model
300+
.sharedModel as any as IYText;
301+
if (sharedModel.undoManager) {
302+
sharedModel.undoManager.redo();
303+
} else {
304+
// Fallback to default redo if Yjs undo manager is not available
305+
NotebookActions.redo(notebookPanel.content);
306+
}
307+
}
308+
},
309+
});
284310
commandRegistry.addCommand(cmdIds.changeCellTypeToCode, {
285311
label: 'Change Cell Type to Code',
286312
execute: args =>
@@ -426,16 +452,16 @@ export const NotebookCommands = (
426452
keys: ['Shift J'],
427453
command: cmdIds.extendBelow,
428454
},
429-
{
430-
selector: '.jp-Notebook.jp-mod-commandMode:focus',
431-
keys: ['Ctrl Z'],
432-
command: cmdIds.undo,
433-
},
434-
{
435-
selector: '.jp-Notebook.jp-mod-commandMode:focus',
436-
keys: ['Ctrl Y'],
437-
command: cmdIds.redo,
438-
},
455+
{
456+
selector: '.jp-Notebook',
457+
keys: ['Ctrl Z'],
458+
command: cmdIds.undo,
459+
},
460+
{
461+
selector: '.jp-Notebook',
462+
keys: ['Ctrl Y'],
463+
command: cmdIds.redo,
464+
},
439465
{
440466
selector: '.jp-Notebook:focus',
441467
keys: ['M'],

0 commit comments

Comments
 (0)