feat: adjust code editor font size (#2204)

* add font-size setting for code editor

* add code font size to remaining editors

* align font-size after font-family

* changed default font size to 14

* fixed className typo

* set inherit mode if unset

* add code font size schema validation

* add font size to folder settings

---------

Co-authored-by: Anoop M D <anoop.md1421@gmail.com>
This commit is contained in:
Max Bauer 2024-08-27 14:56:58 +02:00 committed by GitHub
parent 682c7bd1b1
commit ee7f886c03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 65 additions and 15 deletions

View File

@ -5,6 +5,7 @@ const StyledWrapper = styled.div`
background: ${(props) => props.theme.codemirror.bg}; background: ${(props) => props.theme.codemirror.bg};
border: solid 1px ${(props) => props.theme.codemirror.border}; border: solid 1px ${(props) => props.theme.codemirror.border};
font-family: ${(props) => (props.font ? props.font : 'default')}; font-family: ${(props) => (props.font ? props.font : 'default')};
font-size: ${(props) => (props.fontSize ? `${props.fontSize}px` : 'inherit')};
line-break: anywhere; line-break: anywhere;
flex: 1 1 0; flex: 1 1 0;
} }

View File

@ -333,6 +333,7 @@ export default class CodeEditor extends React.Component {
className="h-full w-full flex flex-col relative" className="h-full w-full flex flex-col relative"
aria-label="Code Editor" aria-label="Code Editor"
font={this.props.font} font={this.props.font}
fontSize={this.props.fontSize}
ref={(node) => { ref={(node) => {
this._node = node; this._node = node;
}} }}

View File

@ -46,6 +46,7 @@ const Docs = ({ collection }) => {
onSave={onSave} onSave={onSave}
mode="application/text" mode="application/text"
font={get(preferences, 'font.codeFont', 'default')} font={get(preferences, 'font.codeFont', 'default')}
fontSize={get(preferences, 'font.codeFontSize')}
/> />
) : ( ) : (
<Markdown collectionPath={collection.pathname} onDoubleClick={toggleViewMode} content={docs} /> <Markdown collectionPath={collection.pathname} onDoubleClick={toggleViewMode} content={docs} />

View File

@ -52,6 +52,7 @@ const Script = ({ collection }) => {
mode="javascript" mode="javascript"
onSave={handleSave} onSave={handleSave}
font={get(preferences, 'font.codeFont', 'default')} font={get(preferences, 'font.codeFont', 'default')}
fontSize={get(preferences, 'font.codeFontSize')}
/> />
</div> </div>
<div className="flex-1 mt-6"> <div className="flex-1 mt-6">
@ -64,6 +65,7 @@ const Script = ({ collection }) => {
mode="javascript" mode="javascript"
onSave={handleSave} onSave={handleSave}
font={get(preferences, 'font.codeFont', 'default')} font={get(preferences, 'font.codeFont', 'default')}
fontSize={get(preferences, 'font.codeFontSize')}
/> />
</div> </div>

View File

@ -36,6 +36,7 @@ const Tests = ({ collection }) => {
mode="javascript" mode="javascript"
onSave={handleSave} onSave={handleSave}
font={get(preferences, 'font.codeFont', 'default')} font={get(preferences, 'font.codeFont', 'default')}
fontSize={get(preferences, 'font.codeFontSize')}
/> />
<div className="mt-6"> <div className="mt-6">

View File

@ -47,6 +47,7 @@ const Documentation = ({ item, collection }) => {
collection={collection} collection={collection}
theme={displayedTheme} theme={displayedTheme}
font={get(preferences, 'font.codeFont', 'default')} font={get(preferences, 'font.codeFont', 'default')}
fontSize={get(preferences, 'font.codeFontSize')}
value={docs || ''} value={docs || ''}
onEdit={onEdit} onEdit={onEdit}
onSave={onSave} onSave={onSave}

View File

@ -54,6 +54,7 @@ const Script = ({ collection, folder }) => {
mode="javascript" mode="javascript"
onSave={handleSave} onSave={handleSave}
font={get(preferences, 'font.codeFont', 'default')} font={get(preferences, 'font.codeFont', 'default')}
fontSize={get(preferences, 'font.codeFontSize')}
/> />
</div> </div>
<div className="flex flex-col flex-1 mt-2 gap-y-2"> <div className="flex flex-col flex-1 mt-2 gap-y-2">
@ -66,6 +67,7 @@ const Script = ({ collection, folder }) => {
mode="javascript" mode="javascript"
onSave={handleSave} onSave={handleSave}
font={get(preferences, 'font.codeFont', 'default')} font={get(preferences, 'font.codeFont', 'default')}
fontSize={get(preferences, 'font.codeFontSize')}
/> />
</div> </div>

View File

@ -37,6 +37,7 @@ const Tests = ({ collection, folder }) => {
mode="javascript" mode="javascript"
onSave={handleSave} onSave={handleSave}
font={get(preferences, 'font.codeFont', 'default')} font={get(preferences, 'font.codeFont', 'default')}
fontSize={get(preferences, 'font.codeFontSize')}
/> />
<div className="mt-6"> <div className="mt-6">

View File

@ -9,17 +9,25 @@ const Font = ({ close }) => {
const preferences = useSelector((state) => state.app.preferences); const preferences = useSelector((state) => state.app.preferences);
const [codeFont, setCodeFont] = useState(get(preferences, 'font.codeFont', 'default')); const [codeFont, setCodeFont] = useState(get(preferences, 'font.codeFont', 'default'));
const [codeFontSize, setCodeFontSize] = useState(get(preferences, 'font.codeFontSize', '14'));
const handleInputChange = (event) => { const handleCodeFontChange = (event) => {
setCodeFont(event.target.value); setCodeFont(event.target.value);
}; };
const handleCodeFontSizeChange = (event) => {
// Restrict to min/max value
const clampedSize = Math.max(1, Math.min(event.target.value, 32));
setCodeFontSize(clampedSize);
};
const handleSave = () => { const handleSave = () => {
dispatch( dispatch(
savePreferences({ savePreferences({
...preferences, ...preferences,
font: { font: {
codeFont codeFont,
codeFontSize
} }
}) })
).then(() => { ).then(() => {
@ -29,17 +37,33 @@ const Font = ({ close }) => {
return ( return (
<StyledWrapper> <StyledWrapper>
<label className="block font-medium">Code Editor Font</label> <div className="flex flex-row gap-2 w-full">
<input <div className="w-4/5">
type="text" <label className="block font-medium">Code Editor Font</label>
className="block textbox mt-2 w-full" <input
autoComplete="off" type="text"
autoCorrect="off" className="block textbox mt-2 w-full"
autoCapitalize="off" autoComplete="off"
spellCheck="false" autoCorrect="off"
onChange={handleInputChange} autoCapitalize="off"
defaultValue={codeFont} spellCheck="false"
/> onChange={handleCodeFontChange}
defaultValue={codeFont}
/>
</div>
<div className="w-1/5">
<label className="block font-medium">Font Size</label>
<input
type="number"
className="block textbox mt-2 w-full"
autoComplete="off"
autoCorrect="off"
inputMode="numeric"
onChange={handleCodeFontSizeChange}
defaultValue={codeFontSize}
/>
</div>
</div>
<div className="mt-10"> <div className="mt-10">
<button type="submit" className="submit btn btn-sm btn-secondary" onClick={handleSave}> <button type="submit" className="submit btn btn-sm btn-secondary" onClick={handleSave}>

View File

@ -31,6 +31,7 @@ const GraphQLRequestPane = ({ item, collection, leftPaneWidth, onSchemaLoad, tog
: get(item, 'request.body.graphql.variables'); : get(item, 'request.body.graphql.variables');
const { displayedTheme } = useTheme(); const { displayedTheme } = useTheme();
const [schema, setSchema] = useState(null); const [schema, setSchema] = useState(null);
const preferences = useSelector((state) => state.app.preferences);
useEffect(() => { useEffect(() => {
onSchemaLoad(schema); onSchemaLoad(schema);
@ -71,6 +72,8 @@ const GraphQLRequestPane = ({ item, collection, leftPaneWidth, onSchemaLoad, tog
onRun={onRun} onRun={onRun}
onEdit={onQueryChange} onEdit={onQueryChange}
onClickReference={handleGqlClickReference} onClickReference={handleGqlClickReference}
font={get(preferences, 'font.codeFont', 'default')}
fontSize={get(preferences, 'font.codeFontSize')}
/> />
); );
} }

View File

@ -33,6 +33,7 @@ const GraphQLVariables = ({ variables, item, collection }) => {
value={variables || ''} value={variables || ''}
theme={displayedTheme} theme={displayedTheme}
font={get(preferences, 'font.codeFont', 'default')} font={get(preferences, 'font.codeFont', 'default')}
fontSize={get(preferences, 'font.codeFontSize')}
onEdit={onEdit} onEdit={onEdit}
mode="javascript" mode="javascript"
onRun={onRun} onRun={onRun}

View File

@ -4,6 +4,8 @@ const StyledWrapper = styled.div`
div.CodeMirror { div.CodeMirror {
background: ${(props) => props.theme.codemirror.bg}; background: ${(props) => props.theme.codemirror.bg};
border: solid 1px ${(props) => props.theme.codemirror.border}; border: solid 1px ${(props) => props.theme.codemirror.border};
font-family: ${(props) => (props.font ? props.font : 'default')};
font-size: ${(props) => (props.fontSize ? `${props.fontSize}px` : 'inherit')};
flex: 1 1 0; flex: 1 1 0;
} }

View File

@ -211,6 +211,8 @@ export default class QueryEditor extends React.Component {
<StyledWrapper <StyledWrapper
className="h-full w-full flex flex-col relative" className="h-full w-full flex flex-col relative"
aria-label="Query Editor" aria-label="Query Editor"
font={this.props.font}
fontSize={this.props.fontSize}
ref={(node) => { ref={(node) => {
this._node = node; this._node = node;
}} }}

View File

@ -50,6 +50,7 @@ const RequestBody = ({ item, collection }) => {
collection={collection} collection={collection}
theme={displayedTheme} theme={displayedTheme}
font={get(preferences, 'font.codeFont', 'default')} font={get(preferences, 'font.codeFont', 'default')}
fontSize={get(preferences, 'font.codeFontSize')}
value={bodyContent[bodyMode] || ''} value={bodyContent[bodyMode] || ''}
onEdit={onEdit} onEdit={onEdit}
onRun={onRun} onRun={onRun}

View File

@ -47,6 +47,7 @@ const Script = ({ item, collection }) => {
value={requestScript || ''} value={requestScript || ''}
theme={displayedTheme} theme={displayedTheme}
font={get(preferences, 'font.codeFont', 'default')} font={get(preferences, 'font.codeFont', 'default')}
fontSize={get(preferences, 'font.codeFontSize')}
onEdit={onRequestScriptEdit} onEdit={onRequestScriptEdit}
mode="javascript" mode="javascript"
onRun={onRun} onRun={onRun}
@ -60,6 +61,7 @@ const Script = ({ item, collection }) => {
value={responseScript || ''} value={responseScript || ''}
theme={displayedTheme} theme={displayedTheme}
font={get(preferences, 'font.codeFont', 'default')} font={get(preferences, 'font.codeFont', 'default')}
fontSize={get(preferences, 'font.codeFontSize')}
onEdit={onResponseScriptEdit} onEdit={onResponseScriptEdit}
mode="javascript" mode="javascript"
onRun={onRun} onRun={onRun}

View File

@ -34,6 +34,7 @@ const Tests = ({ item, collection }) => {
value={tests || ''} value={tests || ''}
theme={displayedTheme} theme={displayedTheme}
font={get(preferences, 'font.codeFont', 'default')} font={get(preferences, 'font.codeFont', 'default')}
fontSize={get(preferences, 'font.codeFontSize')}
onEdit={onEdit} onEdit={onEdit}
mode="javascript" mode="javascript"
onRun={onRun} onRun={onRun}

View File

@ -81,6 +81,7 @@ const QueryResultPreview = ({
<CodeEditor <CodeEditor
collection={collection} collection={collection}
font={get(preferences, 'font.codeFont', 'default')} font={get(preferences, 'font.codeFont', 'default')}
fontSize={get(preferences, 'font.codeFontSize')}
theme={displayedTheme} theme={displayedTheme}
onRun={onRun} onRun={onRun}
value={formattedData} value={formattedData}

View File

@ -53,6 +53,7 @@ const CodeView = ({ language, item }) => {
collection={collection} collection={collection}
value={snippet} value={snippet}
font={get(preferences, 'font.codeFont', 'default')} font={get(preferences, 'font.codeFont', 'default')}
fontSize={get(preferences, 'font.codeFontSize')}
theme={displayedTheme} theme={displayedTheme}
mode={lang} mode={lang}
/> />

View File

@ -23,7 +23,8 @@ const defaultPreferences = {
timeout: 0 timeout: 0
}, },
font: { font: {
codeFont: 'default' codeFont: 'default',
codeFontSize: 14
}, },
proxy: { proxy: {
enabled: false, enabled: false,
@ -54,7 +55,8 @@ const preferencesSchema = Yup.object().shape({
timeout: Yup.number() timeout: Yup.number()
}), }),
font: Yup.object().shape({ font: Yup.object().shape({
codeFont: Yup.string().nullable() codeFont: Yup.string().nullable(),
codeFontSize: Yup.number().min(1).max(32).nullable()
}), }),
proxy: Yup.object({ proxy: Yup.object({
enabled: Yup.boolean(), enabled: Yup.boolean(),