Skip to content

Commit 7075d39

Browse files
committed
Introducing editor font size UI parameter.
1 parent 88bcca6 commit 7075d39

File tree

5 files changed

+61
-9
lines changed

5 files changed

+61
-9
lines changed

src/components/forms/EditUserUIDataForm/EditUserUIDataForm.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Callout from '../../widgets/Callout';
88
import FormBox from '../../widgets/FormBox';
99
import { SaveIcon } from '../../icons';
1010
import SubmitButton from '../SubmitButton';
11-
import { CheckboxField, SelectField } from '../Fields';
11+
import { CheckboxField, SelectField, NumericTextField } from '../Fields';
1212

1313
const defaultPagesCaptions = defineMessages({
1414
dashboard: {
@@ -32,6 +32,10 @@ const getDefaultPages = defaultMemoize(formatMessage =>
3232
}))
3333
);
3434

35+
export const EDITOR_FONT_SIZE_MIN = 5;
36+
export const EDITOR_FONT_SIZE_MAX = 50;
37+
export const EDITOR_FONT_SIZE_DEFAULT = 16;
38+
3539
const EditUserUIDataForm = ({
3640
submitting,
3741
handleSubmit,
@@ -96,6 +100,14 @@ const EditUserUIDataForm = ({
96100
}
97101
/>
98102

103+
<NumericTextField
104+
name="editorFontSize"
105+
maxLength={2}
106+
validateMin={EDITOR_FONT_SIZE_MIN}
107+
validateMax={EDITOR_FONT_SIZE_MAX}
108+
label={<FormattedMessage id="app.editUserUIData.editorFontSize" defaultMessage="Code editor font size:" />}
109+
/>
110+
99111
<Field
100112
name="vimMode"
101113
component={CheckboxField}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
import EditUserUIDataForm from './EditUserUIDataForm';
1+
import EditUserUIDataForm, {
2+
EDITOR_FONT_SIZE_MIN,
3+
EDITOR_FONT_SIZE_MAX,
4+
EDITOR_FONT_SIZE_DEFAULT,
5+
} from './EditUserUIDataForm';
26
export default EditUserUIDataForm;
7+
export { EDITOR_FONT_SIZE_MIN, EDITOR_FONT_SIZE_MAX, EDITOR_FONT_SIZE_DEFAULT };

src/components/forms/Fields/SourceCodeField.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const SourceCodeField = ({
2727
{canUseDOM && (
2828
<div className={readOnly ? 'noselection' : ''}>
2929
<UserUIDataContext.Consumer>
30-
{({ vimMode = false, darkTheme = true }) => (
30+
{({ vimMode = false, darkTheme = true, editorFontSize = 16 }) => (
3131
<AceEditor
3232
{...props}
3333
{...input}
@@ -41,7 +41,7 @@ const SourceCodeField = ({
4141
minLines={5}
4242
maxLines={20}
4343
readOnly={readOnly}
44-
fontSize={16}
44+
fontSize={editorFontSize}
4545
onBlur={
4646
() => input.onBlur() // this is a hack that will ensure blur call without distorting the contents
4747
}

src/components/helpers/SourceCodeViewer/SourceCodeViewer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const AceEditor = canUseDOM ? require('react-ace').default : null;
99
const SourceCodeViewer = ({ name, content = '' }) =>
1010
canUseDOM ? (
1111
<UserUIDataContext.Consumer>
12-
{({ vimMode = false, darkTheme = true }) => (
12+
{({ vimMode = false, darkTheme = true, editorFontSize = 16 }) => (
1313
<AceEditor
1414
value={content}
1515
mode={getAceModeFromExtension(name.split('.').pop())}
@@ -18,7 +18,7 @@ const SourceCodeViewer = ({ name, content = '' }) =>
1818
name="source-code-viewer"
1919
width="100%"
2020
height="100%"
21-
fontSize={16}
21+
fontSize={editorFontSize}
2222
editorProps={{ $blockScrolling: true, $autoScrollEditorIntoView: true }}
2323
/>
2424
)}

src/pages/EditUser/EditUser.js

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,39 @@ import AllowUserButtonContainer from '../../containers/AllowUserButtonContainer'
2626

2727
import EditUserProfileForm from '../../components/forms/EditUserProfileForm';
2828
import EditUserSettingsForm from '../../components/forms/EditUserSettingsForm';
29-
import EditUserUIDataForm from '../../components/forms/EditUserUIDataForm';
29+
import EditUserUIDataForm, {
30+
EDITOR_FONT_SIZE_MIN,
31+
EDITOR_FONT_SIZE_MAX,
32+
EDITOR_FONT_SIZE_DEFAULT,
33+
} from '../../components/forms/EditUserUIDataForm';
3034
import GenerateTokenForm from '../../components/forms/GenerateTokenForm';
3135
import EditUserRoleForm from '../../components/forms/EditUserRoleForm';
3236
import { generateToken, takeOver } from '../../redux/modules/auth';
3337
import { lastGeneratedToken, loggedInUserIdSelector } from '../../redux/selectors/auth';
3438

39+
const prepareNumber = (number, min, max, defaultValue) => {
40+
number = Number(number);
41+
if (isNaN(number)) {
42+
return defaultValue;
43+
}
44+
return Math.max(Math.min(number, max), min);
45+
};
46+
3547
const prepareUserUIDataInitialValues = defaultMemoize(
36-
({ darkTheme = true, vimMode = false, openedSidebar = true, useGravatar = true, defaultPage = null }) => ({
48+
({
49+
darkTheme = true,
50+
vimMode = false,
51+
openedSidebar = true,
52+
useGravatar = true,
53+
defaultPage = null,
54+
editorFontSize = EDITOR_FONT_SIZE_DEFAULT,
55+
}) => ({
3756
darkTheme,
3857
vimMode,
3958
openedSidebar,
4059
useGravatar,
4160
defaultPage: defaultPage || '',
61+
editorFontSize: prepareNumber(editorFontSize, EDITOR_FONT_SIZE_MIN, EDITOR_FONT_SIZE_MAX, EDITOR_FONT_SIZE_DEFAULT),
4262
})
4363
);
4464

@@ -237,7 +257,22 @@ export default connect(
237257
loadAsync: () => EditUser.loadAsync({ userId }, dispatch),
238258
refreshUser: () => dispatch(fetchUser(userId)),
239259
updateSettings: data => dispatch(updateSettings(userId, data)),
240-
updateUIData: data => dispatch(updateUIData(userId, data, false)),
260+
updateUIData: ({ editorFontSize, ...data }) =>
261+
dispatch(
262+
updateUIData(
263+
userId,
264+
{
265+
editorFontSize: prepareNumber(
266+
editorFontSize,
267+
EDITOR_FONT_SIZE_MIN,
268+
EDITOR_FONT_SIZE_MAX,
269+
EDITOR_FONT_SIZE_DEFAULT
270+
),
271+
...data,
272+
},
273+
false
274+
)
275+
),
241276
updateProfile: data => dispatch(updateProfile(userId, data)),
242277
makeLocalLogin: () => dispatch(makeLocalLogin(userId)),
243278
generateToken: formData =>

0 commit comments

Comments
 (0)