mirror of
https://github.com/zadam/trilium.git
synced 2025-11-28 19:44:24 +01:00
fix(ckeditor): move block interfering with normal shortcut (closes #6964)
This commit is contained in:
parent
6958e4b74f
commit
786f0db4bb
@ -2,9 +2,14 @@
|
||||
* https://github.com/TriliumNext/Trilium/issues/1002
|
||||
*/
|
||||
|
||||
import { Command, ModelDocumentSelection, ModelElement, ModelNode, Plugin, ModelRange } from 'ckeditor5';
|
||||
export default class MoveBlockUpDownPlugin extends Plugin {
|
||||
import { Command, ModelDocumentSelection, ModelElement, ModelNode, Plugin, ModelRange, _isMac } from 'ckeditor5';
|
||||
|
||||
const keyMap = {
|
||||
ArrowUp: 'moveBlockUp',
|
||||
ArrowDown: 'moveBlockDown'
|
||||
};
|
||||
|
||||
export default class MoveBlockUpDownPlugin extends Plugin {
|
||||
init() {
|
||||
const editor = this.editor;
|
||||
|
||||
@ -21,17 +26,14 @@ export default class MoveBlockUpDownPlugin extends Plugin {
|
||||
const domRoot = editor.editing.view.getDomRoot();
|
||||
if (!domRoot) return;
|
||||
|
||||
const isMac = _isMac(navigator.userAgent.toLowerCase());
|
||||
const handleKeydown = (e: KeyboardEvent) => {
|
||||
const keyMap = {
|
||||
ArrowUp: 'moveBlockUp',
|
||||
ArrowDown: 'moveBlockDown'
|
||||
};
|
||||
|
||||
const command = keyMap[e.key];
|
||||
const isCtrl = e.ctrlKey || e.metaKey;
|
||||
const hasModifier = (isCtrl || e.altKey) && !(isCtrl && e.altKey);
|
||||
if (!command) return;
|
||||
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.stopImmediatePropagation();
|
||||
editor.execute(command);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user