mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-22 11:15:23 -04: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 { editorTestContent } from './editorTestContent'
|
||||||
import { useFirstDraw } from './hooks/useFirstDraw'
|
import { useFirstDraw } from './hooks/useFirstDraw'
|
||||||
import { DualScrollState, ScrollState } from './scroll/scroll-props'
|
import { DualScrollState, ScrollState } from './scroll/scroll-props'
|
||||||
import { shortcutHandler } from './shortcut/shortcut'
|
import { useViewModeShortcuts } from './hooks/useViewModeShortcuts'
|
||||||
import { Splitter } from './splitter/splitter'
|
import { Splitter } from './splitter/splitter'
|
||||||
import { YAMLMetaData } from './yaml-metadata/yaml-metadata'
|
import { YAMLMetaData } from './yaml-metadata/yaml-metadata'
|
||||||
|
|
||||||
|
@ -75,12 +75,7 @@ export const Editor: React.FC = () => {
|
||||||
}
|
}
|
||||||
}, [markdownContent, setMarkdownContent])
|
}, [markdownContent, setMarkdownContent])
|
||||||
|
|
||||||
useEffect(() => {
|
useViewModeShortcuts()
|
||||||
document.addEventListener('keydown', shortcutHandler, false)
|
|
||||||
return () => {
|
|
||||||
document.removeEventListener('keydown', shortcutHandler, false)
|
|
||||||
}
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
const isFirstDraw = useFirstDraw()
|
const isFirstDraw = useFirstDraw()
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
|
import { useEffect } from 'react'
|
||||||
import { setEditorMode } from '../../../redux/editor/methods'
|
import { setEditorMode } from '../../../redux/editor/methods'
|
||||||
import { EditorMode } from '../app-bar/editor-view-mode'
|
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') {
|
if (event.ctrlKey && event.altKey && event.key === 'b') {
|
||||||
setEditorMode(EditorMode.BOTH)
|
setEditorMode(EditorMode.BOTH)
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
@ -17,3 +18,12 @@ export const shortcutHandler = (event: KeyboardEvent): void => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const useViewModeShortcuts = ():void => {
|
||||||
|
useEffect(() => {
|
||||||
|
document.addEventListener('keydown', shortcutHandler, false)
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('keydown', shortcutHandler, false)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue