mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-11 02:42:27 +08:00
19 lines
521 B
TypeScript
19 lines
521 B
TypeScript
import { Plugin } from 'ckeditor5';
|
|
|
|
export default class ScrollOnUndoRedoPlugin extends Plugin {
|
|
init() {
|
|
const editor = this.editor;
|
|
|
|
const scrollToSelection = () => {
|
|
// Ensure scroll happens in sync with DOM updates
|
|
requestAnimationFrame(() => {
|
|
editor.editing.view.scrollToTheSelection();
|
|
});
|
|
};
|
|
|
|
// Scroll to selection after undo/redo to keep cursor in view
|
|
editor.commands.get('undo')?.on('execute', scrollToSelection);
|
|
editor.commands.get('redo')?.on('execute', scrollToSelection);
|
|
}
|
|
}
|