Skip to content

Commit ecefaa8

Browse files
committed
Add Cmd+Shift+F astidy code shortcut and prevent browser default behaviour
1 parent 06396bd commit ecefaa8

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

client/modules/IDE/components/Editor.jsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ const beautifyHTML = beautifyJS.html;
6262
window.JSHINT = JSHINT;
6363
window.CSSLint = CSSLint;
6464
window.HTMLHint = HTMLHint;
65-
delete CodeMirror.keyMap.sublime['Shift-Tab'];
65+
66+
67+
// delete CodeMirror.keyMap.sublime['Shift-Cmd-F'];
68+
69+
console.log(CodeMirror.keyMap.sublime);
6670

6771
const IS_TAB_INDENT = false;
6872
const INDENTATION_AMOUNT = 2;
@@ -88,6 +92,7 @@ class Editor extends React.Component {
8892
this.findPrev = this.findPrev.bind(this);
8993
this.showReplace = this.showReplace.bind(this);
9094
this.getContent = this.getContent.bind(this);
95+
this.handleKey = this.handleKey.bind(this);
9196
}
9297

9398
componentDidMount() {
@@ -155,14 +160,21 @@ class Editor extends React.Component {
155160
}
156161
}, 1000));
157162

158-
this._cm.on('keyup', () => {
163+
this.map = {};
164+
165+
this._cm.on('keyup', (_cm, e) => {
159166
const temp = this.props.t('Editor.KeyUpLineNumber', { lineNumber: parseInt((this._cm.getCursor().line) + 1, 10) });
160167
document.getElementById('current-line').innerHTML = temp;
168+
this.handleKey(this.map, e);
161169
});
162170

163171
this._cm.on('keydown', (_cm, e) => {
164-
// 9 === Tab
165-
if (e.keyCode === 9 && e.shiftKey) {
172+
this.handleKey(this.map, e);
173+
// 91 === Cmd
174+
// 16 === Shift
175+
// 70 === f
176+
if (this.map[91] && this.map[16] && this.map[70]) {
177+
e.preventDefault(); // prevent browser's default behaviour
166178
this.tidyCode();
167179
}
168180
});
@@ -192,7 +204,7 @@ class Editor extends React.Component {
192204

193205
componentDidUpdate(prevProps) {
194206
if (this.props.file.content !== prevProps.file.content &&
195-
this.props.file.content !== this._cm.getValue()) {
207+
this.props.file.content !== this._cm.getValue()) {
196208
const oldDoc = this._cm.swapDoc(this._docs[this.props.file.id]);
197209
this._docs[prevProps.file.id] = oldDoc;
198210
this._cm.focus();
@@ -327,6 +339,10 @@ class Editor extends React.Component {
327339
}
328340
}
329341

342+
handleKey(map, e) { // update the state of each key pressed and released
343+
map[e.keyCode] = e.type === 'keydown';
344+
}
345+
330346
render() {
331347
const editorSectionClass = classNames({
332348
'editor': true,

0 commit comments

Comments
 (0)