From a5a7013333b68c12b231b9792db97d5867132315 Mon Sep 17 00:00:00 2001
From: d11e9
Date: Mon, 31 Aug 2015 11:02:48 +0100
Subject: [PATCH] add text wrap option
---
index.html | 34 +++++++++++++++++++++++++++++-----
1 file changed, 29 insertions(+), 5 deletions(-)
diff --git a/index.html b/index.html
index 45c1af6f06..27b2af5366 100644
--- a/index.html
+++ b/index.html
@@ -254,6 +254,7 @@ body {
enable the debug console (Ctrl+Shift+i) and reload.
+
@@ -292,18 +293,42 @@ body {
$('#ghostbar').remove();
$(document).unbind('mousemove');
dragging = false;
+ onResize();
}
});
// ----------------- editor ----------------------
var editor = ace.edit("input");
- editor.getSession().setMode("ace/mode/javascript");
- editor.getSession().setTabSize(4);
- editor.getSession().setUseSoftTabs(true);
- Range = ace.require('ace/range').Range;
+ var session = editor.getSession();
+ var Range = ace.require('ace/range').Range;
var errMarkerId = null;
+ session.setMode("ace/mode/javascript");
+ session.setTabSize(4);
+ session.setUseSoftTabs(true);
+
+
+ // ----------------- editor resize ---------------
+
+ function onResize() {
+ editor.resize();
+ session.setUseWrapMode(document.querySelector('#editorWrap').checked);
+ if(session.getUseWrapMode()) {
+ var characterWidth = editor.renderer.characterWidth;
+ var contentWidth = editor.container.ownerDocument.getElementsByClassName("ace_scroller")[0].clientWidth;
+
+ if(contentWidth > 0) {
+ session.setWrapLimit(parseInt(contentWidth / characterWidth, 10));
+ }
+ }
+ }
+ window.onresize = onResize;
+ onResize();
+
+ document.querySelector('#editorWrap').addEventListener('change', onResize );
+
+
// ----------------- compiler ----------------------
var compileJSON = Module.cwrap("compileJSON", "string", ["string", "number"]);
$('#version').text(Module.cwrap("version", "string", [])());
@@ -346,7 +371,6 @@ body {
var err = message.match(/^:([0-9]*):([0-9]*)/)
var errLine = parseInt( err[1], 10 ) - 1;
var errCol = parseInt( err[2], 10 );
- editor.gotoLine( errLine );
$('#output').empty().append($('').text(message));
errMarkerId = editor.getSession().addMarker(new Range(errLine, 0, errLine, 1), "solError", "fullLine");
editor.getSession().setAnnotations([{