Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: experimental/webtry/res/js/webtry.js

Issue 261693003: Use CodeMirror for WebTry snippets. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: design.md notes Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « experimental/webtry/res/js/cm/codemirror.js ('k') | experimental/webtry/templates/content.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/webtry/res/js/webtry.js
diff --git a/experimental/webtry/js/webtry.js b/experimental/webtry/res/js/webtry.js
similarity index 92%
rename from experimental/webtry/js/webtry.js
rename to experimental/webtry/res/js/webtry.js
index aafadf3b67bb4165ebb948558db2acdb953e99d1..7dfd756a9bb5f77545d5b2963ec7f0e447f8b4c8 100644
--- a/experimental/webtry/js/webtry.js
+++ b/experimental/webtry/res/js/webtry.js
@@ -128,6 +128,23 @@
var parser = new DOMParser();
var tryTemplate = document.getElementById('tryTemplate');
+ var editor = CodeMirror.fromTextArea(code, {
+ theme: "ambiance",
+ lineNumbers: true,
+ matchBrackets: true,
+ mode: "text/x-c++src",
+ indentUnit: 4,
+ });
+
+ // Match the initial textarea size.
+ editor.setSize(editor.defaultCharWidth() * code.cols,
+ editor.defaultTextHeight() * code.rows);
+
+ // Suppress changes to the first/last line (draw wrapper method)
+ editor.on('beforeChange', function(cm, change) {
+ if (change.from.line < 1 || change.from.line == cm.lineCount() - 1)
+ change.cancel();
+ });
function beginWait() {
document.body.classList.add('waiting');
@@ -258,7 +275,7 @@
req.overrideMimeType('application/json');
req.open('POST', '/', true);
req.setRequestHeader('content-type', 'application/json');
- req.send(JSON.stringify({'code': code.value, 'name': workspaceName}));
+ req.send(JSON.stringify({'code': editor.getValue(), 'name': workspaceName}));
}
run.addEventListener('click', onSubmitCode);
« no previous file with comments | « experimental/webtry/res/js/cm/codemirror.js ('k') | experimental/webtry/templates/content.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698