mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
feat(editor/move_block): support multiple keystrokes
This commit is contained in:
parent
27d1a87fb0
commit
e2a089eb7e
@ -23,6 +23,8 @@ declare global {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Keystroke = string | string[];
|
||||||
|
|
||||||
declare module "ckeditor5" {
|
declare module "ckeditor5" {
|
||||||
interface Editor {
|
interface Editor {
|
||||||
getSelectedHtml(): string;
|
getSelectedHtml(): string;
|
||||||
@ -37,10 +39,10 @@ declare module "ckeditor5" {
|
|||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
},
|
},
|
||||||
moveBlockUp?: {
|
moveBlockUp?: {
|
||||||
keystroke: string;
|
keystroke: Keystroke;
|
||||||
},
|
},
|
||||||
moveBlockDown?: {
|
moveBlockDown?: {
|
||||||
keystroke: string;
|
keystroke: Keystroke;
|
||||||
},
|
},
|
||||||
clipboard?: {
|
clipboard?: {
|
||||||
copy(text: string): void;
|
copy(text: string): void;
|
||||||
|
@ -9,20 +9,21 @@ export default class MoveBlockUpDownPlugin extends Plugin {
|
|||||||
init() {
|
init() {
|
||||||
const editor = this.editor;
|
const editor = this.editor;
|
||||||
editor.config.define('moveBlockUp', {
|
editor.config.define('moveBlockUp', {
|
||||||
keystroke: 'ctrl+arrowup',
|
keystroke: ['ctrl+arrowup', 'alt+arrowup'],
|
||||||
});
|
});
|
||||||
editor.config.define('moveBlockDown', {
|
editor.config.define('moveBlockDown', {
|
||||||
keystroke: 'ctrl+arrowdown',
|
keystroke: ['ctrl+arrowdown', 'alt+arrowdown'],
|
||||||
});
|
});
|
||||||
|
|
||||||
const keystrokeUp = editor.config.get('moveBlockUp.keystroke')!;
|
|
||||||
const keystrokeDown = editor.config.get('moveBlockDown.keystroke')!;
|
|
||||||
|
|
||||||
editor.commands.add('moveBlockUp', new MoveBlockUpCommand(editor));
|
editor.commands.add('moveBlockUp', new MoveBlockUpCommand(editor));
|
||||||
editor.commands.add('moveBlockDown', new MoveBlockDownCommand(editor));
|
editor.commands.add('moveBlockDown', new MoveBlockDownCommand(editor));
|
||||||
|
|
||||||
editor.keystrokes.set(keystrokeUp, 'moveBlockUp');
|
for (const keystroke of editor.config.get('moveBlockUp.keystroke') ?? []) {
|
||||||
editor.keystrokes.set(keystrokeDown, 'moveBlockDown');
|
editor.keystrokes.set(keystroke, 'moveBlockUp');
|
||||||
|
}
|
||||||
|
for (const keystroke of editor.config.get('moveBlockDown.keystroke') ?? []) {
|
||||||
|
editor.keystrokes.set(keystroke, 'moveBlockDown');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user