Skip to content

Initial editor toolbar setup #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import AppNavigator from './organisms/AppNavigator'
import Toast from '../shared/components/organisms/Toast'
import styled from '../shared/lib/styled'
import { useToast } from '../shared/lib/stores/toast'
import {
applyBoldStyleEventEmitter,
applyItalicStyleEventEmitter,
} from '../lib/events'

const LoadingText = styled.div`
margin: 30px;
Expand Down Expand Up @@ -155,6 +159,23 @@ const App = () => {
}
}, [togglePreferencesModal, push])

useEffectOnce(() => {
const applyBoldStyleIpcEventHandler = () => {
applyBoldStyleEventEmitter.dispatch()
}
const applyItalicStyleIpcEventHandler = () => {
applyItalicStyleEventEmitter.dispatch()
}

addIpcListener('apply-bold-style', applyBoldStyleIpcEventHandler)
addIpcListener('apply-italic-style', applyItalicStyleIpcEventHandler)

return () => {
removeIpcListener('apply-bold-style', applyBoldStyleIpcEventHandler)
removeIpcListener('apply-italic-style', applyItalicStyleIpcEventHandler)
}
})

const switchWorkspaceHandler = useCallback(
(_event: any, index: number) => {
const storageIds = keys(storageMap)
Expand Down
43 changes: 42 additions & 1 deletion src/components/PreferencesModal/EditorTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import { themes } from '../../lib/CodeMirror'
import CustomizedCodeEditor from '../atoms/CustomizedCodeEditor'
import { useDebounce } from 'react-use'
import Form from '../../shared/components/molecules/Form'
import { SimpleFormSelect } from '../../shared/components/molecules/Form/atoms/FormSelect'
import FormSelect, {
FormSelectOption,
SimpleFormSelect,
} from '../../shared/components/molecules/Form/atoms/FormSelect'
import { lngKeys } from '../../lib/i18n/types'

const defaultPreviewContent = `# hello-world.js

Expand Down Expand Up @@ -101,6 +105,15 @@ const EditorTab = () => {
[setPreferences]
)

const selectShowEditorToolbar = useCallback(
(formOption: FormSelectOption) => {
setPreferences({
'editor.showEditorToolbar': formOption.value === 'Show',
})
},
[setPreferences]
)

const codeEditorKeydownInterceptor = useMemo<KeyboardEventHandler>(() => {
return (event) => {
if (event.key === 'Escape') {
Expand Down Expand Up @@ -187,6 +200,34 @@ const EditorTab = () => {
},
],
},
{
title: t(lngKeys.SettingsShowEditorToolbar),
items: [
{
type: 'node',
element: (
<FormSelect
options={[
{
label: t(lngKeys.GeneralShowVerb),
value: 'Show',
},
{ label: t(lngKeys.GeneralHideVerb), value: 'Hide' },
]}
value={{
label: preferences['editor.showEditorToolbar']
? t(lngKeys.GeneralShowVerb)
: t(lngKeys.GeneralHideVerb),
value: preferences['editor.showEditorToolbar']
? 'Show'
: 'Hide',
}}
onChange={selectShowEditorToolbar}
/>
),
},
],
},
{
title: t('preferences.editorKeymap'),
items: [
Expand Down
Loading