mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-23 19:47:03 -04:00
parent
058b6ab97a
commit
8a9c2c923d
2 changed files with 28 additions and 1 deletions
|
@ -13,6 +13,7 @@ import { DocumentRenderPane } from './document-renderer-pane/document-render-pan
|
||||||
import { EditorPane } from './editor-pane/editor-pane'
|
import { EditorPane } from './editor-pane/editor-pane'
|
||||||
import { editorTestContent } from './editorTestContent'
|
import { editorTestContent } from './editorTestContent'
|
||||||
import { DualScrollState, ScrollState } from './scroll/scroll-props'
|
import { DualScrollState, ScrollState } from './scroll/scroll-props'
|
||||||
|
import { shortcutHandler } from './shortcut/shortcut'
|
||||||
import { Splitter } from './splitter/splitter'
|
import { Splitter } from './splitter/splitter'
|
||||||
import { YAMLMetaData } from './yaml-metadata/yaml-metadata'
|
import { YAMLMetaData } from './yaml-metadata/yaml-metadata'
|
||||||
|
|
||||||
|
@ -64,6 +65,13 @@ export const Editor: React.FC = () => {
|
||||||
updateDocumentTitle()
|
updateDocumentTitle()
|
||||||
}, [updateDocumentTitle])
|
}, [updateDocumentTitle])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
document.addEventListener('keyup', shortcutHandler, false)
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('keyup', shortcutHandler, false)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setFirstDraw(false)
|
setFirstDraw(false)
|
||||||
}, [])
|
}, [])
|
||||||
|
@ -101,7 +109,7 @@ export const Editor: React.FC = () => {
|
||||||
content={markdownContent}
|
content={markdownContent}
|
||||||
scrollState={scrollState.editorScrollState}
|
scrollState={scrollState.editorScrollState}
|
||||||
onScroll={onEditorScroll}
|
onScroll={onEditorScroll}
|
||||||
onMakeScrollSource={() => scrollSource.current = ScrollSource.EDITOR}
|
onMakeScrollSource={() => (scrollSource.current = ScrollSource.EDITOR)}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
showRight={editorMode === EditorMode.PREVIEW || (editorMode === EditorMode.BOTH)}
|
showRight={editorMode === EditorMode.PREVIEW || (editorMode === EditorMode.BOTH)}
|
||||||
|
|
19
src/components/editor/shortcut/shortcut.ts
Normal file
19
src/components/editor/shortcut/shortcut.ts
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import { setEditorMode } from '../../../redux/editor/methods'
|
||||||
|
import { EditorMode } from '../app-bar/editor-view-mode'
|
||||||
|
import { isMac } from '../utils'
|
||||||
|
|
||||||
|
export const shortcutHandler = (event: KeyboardEvent): void => {
|
||||||
|
const modifierKey = isMac ? event.metaKey : event.ctrlKey
|
||||||
|
|
||||||
|
if (modifierKey && event.altKey && event.key === 'b') {
|
||||||
|
setEditorMode(EditorMode.BOTH)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modifierKey && event.altKey && event.key === 'v') {
|
||||||
|
setEditorMode(EditorMode.PREVIEW)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modifierKey && event.altKey && event.key === 'e') {
|
||||||
|
setEditorMode(EditorMode.EDITOR)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue