Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo } from 'react'
import React, { useMemo, useRef } from 'react'
import { useEffectOnce } from 'react-use'
import { getFirstFocusableChildOfElement } from '../../../lib/dom'
import { FormattingTool } from './types'
Expand Down Expand Up @@ -34,7 +34,7 @@ const EditorAdmonitionToolDropdown = ({
closeDropdowndown,
onFormatCallback,
}: EditorAdmonitionToolDropdownProps) => {
const menuRef = React.createRef<HTMLDivElement>()
const menuRef = useRef<HTMLDivElement>(null)

useEffectOnce(() => {
const focusableElement = getFirstFocusableChildOfElement(menuRef.current!)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo } from 'react'
import React, { useMemo, useRef } from 'react'
import { useEffectOnce } from 'react-use'
import { getFirstFocusableChildOfElement } from '../../../lib/dom'
import { FormattingTool } from './types'
Expand Down Expand Up @@ -45,7 +45,7 @@ const EditorHeaderToolDropdown = ({
closeDropdowndown,
onFormatCallback,
}: EditorHeaderToolDropdownProps) => {
const menuRef = React.createRef<HTMLDivElement>()
const menuRef = useRef<HTMLDivElement>(null)

useEffectOnce(() => {
const focusableElement = getFirstFocusableChildOfElement(menuRef.current!)
Expand Down
24 changes: 21 additions & 3 deletions src/cloud/components/molecules/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ import DocShare from '../DocShare'
import EditorLayout from '../../organisms/EditorLayout'
import PreferencesContextMenuWrapper from '../../molecules/PreferencesContextMenuWrapper'
import InviteCTAButton from '../InviteCTAButton'
import { BaseTheme } from '../../../../shared/lib/styled/types'

type LayoutMode = 'split' | 'preview' | 'editor'

Expand Down Expand Up @@ -596,6 +597,9 @@ const Editor = ({ doc, team, user, contributors, backLinks }: EditorProps) => {
)

const { settings } = useSettings()
const fontSize = settings['general.editorFontSize']
const fontFamily = settings['general.editorFontFamily']

const editorConfig: CodeMirror.EditorConfiguration = useMemo(() => {
const editorTheme = settings['general.editorTheme']
const theme =
Expand Down Expand Up @@ -1077,7 +1081,11 @@ const Editor = ({ doc, team, user, contributors, backLinks }: EditorProps) => {
</StyledLayoutDimensions>
)}
<StyledEditor className={editorLayout}>
<StyledEditorWrapper className={`layout-${editorLayout}`}>
<StyledEditorWrapper
className={`layout-${editorLayout}`}
fontFamily={fontFamily}
fontSize={fontSize}
>
<>
<CodeMirrorEditor
bind={bindCallback}
Expand Down Expand Up @@ -1241,8 +1249,11 @@ const ToolbarRow = styled.div`
border: solid 1px ${({ theme }) => theme.divideBorderColor};
border-radius: 5px;
`

const StyledEditorWrapper = styled.div`
interface FontOptionsProps {
fontSize: string
fontFamily: string
}
const StyledEditorWrapper = styled.div<BaseTheme & FontOptionsProps>`
position: relative;
height: auto;
width: 50%;
Expand All @@ -1252,6 +1263,13 @@ const StyledEditorWrapper = styled.div`
&.layout-preview {
display: none;
}

& .CodeMirror * {
font-size: ${({ fontSize }) =>
fontSize == null ? 'inherit' : `${fontSize}px`};
font-family: ${({ fontFamily }) =>
fontFamily == null ? 'monospace' : fontFamily};
}
`

const StyledPreview = styled.div`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react'
import React, { useEffect, useRef } from 'react'
import {
StyledRelativeDialog,
StyledWrapper,
Expand All @@ -17,7 +17,7 @@ const RelativeDialog = ({
closed,
setClosed,
}: React.PropsWithChildren<RelativeDialogProps>) => {
const dialogRef: React.RefObject<HTMLDivElement> = React.createRef()
const dialogRef = useRef<HTMLDivElement>(null)

useEffect(() => {
if (!closed) {
Expand Down
4 changes: 2 additions & 2 deletions src/cloud/components/molecules/Timeline/TimelineList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo } from 'react'
import React, { useMemo, useRef } from 'react'
import { SerializedAppEvent } from '../../../interfaces/db/appEvents'
import { useNav } from '../../../lib/stores/nav'
import { getOriginalDocId } from '../../../lib/utils/patterns'
Expand Down Expand Up @@ -28,7 +28,7 @@ const TimelineList = ({
workspacesMap,
}: TimelineListProps) => {
const { docsMap } = useNav()
const listRef = React.createRef<HTMLDivElement>()
const listRef = useRef<HTMLDivElement>(null)
useUpDownNavigationListener(listRef)

const timelineDocs = useMemo(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/cloud/components/organisms/EventSource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ const EventSource = ({ teamId }: EventSourceProps) => {
}

if (usingElectron) {
sendToElectron('team-update', event.data.team)
sendToElectron('team-update', { ...team, ...eventTeam })
}
},
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo } from 'react'
import React, { useMemo, useRef } from 'react'
import { useNav } from '../../../../lib/stores/nav'
import { sortByAttributeAsc } from '../../../../lib/utils/array'
import { SerializedWorkspace } from '../../../../interfaces/db/workspace'
Expand Down Expand Up @@ -28,7 +28,7 @@ const ImportModalSelectFolder = ({
onSelect,
}: ImportModalSelectFolderProps) => {
const { foldersMap, workspacesMap } = useNav()
const wrapperRef = React.createRef<HTMLDivElement>()
const wrapperRef = useRef<HTMLDivElement>(null)
const { translate } = useI18n()

const sortedWorkspaces = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ const TemplatesModal = ({ callback }: TemplatesModalProps) => {
currentParentFolderId,
} = useNav()
const { pushApiErrorMessage } = useToast()
const contentSideRef = React.createRef<HTMLDivElement>()
const menuRef = React.createRef<HTMLDivElement>()
const contentSideRef = useRef<HTMLDivElement>(null)
const menuRef = useRef<HTMLDivElement>(null)
const [filter, setFilter] = useState<string>('')
const [selectedTemplateId, setSelectedTemplateId] = useState<string>()
const [templateTitle, setTemplateTitle] = useState<string>('')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useCallback, useMemo } from 'react'
import React, { useState, useCallback, useMemo, useRef } from 'react'
import { usePage } from '../../../../../lib/stores/pageStore'
import { useNav } from '../../../../../lib/stores/nav'
import {
Expand Down Expand Up @@ -48,7 +48,7 @@ const FolderContextMenu = ({
const { openRenameFolderForm } = useCloudResourceModals()
const { translate } = useI18n()

const menuRef = React.createRef<HTMLDivElement>()
const menuRef = useRef<HTMLDivElement>(null)
useEffectOnce(() => {
menuRef.current!.focus()
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useMemo, useCallback } from 'react'
import React, { useState, useMemo, useCallback, useRef } from 'react'
import { usePage } from '../../../../../lib/stores/pageStore'
import { useNav } from '../../../../../lib/stores/nav'
import ContextMenuItem from './ControlsContextMenuItem'
Expand Down Expand Up @@ -46,7 +46,7 @@ const TagContextMenu = ({
const { pushApiErrorMessage } = useToast()
const { messageBox } = useDialog()

const menuRef = React.createRef<HTMLDivElement>()
const menuRef = useRef<HTMLDivElement>(null)
useEffectOnce(() => {
menuRef.current!.focus()
})
Expand Down
6 changes: 3 additions & 3 deletions src/cloud/components/organisms/settings/SettingsComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo, useEffect } from 'react'
import React, { useMemo, useEffect, useRef } from 'react'
import { useSettings } from '../../../lib/stores/settings'
import {
preventKeyboardEventPropagation,
Expand Down Expand Up @@ -57,8 +57,8 @@ const SettingsComponent = () => {
openSettingsTab,
settingsOpeningOptions,
} = useSettings()
const contentSideRef = React.createRef<HTMLDivElement>()
const menuRef = React.createRef<HTMLDivElement>()
const contentSideRef = useRef<HTMLDivElement>(null)
const menuRef = useRef<HTMLDivElement>(null)
const { team, subscription, currentUserPermissions } = usePage<
PageStoreWithTeam
>()
Expand Down
71 changes: 70 additions & 1 deletion src/cloud/components/organisms/settings/UserPreferencesForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback } from 'react'
import React, { ChangeEventHandler, useCallback, useState } from 'react'
import {
useSettings,
GeneralThemeOptions,
Expand All @@ -19,11 +19,19 @@ import FormSelect, {
} from '../../../../shared/components/molecules/Form/atoms/FormSelect'
import FormRow from '../../../../shared/components/molecules/Form/templates/FormRow'
import { lngKeys } from '../../../lib/i18n/types'
import { useDebounce } from 'react-use'

const UserPreferencesForm = () => {
const { settings, setSettings } = useSettings()
const { t } = useTranslation()

const [fontSize, setFontSize] = useState(
settings['general.editorFontSize'].toString()
)
const [fontFamily, setFontFamily] = useState(
settings['general.editorFontFamily']
)

const selectLanguage = useCallback(
(formOption: FormSelectOption) => {
setSettings({
Expand Down Expand Up @@ -100,6 +108,41 @@ const UserPreferencesForm = () => {
[setSettings]
)

const updateFontSize: ChangeEventHandler<HTMLInputElement> = useCallback(
(event) => {
setFontSize(event.target.value)
},
[setFontSize]
)
useDebounce(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Changing font family loses focus after update (not sure why it happens here and not in local space)

@Rokt33r any ideas?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should provide key for form item. Otherwise, react think the input element is replaced by a new element so it won't keep the focus

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our usage of react select might cause the issue.

() => {
const parsedFontSize = parseInt(fontSize, 10)
if (!Number.isNaN(parsedFontSize)) {
setSettings({
'general.editorFontSize': parsedFontSize,
})
}
},
500,
[fontSize, setSettings]
)

const updateFontFamily: ChangeEventHandler<HTMLInputElement> = useCallback(
(event) => {
setFontFamily(event.target.value)
},
[setFontFamily]
)
useDebounce(
() => {
setSettings({
'general.editorFontFamily': fontFamily,
})
},
500,
[fontFamily, setSettings]
)

return (
<Form
rows={[
Expand Down Expand Up @@ -162,6 +205,32 @@ const UserPreferencesForm = () => {
},
],
},
{
title: t(lngKeys.SettingsEditorFontSize),
items: [
{
type: 'input',
props: {
type: 'number',
value: fontSize,
onChange: updateFontSize,
},
},
],
},
{
title: t(lngKeys.SettingsEditorFontFamily),
items: [
{
type: 'input',
props: {
type: 'text',
value: fontFamily,
onChange: updateFontFamily,
},
},
],
},
{
title: t(lngKeys.SettingsEditorTheme),
items: [
Expand Down
2 changes: 2 additions & 0 deletions src/cloud/lib/i18n/enUS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const enTranslation: TranslationSource = {
[lngKeys.SettingsEditorTheme]: 'Editor Theme',
[lngKeys.SettingsCodeBlockTheme]: 'Code Block Theme',
[lngKeys.SettingsEditorKeyMap]: 'Editor Keymap',
[lngKeys.SettingsEditorFontSize]: 'Editor Font Size',
[lngKeys.SettingsEditorFontFamily]: 'Editor Font Family',
[lngKeys.SettingsLight]: 'Light',
[lngKeys.SettingsDark]: 'Dark',
[lngKeys.SettingsNotifFrequencies]: 'Email updates',
Expand Down
2 changes: 2 additions & 0 deletions src/cloud/lib/i18n/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const frTranslation: TranslationSource = {
[lngKeys.SettingsEditorTheme]: "Thème de l'éditeur",
[lngKeys.SettingsCodeBlockTheme]: 'Thème des blocs de code',
[lngKeys.SettingsEditorKeyMap]: "KeyMap pour l'éditeur",
[lngKeys.SettingsEditorFontSize]: "Taille de la police de l'éditeur",
[lngKeys.SettingsEditorFontFamily]: "Famille de polices de l'éditeur",
[lngKeys.SettingsLight]: 'Clair',
[lngKeys.SettingsDark]: 'Sombre',
[lngKeys.SettingsNotifFrequencies]: 'Fréquence de mises à jour par mail',
Expand Down
2 changes: 2 additions & 0 deletions src/cloud/lib/i18n/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const jpTranslation: TranslationSource = {
[lngKeys.SettingsEditorTheme]: 'エディタテーマ',
[lngKeys.SettingsCodeBlockTheme]: 'コードブロックテーマ',
[lngKeys.SettingsEditorKeyMap]: 'エディタのキーマップ',
[lngKeys.SettingsEditorFontSize]: 'エディタのフォントサイズ',
[lngKeys.SettingsEditorFontFamily]: 'エディタフォントファミリ',
[lngKeys.SettingsLight]: 'ライト',
[lngKeys.SettingsDark]: 'ダーク',
[lngKeys.SettingsNotifFrequencies]: 'メール設定',
Expand Down
2 changes: 2 additions & 0 deletions src/cloud/lib/i18n/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ export enum lngKeys {
SettingsEditorTheme = 'settings.editorTheme',
SettingsCodeBlockTheme = 'settings.codeblockTheme',
SettingsEditorKeyMap = 'settings.editorKeyMap',
SettingsEditorFontSize = 'settings.editorFontSize',
SettingsEditorFontFamily = 'settings.editorFontFamily',
SettingsLight = 'settings.light',
SettingsDark = 'settings.dark',
SettingsNotifFrequencies = 'settings.notificationsFrequency',
Expand Down
2 changes: 2 additions & 0 deletions src/cloud/lib/i18n/zhCN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const zhTranslation: TranslationSource = {
[lngKeys.SettingsEditorTheme]: '编辑主题',
[lngKeys.SettingsCodeBlockTheme]: '代码块主题',
[lngKeys.SettingsEditorKeyMap]: '编辑器键映射',
[lngKeys.SettingsEditorFontSize]: '编辑器字体大小',
[lngKeys.SettingsEditorFontFamily]: '编辑器字体系列',
[lngKeys.SettingsLight]: 'Light',
[lngKeys.SettingsDark]: 'Dark',
[lngKeys.SettingsNotifFrequencies]: 'Email updates',
Expand Down
3 changes: 3 additions & 0 deletions src/cloud/lib/stores/settings/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export const baseUserSettings: UserSettings = {
'general.editorKeyMap': 'default',
'general.editorIndentType': 'spaces',
'general.editorIndentSize': 2,
'general.editorFontSize': 15,
'general.editorFontFamily':
'SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace',
}

export type SettingsTab =
Expand Down
2 changes: 2 additions & 0 deletions src/cloud/lib/stores/settings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export interface UserSettings {
'general.editorKeyMap': CodeMirrorKeyMap
'general.editorIndentType': GeneralEditorIndentType
'general.editorIndentSize': GeneralEditorIndentSize
'general.editorFontSize': number
'general.editorFontFamily': string
}

export const codeMirrorEditorThemes = [
Expand Down
3 changes: 3 additions & 0 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ const App = () => {

const boostHubTeamUpdateEventHandler = (event: BoostHubTeamUpdateEvent) => {
const updatedTeam = event.detail.team
if (updatedTeam.id == null) {
return
}
setGeneralStatus((previousGeneralStatus) => {
const teamMap =
previousGeneralStatus.boostHubTeams!.reduce((map, team) => {
Expand Down
Loading