Skip to content

Commit

Permalink
use editor.on change to get modified text in the editor
Browse files Browse the repository at this point in the history
  • Loading branch information
nightwing committed Apr 7, 2012
1 parent 436948d commit f683cfd
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/coffee-console.html
@@ -1,8 +1,8 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<meta charset="UTF-8">
<title></title>
<script src="jquery-1.7.1.min.js"></script>
<script src="coffee-script.js"></script>
<style>
Expand All @@ -20,7 +20,7 @@
top: 0;
bottom: 0;
right: 0;
left: 50%;
left: 50%;
}
#runcc {
position: fixed;
Expand All @@ -44,23 +44,31 @@

var editor = ace.edit("cc-editor");
editor.setTheme("ace/theme/twilight");
editor.getSession().setMode("ace/mode/coffee");
editor.session.setMode("ace/mode/coffee");
editor.setShowPrintMargin(false);

var compiled = ace.edit("cc-results");
compiled.setTheme("ace/theme/twilight");
compiled.getSession().setMode("ace/mode/javascript");
compiled.session.setMode("ace/mode/javascript");
compiled.setShowPrintMargin(false);

$(document.body).keydown(function(e){
var compiledSource = CoffeeScript.compile( editor.getSession().getValue(), {bare:true});
compiled.getSession().setValue(compiledSource);

if (e.which == 13 && (e.metaKey || e.shiftKey)) {
e.preventDefault();
compileIt();
}
schedule = function(fn, timeout) {
if (fn.$timer) return;
fn.$timer = setTimeout(function() {fn.$timer = null; fn()}, timeout || 10);
}
editor.on("change", function(e){
schedule(update, 20);
})
function update(){
var compiledSource = CoffeeScript.compile( editor.session.getValue(), {bare:true});
compiled.session.setValue(compiledSource);
}
editor.commands.addCommand({
name: "compileIt",
exec: compileIt,
bindKey: "Ctrl-Return|Command-Return|Shift-Return"
})

$('#runcc').click(compileIt);
function compileIt(){
chrome.devtools.inspectedWindow.eval( compiled.getSession().getValue(), function(result, isException) { });
Expand Down

0 comments on commit f683cfd

Please sign in to comment.