Skip to content

Commit c56de60

Browse files
committed
Merge pull request #50 from mrjoelkemp/ace_editor
Use the Ace editor and autocomplete
2 parents c0cf089 + 80559c3 commit c56de60

File tree

322 files changed

+457
-403
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

322 files changed

+457
-403
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ node_js:
33
- "0.10"
44

55
notifications:
6-
email: false
6+
email: false
7+
8+
sudo: false

css/styles.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

css/styles.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ body {
8888
width: 100% - $sidebar-width - 1%;
8989
display: inline-block;
9090
#editor {
91-
font-size: 17px;
91+
font-size: 15px;
9292
border: 1px solid black;
9393
margin-bottom: 5px;
94-
height: 450px;
94+
height: 600px;
9595
.CodeMirror {
9696
min-height: 450px;
9797
}

dist/phpepl.js

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,26 @@ module.exports = Console;
5454

5555
},{}],2:[function(require,module,exports){
5656
var SessionStore = require('./sessionstore');
57+
5758
/**
58-
* A code editor wrapper around Codemirror
59+
* A code editor wrapper around the client-side text editor
5960
*
60-
* @param {$} $element - Dom element the editor should bind to
61-
* @returns {CodeMirror}
61+
* @param {String} selector - Dom element the editor should bind to
6262
*/
63-
function Editor($element) {
64-
this.$element = $element;
65-
66-
this._editor = window.CodeMirror(this.$element.get(0), {
67-
lineNumbers: true,
68-
matchBrackets: true,
69-
mode: 'text/x-php',
70-
indentUnit: 2,
71-
tabSize: 2,
72-
autofocus: true,
73-
autoCloseBrackets: true
63+
function Editor(selector) {
64+
this.$element = $('#' + selector);
65+
66+
this._editor = window.ace.edit(selector);
67+
this._editor.getSession().setMode({path: 'ace/mode/php', inline: true});
68+
this._editor.getSession().setUseSoftTabs(true);
69+
this._editor.getSession().setTabSize(2);
70+
71+
this._editor.$blockScrolling = Infinity;
72+
this._editor.setShowPrintMargin(false);
73+
this._editor.setOptions({
74+
enableBasicAutocompletion: true,
75+
enableSnippets: true,
76+
enableLiveAutocompletion: false
7477
});
7578

7679
this._sessionStore = new SessionStore();
@@ -98,19 +101,13 @@ Editor.prototype.setValue = function(val) {
98101
* @param {Number} line
99102
*/
100103
Editor.prototype.showLineError = function(line) {
101-
// Find the dom element in the gutter
102-
this.$element.find('.CodeMirror-linenumber').each(function() {
103-
// If the cell's line number matches the error line
104-
if (Number($(this).html()) === line) {
105-
// Make the background red
106-
$(this).addClass('error-gutter');
107-
return;
108-
}
109-
});
104+
this.$element
105+
.find('.ace_gutter-cell:nth-child(' + line + ')')
106+
.addClass('error-gutter');
110107
};
111108

112109
Editor.prototype.clearLineErrors = function() {
113-
this.$element.find('.CodeMirror-linenumber').removeClass('error-gutter');
110+
this.$element.find('.ace_gutter-cell').removeClass('error-gutter');
114111
};
115112

116113
Editor.prototype.saveSession = function() {
@@ -285,7 +282,7 @@ var getQueryParams = require('./lib/getQueryParams');
285282
var timestamp = require('./lib/timestamp');
286283
var utils = require('./lib/utils');
287284

288-
var editor = new Editor($('#editor'));
285+
var editor = new Editor('editor');
289286
var console = new Console($('.console'));
290287
var sidebar = new Sidebar($('.sidebar'));
291288

index.html

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
<link rel="shortcut icon" href="/favicon.ico?316280cb6879b222" type="image/x-icon">
1313
<link rel="icon" href="/favicon.ico?316280cb6879b222" type="image/x-icon">
1414

15-
<link href='js/vendor/codemirror/lib/codemirror.css?69882100f431f700' rel='stylesheet'>
16-
<link href='css/styles.css?7781a720541bbc70' rel='stylesheet'>
15+
<link href='css/styles.css?2a3d32a4457212ce' rel='stylesheet'>
1716
<script>
1817
var _gaq = _gaq || [];
1918
_gaq.push(['_setAccount', 'UA-36055599-1']);
@@ -79,6 +78,10 @@
7978
or
8079
<span class='shortcut'>Ctrl + Shift + Down</span>
8180
</span>
81+
<span class='code'>
82+
Autocomplete:
83+
<span class='shortcut'>Ctrl + Space</span>
84+
</span>
8285
</div>
8386
<div class="share-code">
8487
<span>Share your code:</span>
@@ -127,7 +130,9 @@
127130
</body>
128131
<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
129132

130-
<script src='js/vendor/codemirror-compressed.js?af375df6c1c1d3de'></script>
133+
<script src='js/vendor/ace/ace.js?744a5852f2a9614b'></script>
134+
<script src='js/vendor/ace/ext-language_tools.js?541ef4db9ed6eff7'></script>
135+
<script src='js/vendor/ace/snippets/php.js?846bbe7ad7c1d6f6'></script>
131136

132-
<script src='dist/phpepl.js?f7372bc0bcf9ca25'></script>
137+
<script src='dist/phpepl.js?c11e19b19c5457fb'></script>
133138
</html>

js/editor.js

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
var SessionStore = require('./sessionstore');
2+
23
/**
3-
* A code editor wrapper around Codemirror
4+
* A code editor wrapper around the client-side text editor
45
*
5-
* @param {$} $element - Dom element the editor should bind to
6-
* @returns {CodeMirror}
6+
* @param {String} selector - Dom element the editor should bind to
77
*/
8-
function Editor($element) {
9-
this.$element = $element;
10-
11-
this._editor = window.CodeMirror(this.$element.get(0), {
12-
lineNumbers: true,
13-
matchBrackets: true,
14-
mode: 'text/x-php',
15-
indentUnit: 2,
16-
tabSize: 2,
17-
autofocus: true,
18-
autoCloseBrackets: true
8+
function Editor(selector) {
9+
this.$element = $('#' + selector);
10+
11+
this._editor = window.ace.edit(selector);
12+
this._editor.getSession().setMode({path: 'ace/mode/php', inline: true});
13+
this._editor.getSession().setUseSoftTabs(true);
14+
this._editor.getSession().setTabSize(2);
15+
16+
this._editor.$blockScrolling = Infinity;
17+
this._editor.setShowPrintMargin(false);
18+
this._editor.setOptions({
19+
enableBasicAutocompletion: true,
20+
enableSnippets: true,
21+
enableLiveAutocompletion: false
1922
});
2023

2124
this._sessionStore = new SessionStore();
@@ -43,19 +46,13 @@ Editor.prototype.setValue = function(val) {
4346
* @param {Number} line
4447
*/
4548
Editor.prototype.showLineError = function(line) {
46-
// Find the dom element in the gutter
47-
this.$element.find('.CodeMirror-linenumber').each(function() {
48-
// If the cell's line number matches the error line
49-
if (Number($(this).html()) === line) {
50-
// Make the background red
51-
$(this).addClass('error-gutter');
52-
return;
53-
}
54-
});
49+
this.$element
50+
.find('.ace_gutter-cell:nth-child(' + line + ')')
51+
.addClass('error-gutter');
5552
};
5653

5754
Editor.prototype.clearLineErrors = function() {
58-
this.$element.find('.CodeMirror-linenumber').removeClass('error-gutter');
55+
this.$element.find('.ace_gutter-cell').removeClass('error-gutter');
5956
};
6057

6158
Editor.prototype.saveSession = function() {

js/phpepl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var getQueryParams = require('./lib/getQueryParams');
99
var timestamp = require('./lib/timestamp');
1010
var utils = require('./lib/utils');
1111

12-
var editor = new Editor($('#editor'));
12+
var editor = new Editor('editor');
1313
var console = new Console($('.console'));
1414
var sidebar = new Sidebar($('.sidebar'));
1515

js/vendor/ace/ace.js

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/vendor/ace/ext-beautify.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)