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" {
|
||||
interface Editor {
|
||||
getSelectedHtml(): string;
|
||||
@ -37,10 +39,10 @@ declare module "ckeditor5" {
|
||||
enabled: boolean;
|
||||
},
|
||||
moveBlockUp?: {
|
||||
keystroke: string;
|
||||
keystroke: Keystroke;
|
||||
},
|
||||
moveBlockDown?: {
|
||||
keystroke: string;
|
||||
keystroke: Keystroke;
|
||||
},
|
||||
clipboard?: {
|
||||
copy(text: string): void;
|
||||
|
@ -9,20 +9,21 @@ export default class MoveBlockUpDownPlugin extends Plugin {
|
||||
init() {
|
||||
const editor = this.editor;
|
||||
editor.config.define('moveBlockUp', {
|
||||
keystroke: 'ctrl+arrowup',
|
||||
keystroke: ['ctrl+arrowup', 'alt+arrowup'],
|
||||
});
|
||||
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('moveBlockDown', new MoveBlockDownCommand(editor));
|
||||
|
||||
editor.keystrokes.set(keystrokeUp, 'moveBlockUp');
|
||||
editor.keystrokes.set(keystrokeDown, 'moveBlockDown');
|
||||
for (const keystroke of editor.config.get('moveBlockUp.keystroke') ?? []) {
|
||||
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