@kangc/v-md-editor
Version:
A markdown editor built on Vue
28 lines (22 loc) • 688 B
JavaScript
import { importAll } from '@/utils/util';
const defaultHotkeys = {};
importAll(defaultHotkeys, require.context('@/hotkeys', false, /\.(js)$/));
export default function (Component) {
return {
mounted() {
if (this.isPreviewMode) return;
const { hotkeys } = Component;
Object.keys(defaultHotkeys).forEach((key) => {
this.registerHotkeys(defaultHotkeys[key].default);
});
hotkeys.forEach((config) => {
this.registerHotkeys(config);
});
},
methods: {
registerHotkeys({ modifier, key, action }) {
this.editorRegisterHotkeys({ modifier, key, action: (...arg) => action(this, ...arg) });
},
},
};
}