Skip to content

Commit b6dc492

Browse files
committed
feat(editor): support shortcut key
Resolved: #1875
1 parent 8aee49a commit b6dc492

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { inject } from 'vue';
22
import { EditorMdInjectionKey, IEditorMdInjection } from '../editor-md-types';
33

4-
export function useToolbar() {
5-
const { toolbars, toolbarConfig, customToolbars } = inject(EditorMdInjectionKey) as IEditorMdInjection;
6-
7-
return { toolbars, toolbarConfig, customToolbars };
4+
export function useToolbar(): IEditorMdInjection {
5+
return inject(EditorMdInjectionKey) as IEditorMdInjection;
86
}

packages/devui-vue/devui/editor-md/src/composables/use-editor-md.ts

+18
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,24 @@ export function useEditorMd(props: EditorMdProps, ctx: SetupContext) {
316316
setTimeout(() => {
317317
ctx.emit('contentChange', editorIns.getValue());
318318
}, 100);
319+
320+
containerRef.value.addEventListener('keydown', (e: KeyboardEvent) => {
321+
let keyCombination = '';
322+
if (e.ctrlKey) {
323+
keyCombination += 'Ctrl-';
324+
}
325+
if (e.altKey) {
326+
keyCombination += 'Alt-';
327+
}
328+
if (e.shiftKey) {
329+
keyCombination += 'Shift-';
330+
}
331+
keyCombination += e.key.toUpperCase();
332+
if (shortKeys[keyCombination] && typeof shortKeys[keyCombination] === 'function') {
333+
e.preventDefault();
334+
shortKeys[keyCombination]();
335+
}
336+
});
319337
};
320338

321339
const onPaste = (e: ClipboardEvent) => {

packages/devui-vue/devui/editor-md/src/editor-md-types.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { PropType, ExtractPropTypes, InjectionKey, Ref } from 'vue';
22
import { DEFAULT_TOOLBAR_CONFIG, IToolbarItemConfig } from './toolbar-config';
3+
import { RenderRule } from 'markdown-it/lib/renderer';
34

45
export interface MDThemeToolbarConfig {
56
icons: { [key: string]: string };
@@ -11,7 +12,7 @@ export interface MDThemeConfig {
1112

1213
export interface MdPlugin {
1314
plugin: any;
14-
opts?: Object;
15+
opts?: Record<string, unknown>;
1516
}
1617

1718
export interface ICustomXssRule {
@@ -21,7 +22,7 @@ export interface ICustomXssRule {
2122

2223
export interface ICustomRenderRule {
2324
key: string;
24-
value: Function;
25+
value: RenderRule;
2526
}
2627

2728
export type Mode = 'editonly' | 'readonly' | 'normal';
@@ -112,7 +113,7 @@ export const editorMdProps = {
112113
},
113114
toolbarConfig: {
114115
type: Array as PropType<ToolbarConfigProp>,
115-
default: () => DEFAULT_TOOLBAR_CONFIG,
116+
default: (): (string[] | string)[] => DEFAULT_TOOLBAR_CONFIG,
116117
},
117118
fullscreenZIndex: {
118119
type: Number,

packages/devui-vue/devui/editor-md/src/editor-md.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ export default defineComponent({
6161
onPreviewMouseover,
6262
} = useEditorMd(props, ctx);
6363

64-
const { isDarkMode } = useEditorMdTheme(() => {});
64+
const { isDarkMode } = useEditorMdTheme(() => {
65+
return;
66+
});
6567

6668
provide(EditorMdInjectionKey, {
6769
showFullscreen,
@@ -97,7 +99,7 @@ export default defineComponent({
9799
origin={cursorRef.value || undefined}
98100
align="start"
99101
position={['bottom-start']}
100-
onClick={withModifiers(() => {}, ['stop'])}>
102+
onClick={withModifiers(() => {return ;}, ['stop'])}>
101103
{ctx.slots?.hintTemplate?.()}
102104
</FlexibleOverlay>
103105
{Boolean(maxlength?.value) && (

0 commit comments

Comments
 (0)