@@ -7,10 +7,8 @@ import {useEnsuredForwardedRef, useKey, useUpdate} from 'react-use';
77import { ClassNameProps , cn } from '../classname' ;
88import { i18n } from '../i18n/bundle' ;
99import { logger } from '../logger' ;
10- import { useBooleanState } from '../react-utils/hooks' ;
11- import { ToasterContext } from '../react-utils/toaster' ;
12- import { useSticky } from '../react-utils/useSticky' ;
13- import { isMac } from '../utils/platform' ;
10+ import { ToasterContext , useBooleanState , useSticky } from '../react-utils' ;
11+ import { isMac } from '../utils' ;
1412
1513import type { Editor , EditorInt , EditorMode } from './Editor' ;
1614import { HorizontalDrag } from './HorizontalDrag' ;
@@ -20,15 +18,13 @@ import {WysiwygEditorView} from './WysiwygEditorView';
2018import {
2119 MToolbarData ,
2220 MToolbarItemData ,
23- mHiddenDataByPreset ,
24- mToolbarConfigByPreset ,
25- } from './config/markup' ;
26- import {
2721 WToolbarData ,
2822 WToolbarItemData ,
23+ mHiddenDataByPreset ,
24+ mToolbarConfigByPreset ,
2925 wHiddenDataByPreset ,
3026 wToolbarConfigByPreset ,
31- } from './config/wysiwyg ' ;
27+ } from './config' ;
3228import { useMarkdownEditorContext } from './context' ;
3329import { EditorSettings , EditorSettingsProps } from './settings' ;
3430import { stickyCn } from './sticky' ;
@@ -136,6 +132,19 @@ export const MarkdownEditorView = React.forwardRef<HTMLDivElement, MarkdownEdito
136132 const editorWrapperRef = useRef ( null ) ;
137133 const splitModeViewWrapperRef = useRef ( null ) ;
138134
135+ useEffect ( ( ) => {
136+ if ( showPreview ) {
137+ divRef . current . focus ( ) ;
138+ }
139+ } , [ divRef , showPreview ] ) ;
140+
141+ useKey (
142+ ( e ) => showPreview && isWrapperFocused ( divRef ) && isSubmitKeyDown ( e ) ,
143+ ( ) => editor . emit ( 'submit' , null ) ,
144+ { event : 'keydown' } ,
145+ [ showPreview ] ,
146+ ) ;
147+
139148 const settings = useMemo (
140149 ( ) => (
141150 < Settings
@@ -200,6 +209,8 @@ export const MarkdownEditorView = React.forwardRef<HTMLDivElement, MarkdownEdito
200209 } ,
201210 [ className ] ,
202211 ) }
212+ role = "button"
213+ tabIndex = { 0 }
203214 >
204215 < div className = { b ( 'editor-wrapper' ) } ref = { editorWrapperRef } >
205216 { showPreview ? (
@@ -304,3 +315,12 @@ function isPreviewKeyDown(e: KeyboardEvent) {
304315 const modKey = isMac ( ) ? e . metaKey : e . ctrlKey ;
305316 return modKey && e . shiftKey && e . code === 'KeyP' ;
306317}
318+
319+ function isWrapperFocused ( divRef : React . RefObject < HTMLDivElement > ) {
320+ return document . activeElement === divRef . current ;
321+ }
322+
323+ function isSubmitKeyDown ( e : KeyboardEvent ) {
324+ const modKey = isMac ( ) ? e . metaKey : e . ctrlKey ;
325+ return modKey && e . code === 'Enter' ;
326+ }
0 commit comments