Supported toolbox activate key setting in Config.

This commit is contained in:
tsuyoz 2023-10-01 10:20:35 +09:00
parent c9014e670d
commit 184609c5c6
3 changed files with 36 additions and 2 deletions

View file

@ -7,6 +7,7 @@ import { CriticalError } from './errors/critical';
import EventsDispatcher from './utils/events';
import Modules from './modules';
import { EditorEventMap } from './events';
import { keyCodes } from './utils';
/**
* Editor.js core class. Bootstraps modules.
@ -187,6 +188,11 @@ export default class Core {
* Text direction. If not set, uses ltr
*/
this.config.i18n.direction = this.config.i18n?.direction || 'ltr';
/**
* KeyCode for activate toolbox. If not set, uses TAB key
*/
this.config.toolboxKeyCode = this.config.toolboxKeyCode || keyCodes.TAB;
}
/**

View file

@ -49,7 +49,7 @@ export default class BlockEvents extends Module {
this.arrowLeftAndUp(event);
break;
case _.keyCodes.TAB:
case this.config.toolboxKeyCode:
this.tabPressed(event);
break;
}
@ -135,18 +135,35 @@ export default class BlockEvents extends Module {
const canOpenToolbox = currentBlock.tool.isDefault && isEmptyBlock;
const conversionToolbarOpened = !isEmptyBlock && ConversionToolbar.opened;
const inlineToolbarOpened = !isEmptyBlock && !SelectionUtils.isCollapsed && InlineToolbar.opened;
const canOpenBlockTunes = !conversionToolbarOpened && !inlineToolbarOpened;
const canOpenBlockTunes = !conversionToolbarOpened && !inlineToolbarOpened && this.isBlockSettingKeyPressed(event);
/**
* For empty Blocks we show Plus button via Toolbox only for default Blocks
*/
if (canOpenToolbox) {
event.stopPropagation();
event.preventDefault();
this.activateToolbox();
} else if (canOpenBlockTunes) {
event.stopPropagation();
event.preventDefault();
this.activateBlockSettings();
}
}
/**
* Returns whether the setting key is pressed
*
* @param {KeyboardEvent} event keyboard event
* @private
*/
private isBlockSettingKeyPressed(event: KeyboardEvent): boolean {
if (this.config.blockSettingModifier === undefined) {
return true;
}
return event.getModifierState(this.config.blockSettingModifier);
}
/**
* Add drop target styles
*

View file

@ -104,4 +104,15 @@ export interface EditorConfig {
* Common Block Tunes list. Will be added to all the blocks which do not specify their own 'tunes' set
*/
tunes?: string[];
/**
* KeyCode for activate toolbox
*/
toolboxKeyCode?: number;
/**
* Modifier key for activate block setting
*/
blockSettingModifier?: string;
}