mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 03:29:02 +01:00 
			
		
		
		
	Merge pull request #2197 from TriliumNext/ck_patch
fix(ckeditor5): scroll to selection after undo/redo to keep cursor in view
This commit is contained in:
		
						commit
						af698550fd
					
				| @ -27,6 +27,7 @@ import "@triliumnext/ckeditor5-math/index.css"; | |||||||
| import CodeBlockToolbar from "./plugins/code_block_toolbar.js"; | import CodeBlockToolbar from "./plugins/code_block_toolbar.js"; | ||||||
| import CodeBlockLanguageDropdown from "./plugins/code_block_language_dropdown.js"; | import CodeBlockLanguageDropdown from "./plugins/code_block_language_dropdown.js"; | ||||||
| import MoveBlockUpDownPlugin from "./plugins/move_block_updown.js"; | import MoveBlockUpDownPlugin from "./plugins/move_block_updown.js"; | ||||||
|  | import ScrollOnUndoRedoPlugin from "./plugins/scroll_on_undo_redo.js" | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Plugins that are specific to Trilium and not part of the CKEditor 5 core, included in both text editors but not in the attribute editor. |  * Plugins that are specific to Trilium and not part of the CKEditor 5 core, included in both text editors but not in the attribute editor. | ||||||
| @ -46,7 +47,8 @@ const TRILIUM_PLUGINS: typeof Plugin[] = [ | |||||||
|     SyntaxHighlighting, |     SyntaxHighlighting, | ||||||
|     CodeBlockLanguageDropdown, |     CodeBlockLanguageDropdown, | ||||||
|     CodeBlockToolbar, |     CodeBlockToolbar, | ||||||
|     MoveBlockUpDownPlugin |     MoveBlockUpDownPlugin, | ||||||
|  | 	ScrollOnUndoRedoPlugin | ||||||
| ]; | ]; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  | |||||||
| @ -14,7 +14,7 @@ export default class InsertDateTimePlugin extends Plugin { | |||||||
|                 tooltip: true |                 tooltip: true | ||||||
|             } ); |             } ); | ||||||
| 
 | 
 | ||||||
|             // enable internal link only if the editor is not read only
 |             // enable only if the editor is not read only
 | ||||||
|             view.bind('isEnabled').to(editor, 'isReadOnly', isReadOnly => !isReadOnly); |             view.bind('isEnabled').to(editor, 'isReadOnly', isReadOnly => !isReadOnly); | ||||||
| 
 | 
 | ||||||
|             view.on('execute', () => { |             view.on('execute', () => { | ||||||
|  | |||||||
							
								
								
									
										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); | ||||||
|  | 	} | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Elian Doran
						Elian Doran