Skip to content

Commit

Permalink
Use the Ace editor and its autocomplete feature
Browse files Browse the repository at this point in the history
Fixes #49
  • Loading branch information
mrjoelkemp committed Mar 21, 2015
1 parent c0cf089 commit 80559c3
Show file tree
Hide file tree
Showing 322 changed files with 457 additions and 403 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ node_js:
- "0.10"

notifications:
email: false
email: false

sudo: false
2 changes: 1 addition & 1 deletion css/styles.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions css/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ body {
width: 100% - $sidebar-width - 1%;
display: inline-block;
#editor {
font-size: 17px;
font-size: 15px;
border: 1px solid black;
margin-bottom: 5px;
height: 450px;
height: 600px;
.CodeMirror {
min-height: 450px;
}
Expand Down
47 changes: 22 additions & 25 deletions dist/phpepl.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,26 @@ module.exports = Console;

},{}],2:[function(require,module,exports){
var SessionStore = require('./sessionstore');

/**
* A code editor wrapper around Codemirror
* A code editor wrapper around the client-side text editor
*
* @param {$} $element - Dom element the editor should bind to
* @returns {CodeMirror}
* @param {String} selector - Dom element the editor should bind to
*/
function Editor($element) {
this.$element = $element;

this._editor = window.CodeMirror(this.$element.get(0), {
lineNumbers: true,
matchBrackets: true,
mode: 'text/x-php',
indentUnit: 2,
tabSize: 2,
autofocus: true,
autoCloseBrackets: true
function Editor(selector) {
this.$element = $('#' + selector);

this._editor = window.ace.edit(selector);
this._editor.getSession().setMode({path: 'ace/mode/php', inline: true});
this._editor.getSession().setUseSoftTabs(true);
this._editor.getSession().setTabSize(2);

this._editor.$blockScrolling = Infinity;
this._editor.setShowPrintMargin(false);
this._editor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: false
});

this._sessionStore = new SessionStore();
Expand Down Expand Up @@ -98,19 +101,13 @@ Editor.prototype.setValue = function(val) {
* @param {Number} line
*/
Editor.prototype.showLineError = function(line) {
// Find the dom element in the gutter
this.$element.find('.CodeMirror-linenumber').each(function() {
// If the cell's line number matches the error line
if (Number($(this).html()) === line) {
// Make the background red
$(this).addClass('error-gutter');
return;
}
});
this.$element
.find('.ace_gutter-cell:nth-child(' + line + ')')
.addClass('error-gutter');
};

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

Editor.prototype.saveSession = function() {
Expand Down Expand Up @@ -285,7 +282,7 @@ var getQueryParams = require('./lib/getQueryParams');
var timestamp = require('./lib/timestamp');
var utils = require('./lib/utils');

var editor = new Editor($('#editor'));
var editor = new Editor('editor');
var console = new Console($('.console'));
var sidebar = new Sidebar($('.sidebar'));

Expand Down
13 changes: 9 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
<link rel="shortcut icon" href="/favicon.ico?316280cb6879b222" type="image/x-icon">
<link rel="icon" href="/favicon.ico?316280cb6879b222" type="image/x-icon">

<link href='js/vendor/codemirror/lib/codemirror.css?69882100f431f700' rel='stylesheet'>
<link href='css/styles.css?7781a720541bbc70' rel='stylesheet'>
<link href='css/styles.css?2a3d32a4457212ce' rel='stylesheet'>
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-36055599-1']);
Expand Down Expand Up @@ -79,6 +78,10 @@
or
<span class='shortcut'>Ctrl + Shift + Down</span>
</span>
<span class='code'>
Autocomplete:
<span class='shortcut'>Ctrl + Space</span>
</span>
</div>
<div class="share-code">
<span>Share your code:</span>
Expand Down Expand Up @@ -127,7 +130,9 @@
</body>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>

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

<script src='dist/phpepl.js?f7372bc0bcf9ca25'></script>
<script src='dist/phpepl.js?c11e19b19c5457fb'></script>
</html>
45 changes: 21 additions & 24 deletions js/editor.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
var SessionStore = require('./sessionstore');

/**
* A code editor wrapper around Codemirror
* A code editor wrapper around the client-side text editor
*
* @param {$} $element - Dom element the editor should bind to
* @returns {CodeMirror}
* @param {String} selector - Dom element the editor should bind to
*/
function Editor($element) {
this.$element = $element;

this._editor = window.CodeMirror(this.$element.get(0), {
lineNumbers: true,
matchBrackets: true,
mode: 'text/x-php',
indentUnit: 2,
tabSize: 2,
autofocus: true,
autoCloseBrackets: true
function Editor(selector) {
this.$element = $('#' + selector);

this._editor = window.ace.edit(selector);
this._editor.getSession().setMode({path: 'ace/mode/php', inline: true});
this._editor.getSession().setUseSoftTabs(true);
this._editor.getSession().setTabSize(2);

this._editor.$blockScrolling = Infinity;
this._editor.setShowPrintMargin(false);
this._editor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: false
});

this._sessionStore = new SessionStore();
Expand Down Expand Up @@ -43,19 +46,13 @@ Editor.prototype.setValue = function(val) {
* @param {Number} line
*/
Editor.prototype.showLineError = function(line) {
// Find the dom element in the gutter
this.$element.find('.CodeMirror-linenumber').each(function() {
// If the cell's line number matches the error line
if (Number($(this).html()) === line) {
// Make the background red
$(this).addClass('error-gutter');
return;
}
});
this.$element
.find('.ace_gutter-cell:nth-child(' + line + ')')
.addClass('error-gutter');
};

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

Editor.prototype.saveSession = function() {
Expand Down
2 changes: 1 addition & 1 deletion js/phpepl.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var getQueryParams = require('./lib/getQueryParams');
var timestamp = require('./lib/timestamp');
var utils = require('./lib/utils');

var editor = new Editor($('#editor'));
var editor = new Editor('editor');
var console = new Console($('.console'));
var sidebar = new Sidebar($('.sidebar'));

Expand Down
11 changes: 11 additions & 0 deletions js/vendor/ace/ace.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions js/vendor/ace/ext-beautify.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 80559c3

Please sign in to comment.