Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import isKeyHotkey, {toKeyName} from 'is-hotkey'
import {SlateEditor} from '../typeDefs'
type Options = {
decorators?: string[]
}
// This plugin makes keyboard shortcuts for decorators
const isStrongHotkey = isKeyHotkey('mod+b')
const isEmphasisHotkey = isKeyHotkey('mod+i')
const isUnderlinedHotkey = isKeyHotkey('mod+u')
const isCodeHotKey = isKeyHotkey("mod+'")
const modKeyPlatformName = toKeyName('mod')
export const keyMaps = {
strong: `${modKeyPlatformName} + b`,
em: `${modKeyPlatformName} + i`,
underline: `${modKeyPlatformName} + u`,
code: `${modKeyPlatformName} + '`
}
export default function SetMarksOnKeyComboPlugin(options: Options = {}) {
const decorators = options.decorators || []
return {
onKeyDown(event: React.KeyboardEvent, editor: SlateEditor, next: (arg0: void) => void) {
let mark
if (isStrongHotkey(event)) {
mark = 'strong'
} else if (isEmphasisHotkey(event)) {
const handleBase = e => {
const sanitizedKey = toKeyName(e.key);
if((key === null || key === sanitizedKey) && !e.repeat){
handle(e);
}
};
handleNativeEvent(e){
const sanitizedKey = toKeyName(e.key);
if(e.repeat){
return;
}
this.downKeys = this.downKeys.filter(key => key !== sanitizedKey);
if(e.type === 'keydown'){
this.downKeys.push(sanitizedKey);
}
}