mirror of
https://github.com/TriliumNext/Trilium.git
synced 2025-12-11 05:45:26 -06: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
|
* 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);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user