Skip to content

Commit ee635f0

Browse files
authored
Merge pull request #51 from magjac/user-configuration-of-text-editor
User configuration of text editor
2 parents c26e83b + ec4dc03 commit ee635f0

File tree

3 files changed

+84
-4
lines changed

3 files changed

+84
-4
lines changed

src/SettingsDialog.js

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,14 @@ const styles = theme => ({
4545
justifyContent: 'space-between',
4646
},
4747
holdOffInput: {
48-
width: '7em',
49-
}
48+
width: '7.6em',
49+
},
50+
fontSizeInput: {
51+
width: '5em',
52+
},
53+
tabSizeInput: {
54+
width: '7.1em',
55+
},
5056
});
5157

5258
class SettingsDialog extends React.Component {
@@ -67,6 +73,14 @@ class SettingsDialog extends React.Component {
6773
this.props.onHoldOffChange(event.target.value);
6874
};
6975

76+
handleFontSizeChange = (event) => {
77+
this.props.onFontSizeChange(event.target.value);
78+
};
79+
80+
handleTabSizeChange = (event) => {
81+
this.props.onTabSizeChange(event.target.value);
82+
};
83+
7084
render() {
7185
const { classes } = this.props;
7286
return (
@@ -127,13 +141,57 @@ class SettingsDialog extends React.Component {
127141
/>
128142
</FormGroup>
129143
</DialogContent>
130-
<DialogTitle id="form-dialog-title">Other</DialogTitle>
144+
<DialogTitle id="form-dialog-title">Text Editor</DialogTitle>
145+
<DialogContent classes={{root: classes.root}}>
146+
<FormControl
147+
className={classes.formControl}
148+
aria-describedby="font-size-helper-text"
149+
>
150+
<InputLabel shrink={true}>Font size</InputLabel>
151+
<Input
152+
className={classes.fontSizeInput}
153+
id="font-size"
154+
type="number"
155+
value={this.props.fontSize}
156+
onChange={this.handleFontSizeChange}
157+
endAdornment={<InputAdornment position="end"> px</InputAdornment>}
158+
inputProps={{
159+
'aria-label': 'FontSize',
160+
min: 1,
161+
max: 99,
162+
step: 1,
163+
}}
164+
/>
165+
</FormControl>
166+
</DialogContent>
167+
<DialogContent classes={{root: classes.root}}>
168+
<FormControl
169+
className={classes.formControl}
170+
aria-describedby="tab-size-helper-text"
171+
>
172+
<InputLabel shrink={true}>Tab size</InputLabel>
173+
<Input
174+
className={classes.tabSizeInput}
175+
id="tab-size"
176+
type="number"
177+
value={this.props.tabSize}
178+
onChange={this.handleTabSizeChange}
179+
endAdornment={<InputAdornment position="end"> spaces</InputAdornment>}
180+
inputProps={{
181+
'aria-label': 'TabSize',
182+
min: 1,
183+
max: 99,
184+
step: 1,
185+
}}
186+
/>
187+
</FormControl>
188+
</DialogContent>
131189
<DialogContent classes={{root: classes.root}}>
132190
<FormControl
133191
className={classes.formControl}
134192
aria-describedby="holdoff-helper-text"
135193
>
136-
<InputLabel shrink={true}>Editor hold-off time</InputLabel>
194+
<InputLabel shrink={true}>Hold-off time</InputLabel>
137195
<Input
138196
className={classes.holdOffInput}
139197
id="holdoff"

src/TextEditor.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ class TextEditor extends React.Component {
9898
<AceEditor
9999
mode="dot"
100100
theme="github"
101+
fontSize={this.props.fontSize + 'px'}
102+
tabSize={this.props.tabSize}
101103
onChange={this.handleChange}
102104
onBeforeLoad={this.handleBeforeLoad}
103105
onLoad={this.handleLoad}

src/pages/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class Index extends React.Component {
5959
defaultEdgeAttributes: JSON.parse(localStorage.getItem('defaultEdgeAttributes')) || {},
6060
error: null,
6161
holdOff: localStorage.getItem('holdOff') || 0.2,
62+
fontSize: localStorage.getItem('fontSize') || 12,
63+
tabSize: localStorage.getItem('tabSize') || 4,
6264
selectedGraphComponents: [],
6365
};
6466
}
@@ -184,6 +186,18 @@ class Index extends React.Component {
184186
});
185187
}
186188

189+
handleFontSizeChange = (fontSize) => {
190+
this.setPersistentState({
191+
fontSize: fontSize,
192+
});
193+
}
194+
195+
handleTabSizeChange = (tabSize) => {
196+
this.setPersistentState({
197+
tabSize: tabSize,
198+
});
199+
}
200+
187201
handleNodeShapeClick = (shape) => {
188202
let x0 = null;
189203
let y0 = null;
@@ -389,6 +403,10 @@ class Index extends React.Component {
389403
onFitGraphSwitchChange={this.handleFitGraphSwitchChange}
390404
holdOff={this.state.holdOff}
391405
onHoldOffChange={this.handleHoldOffChange}
406+
fontSize={this.state.fontSize}
407+
onFontSizeChange={this.handleFontSizeChange}
408+
tabSize={this.state.tabSize}
409+
onTabSizeChange={this.handleTabSizeChange}
392410
onSettingsClose={this.handleSettingsClose}
393411
/>
394412
<Grid container
@@ -428,6 +446,8 @@ class Index extends React.Component {
428446
error={this.state.error}
429447
selectedGraphComponents={this.state.selectedGraphComponents}
430448
holdOff={this.state.holdOff}
449+
fontSize={this.state.fontSize}
450+
tabSize={this.state.tabSize}
431451
registerUndo={this.registerUndo}
432452
registerRedo={this.registerRedo}
433453
/>

0 commit comments

Comments
 (0)