fix(ckeditor): move block interfering with normal shortcut (closes #6964)

This commit is contained in:
Elian Doran 2025-11-27 19:37:21 +02:00
parent 6958e4b74f
commit 786f0db4bb
No known key found for this signature in database

View File

@ -2,9 +2,14 @@
* https://github.com/TriliumNext/Trilium/issues/1002 * https://github.com/TriliumNext/Trilium/issues/1002
*/ */
import { Command, ModelDocumentSelection, ModelElement, ModelNode, Plugin, ModelRange } from 'ckeditor5'; import { Command, ModelDocumentSelection, ModelElement, ModelNode, Plugin, ModelRange, _isMac } from 'ckeditor5';
export default class MoveBlockUpDownPlugin extends Plugin {
const keyMap = {
ArrowUp: 'moveBlockUp',
ArrowDown: 'moveBlockDown'
};
export default class MoveBlockUpDownPlugin extends Plugin {
init() { init() {
const editor = this.editor; const editor = this.editor;
@ -21,17 +26,14 @@ export default class MoveBlockUpDownPlugin extends Plugin {
const domRoot = editor.editing.view.getDomRoot(); const domRoot = editor.editing.view.getDomRoot();
if (!domRoot) return; if (!domRoot) return;
const isMac = _isMac(navigator.userAgent.toLowerCase());
const handleKeydown = (e: KeyboardEvent) => { const handleKeydown = (e: KeyboardEvent) => {
const keyMap = {
ArrowUp: 'moveBlockUp',
ArrowDown: 'moveBlockDown'
};
const command = keyMap[e.key]; const command = keyMap[e.key];
const isCtrl = e.ctrlKey || e.metaKey; if (!command) return;
const hasModifier = (isCtrl || e.altKey) && !(isCtrl && e.altKey); const isOnlyMeta = (!e.ctrlKey && !e.altKey && e.metaKey);
const isOnlyAlt = (!e.ctrlKey && e.altKey && !e.metaKey);
if (command && hasModifier) { if ((!isMac && isOnlyMeta) || isOnlyAlt) {
e.preventDefault(); e.preventDefault();
e.stopImmediatePropagation(); e.stopImmediatePropagation();
editor.execute(command); editor.execute(command);