feat(editor/move_block): support multiple keystrokes

This commit is contained in:
Elian Doran 2025-05-27 20:39:52 +03:00
parent 27d1a87fb0
commit e2a089eb7e
No known key found for this signature in database
2 changed files with 12 additions and 9 deletions

View File

@ -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;

View File

@ -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');
}
}
}