mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-26 11:43:59 -05:00
Extract view mode shortcut code into hook (#688)
This commit is contained in:
parent
c6d2aa76ca
commit
4603e3988a
2 changed files with 13 additions and 8 deletions
|
@ -16,7 +16,7 @@ import { EditorPane } from './editor-pane/editor-pane'
|
|||
import { editorTestContent } from './editorTestContent'
|
||||
import { useFirstDraw } from './hooks/useFirstDraw'
|
||||
import { DualScrollState, ScrollState } from './scroll/scroll-props'
|
||||
import { shortcutHandler } from './shortcut/shortcut'
|
||||
import { useViewModeShortcuts } from './hooks/useViewModeShortcuts'
|
||||
import { Splitter } from './splitter/splitter'
|
||||
import { YAMLMetaData } from './yaml-metadata/yaml-metadata'
|
||||
|
||||
|
@ -75,12 +75,7 @@ export const Editor: React.FC = () => {
|
|||
}
|
||||
}, [markdownContent, setMarkdownContent])
|
||||
|
||||
useEffect(() => {
|
||||
document.addEventListener('keydown', shortcutHandler, false)
|
||||
return () => {
|
||||
document.removeEventListener('keydown', shortcutHandler, false)
|
||||
}
|
||||
}, [])
|
||||
useViewModeShortcuts()
|
||||
|
||||
const isFirstDraw = useFirstDraw()
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { useEffect } from 'react'
|
||||
import { setEditorMode } from '../../../redux/editor/methods'
|
||||
import { EditorMode } from '../app-bar/editor-view-mode'
|
||||
|
||||
export const shortcutHandler = (event: KeyboardEvent): void => {
|
||||
const shortcutHandler = (event: KeyboardEvent): void => {
|
||||
if (event.ctrlKey && event.altKey && event.key === 'b') {
|
||||
setEditorMode(EditorMode.BOTH)
|
||||
event.preventDefault()
|
||||
|
@ -17,3 +18,12 @@ export const shortcutHandler = (event: KeyboardEvent): void => {
|
|||
event.preventDefault()
|
||||
}
|
||||
}
|
||||
|
||||
export const useViewModeShortcuts = ():void => {
|
||||
useEffect(() => {
|
||||
document.addEventListener('keydown', shortcutHandler, false)
|
||||
return () => {
|
||||
document.removeEventListener('keydown', shortcutHandler, false)
|
||||
}
|
||||
}, [])
|
||||
}
|
Loading…
Reference in a new issue