Skip to content

Commit e0f9f1b

Browse files
authored
Merge pull request #1623 from sagar-joshi/feature/autoclose-brackets-quotes
Feature/autoclose brackets quotes
2 parents 16bbeda + e463743 commit e0f9f1b

File tree

9 files changed

+71
-3
lines changed

9 files changed

+71
-3
lines changed

Diff for: client/constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export const SET_PREFERENCES = 'SET_PREFERENCES';
7474
export const SET_TEXT_OUTPUT = 'SET_TEXT_OUTPUT';
7575
export const SET_GRID_OUTPUT = 'SET_GRID_OUTPUT';
7676
export const SET_SOUND_OUTPUT = 'SET_SOUND_OUTPUT';
77+
export const SET_AUTOCLOSE_BRACKETS_QUOTES = 'SET_AUTOCLOSE_BRACKETS_QUOTES';
7778

7879
export const OPEN_PROJECT_OPTIONS = 'OPEN_PROJECT_OPTIONS';
7980
export const CLOSE_PROJECT_OPTIONS = 'CLOSE_PROJECT_OPTIONS';

Diff for: client/modules/IDE/actions/preferences.js

+18
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ export function setLineNumbers(value) {
5151
};
5252
}
5353

54+
export function setAutocloseBracketsQuotes(value) {
55+
return (dispatch, getState) => {
56+
dispatch({
57+
type: ActionTypes.SET_AUTOCLOSE_BRACKETS_QUOTES,
58+
value
59+
});
60+
const state = getState();
61+
if (state.user.authenticated) {
62+
const formParams = {
63+
preferences: {
64+
autocloseBracketsQuotes: value
65+
}
66+
};
67+
updatePreferences(formParams, dispatch);
68+
}
69+
};
70+
}
71+
5472
export function setAutosave(value) {
5573
return (dispatch, getState) => {
5674
dispatch({

Diff for: client/modules/IDE/components/Editor.jsx

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import 'codemirror/addon/search/matchesonscrollbar';
2121
import 'codemirror/addon/search/match-highlighter';
2222
import 'codemirror/addon/search/jump-to-line';
2323
import 'codemirror/addon/edit/matchbrackets';
24+
import 'codemirror/addon/edit/closebrackets';
2425

2526
import { JSHINT } from 'jshint';
2627
import { CSSLint } from 'csslint';
@@ -104,6 +105,7 @@ class Editor extends React.Component {
104105
keyMap: 'sublime',
105106
highlightSelectionMatches: true, // highlight current search match
106107
matchBrackets: true,
108+
autoCloseBrackets: this.props.autocloseBracketsQuotes,
107109
lint: {
108110
onUpdateLinting: ((annotations) => {
109111
this.props.hideRuntimeErrorWarning();
@@ -206,6 +208,9 @@ class Editor extends React.Component {
206208
if (this.props.lineNumbers !== prevProps.lineNumbers) {
207209
this._cm.setOption('lineNumbers', this.props.lineNumbers);
208210
}
211+
if (this.props.autocloseBracketsQuotes !== prevProps.autocloseBracketsQuotes) {
212+
this._cm.setOption('autoCloseBrackets', this.props.autocloseBracketsQuotes);
213+
}
209214

210215
if (prevProps.consoleEvents !== this.props.consoleEvents) {
211216
this.props.showRuntimeErrorWarning();
@@ -371,6 +376,7 @@ class Editor extends React.Component {
371376
}
372377

373378
Editor.propTypes = {
379+
autocloseBracketsQuotes: PropTypes.bool.isRequired,
374380
lineNumbers: PropTypes.bool.isRequired,
375381
lintWarning: PropTypes.bool.isRequired,
376382
linewrap: PropTypes.bool.isRequired,

Diff for: client/modules/IDE/components/Preferences/index.jsx

+29
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,33 @@ class Preferences extends React.Component {
202202
<label htmlFor="autosave-off" className="preference__option">{this.props.t('Preferences.Off')}</label>
203203
</div>
204204
</div>
205+
<div className="preference">
206+
<h4 className="preference__title">{this.props.t('Preferences.AutocloseBracketsQuotes')}</h4>
207+
<div className="preference__options">
208+
<input
209+
type="radio"
210+
onChange={() => this.props.setAutocloseBracketsQuotes(true)}
211+
aria-label={this.props.t('Preferences.AutocloseBracketsQuotesOnARIA')}
212+
name="autoclosebracketsquotes"
213+
id="autoclosebracketsquotes-on"
214+
className="preference__radio-button"
215+
value="On"
216+
checked={this.props.autocloseBracketsQuotes}
217+
/>
218+
<label htmlFor="autoclosebracketsquotes-on" className="preference__option">{this.props.t('Preferences.On')}</label>
219+
<input
220+
type="radio"
221+
onChange={() => this.props.setAutocloseBracketsQuotes(false)}
222+
aria-label={this.props.t('Preferences.AutocloseBracketsQuotesOffARIA')}
223+
name="autoclosebracketsquotes"
224+
id="autoclosebracketsquotes-off"
225+
className="preference__radio-button"
226+
value="Off"
227+
checked={!this.props.autocloseBracketsQuotes}
228+
/>
229+
<label htmlFor="autoclosebracketsquotes-off" className="preference__option">{this.props.t('Preferences.Off')}</label>
230+
</div>
231+
</div>
205232
<div className="preference">
206233
<h4 className="preference__title">{this.props.t('Preferences.WordWrap')}</h4>
207234
<div className="preference__options">
@@ -361,6 +388,8 @@ Preferences.propTypes = {
361388
setLintWarning: PropTypes.func.isRequired,
362389
theme: PropTypes.string.isRequired,
363390
setTheme: PropTypes.func.isRequired,
391+
autocloseBracketsQuotes: PropTypes.bool.isRequired,
392+
setAutocloseBracketsQuotes: PropTypes.func.isRequired,
364393
t: PropTypes.func.isRequired,
365394
};
366395

Diff for: client/modules/IDE/pages/IDEView.jsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ class IDEView extends React.Component {
286286
setSoundOutput={this.props.setSoundOutput}
287287
theme={this.props.preferences.theme}
288288
setTheme={this.props.setTheme}
289+
autocloseBracketsQuotes={this.props.preferences.autocloseBracketsQuotes}
290+
setAutocloseBracketsQuotes={this.props.setAutocloseBracketsQuotes}
289291
/>
290292
</Overlay>
291293
)}
@@ -534,9 +536,11 @@ IDEView.propTypes = {
534536
soundOutput: PropTypes.bool.isRequired,
535537
theme: PropTypes.string.isRequired,
536538
autorefresh: PropTypes.bool.isRequired,
537-
language: PropTypes.string.isRequired
539+
language: PropTypes.string.isRequired,
540+
autocloseBracketsQuotes: PropTypes.bool.isRequired
538541
}).isRequired,
539542
closePreferences: PropTypes.func.isRequired,
543+
setAutocloseBracketsQuotes: PropTypes.func.isRequired,
540544
setFontSize: PropTypes.func.isRequired,
541545
setAutosave: PropTypes.func.isRequired,
542546
setLineNumbers: PropTypes.func.isRequired,

Diff for: client/modules/IDE/reducers/preferences.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const initialState = {
1212
soundOutput: false,
1313
theme: 'light',
1414
autorefresh: false,
15-
language: 'en-US'
15+
language: 'en-US',
16+
autocloseBracketsQuotes: true
1617
};
1718

1819
const preferences = (state = initialState, action) => {
@@ -41,6 +42,8 @@ const preferences = (state = initialState, action) => {
4142
return Object.assign({}, state, { lineNumbers: action.value });
4243
case ActionTypes.SET_LANGUAGE:
4344
return Object.assign({}, state, { language: action.language });
45+
case ActionTypes.SET_AUTOCLOSE_BRACKETS_QUOTES:
46+
return Object.assign({}, state, { autocloseBracketsQuotes: action.value });
4447
default:
4548
return state;
4649
}

Diff for: server/models/user.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ const userSchema = new Schema({
6767
soundOutput: { type: Boolean, default: false },
6868
theme: { type: String, default: 'light' },
6969
autorefresh: { type: Boolean, default: false },
70-
language: { type: String, default: 'en-US' }
70+
language: { type: String, default: 'en-US' },
71+
autocloseBracketsQuotes: { type: Boolean, default: true }
7172
},
7273
totalSize: { type: Number, default: 0 }
7374
}, { timestamps: true, usePushEach: true });

Diff for: translations/locales/en-US/translations.json

+3
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@
133133
"AutosaveOnARIA": "autosave on",
134134
"Off": "Off",
135135
"AutosaveOffARIA": "autosave off",
136+
"AutocloseBracketsQuotes": "Autoclose Brackets and Quotes",
137+
"AutocloseBracketsQuotesOnARIA": "autoclose brackets and quotes on",
138+
"AutocloseBracketsQuotesOffARIA": "autoclose brackets and quotes off",
136139
"WordWrap": "Word Wrap",
137140
"LineWrapOnARIA": "linewrap on",
138141
"LineWrapOffARIA": "linewrap off",

Diff for: translations/locales/es-419/translations.json

+3
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@
131131
"Autosave": "Grabar automáticamente",
132132
"On": "Activar",
133133
"AutosaveOnARIA": "Grabado automático activado",
134+
"AutocloseBracketsQuotes": "Cerrar automáticamente llaves y comillas",
135+
"AutocloseBracketsQuotesOnARIA": "Activar cierre automático de llaves y comillas",
136+
"AutocloseBracketsQuotesOffARIA": "Desactivar cierre automático de llaves y comillas",
134137
"Off": "Desactivar",
135138
"AutosaveOffARIA": "Grabado automático desactivado",
136139
"WordWrap": "Ajuste automático de línea",

0 commit comments

Comments
 (0)