mirror of
https://github.com/zadam/trilium.git
synced 2025-11-09 06:45:49 +01:00
fix(ckeditor5): scroll to selection after undo/redo to keep cursor in view
This commit is contained in:
18
packages/ckeditor5/src/plugins/scroll_on_undo_redo.ts
Normal file
18
packages/ckeditor5/src/plugins/scroll_on_undo_redo.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user