fix toggle show invisibles and add it to the demo
This commit is contained in:
parent
9ddc3dbc3b
commit
1c432b976c
4 changed files with 64 additions and 42 deletions
|
|
@ -77,13 +77,35 @@ exports.launch = function(env) {
|
||||||
docs.php.setMode(new PhpMode());
|
docs.php.setMode(new PhpMode());
|
||||||
docs.php.setUndoManager(new UndoManager());
|
docs.php.setUndoManager(new UndoManager());
|
||||||
|
|
||||||
var docEl = document.getElementById("doc");
|
|
||||||
|
|
||||||
var container = document.getElementById("editor");
|
var container = document.getElementById("editor");
|
||||||
env.editor = new Editor(new Renderer(container, theme));
|
env.editor = new Editor(new Renderer(container, theme));
|
||||||
|
|
||||||
|
var modes = {
|
||||||
|
text: new TextMode(),
|
||||||
|
xml: new XmlMode(),
|
||||||
|
html: new HtmlMode(),
|
||||||
|
css: new CssMode(),
|
||||||
|
javascript: new JavaScriptMode(),
|
||||||
|
python: new PythonMode(),
|
||||||
|
php: new PhpMode()
|
||||||
|
};
|
||||||
|
|
||||||
|
function getMode() {
|
||||||
|
return modes[modeEl.value];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var modeEl = document.getElementById("mode");
|
||||||
|
function setMode() {
|
||||||
|
env.editor.getDocument().setMode(modes[modeEl.value] || modes.text);
|
||||||
|
}
|
||||||
|
modeEl.onchange = setMode;
|
||||||
|
setMode();
|
||||||
|
|
||||||
|
var docEl = document.getElementById("doc");
|
||||||
function onDocChange() {
|
function onDocChange() {
|
||||||
var doc = getDoc();
|
var doc = docs[docEl.value];
|
||||||
env.editor.setDocument(doc);
|
env.editor.setDocument(doc);
|
||||||
|
|
||||||
var mode = doc.getMode();
|
var mode = doc.getMode();
|
||||||
|
|
@ -112,51 +134,46 @@ exports.launch = function(env) {
|
||||||
env.editor.focus();
|
env.editor.focus();
|
||||||
}
|
}
|
||||||
docEl.onchange = onDocChange;
|
docEl.onchange = onDocChange;
|
||||||
|
onDocChange();
|
||||||
|
|
||||||
function getDoc() {
|
|
||||||
return docs[docEl.value];
|
|
||||||
}
|
|
||||||
|
|
||||||
var modeEl = document.getElementById("mode");
|
|
||||||
modeEl.onchange = function() {
|
|
||||||
env.editor.getDocument().setMode(modes[modeEl.value] || modes.text);
|
|
||||||
};
|
|
||||||
|
|
||||||
var modes = {
|
|
||||||
text: new TextMode(),
|
|
||||||
xml: new XmlMode(),
|
|
||||||
html: new HtmlMode(),
|
|
||||||
css: new CssMode(),
|
|
||||||
javascript: new JavaScriptMode(),
|
|
||||||
python: new PythonMode(),
|
|
||||||
php: new PhpMode()
|
|
||||||
};
|
|
||||||
|
|
||||||
function getMode() {
|
|
||||||
return modes[modeEl.value];
|
|
||||||
}
|
|
||||||
|
|
||||||
var themeEl = document.getElementById("theme");
|
var themeEl = document.getElementById("theme");
|
||||||
themeEl.onchange = function() {
|
function setTheme() {
|
||||||
env.editor.setTheme(themeEl.value);
|
env.editor.setTheme(themeEl.value);
|
||||||
};
|
};
|
||||||
|
themeEl.onchange = setTheme;
|
||||||
|
setTheme();
|
||||||
|
|
||||||
|
|
||||||
var selectEl = document.getElementById("select_style");
|
var selectEl = document.getElementById("select_style");
|
||||||
selectEl.onchange = function() {
|
function setSelectionStyle() {
|
||||||
if (selectEl.checked) {
|
if (selectEl.checked) {
|
||||||
env.editor.setSelectionStyle("line");
|
env.editor.setSelectionStyle("line");
|
||||||
} else {
|
} else {
|
||||||
env.editor.setSelectionStyle("text");
|
env.editor.setSelectionStyle("text");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
selectEl.onchange = setSelectionStyle;
|
||||||
|
setSelectionStyle();
|
||||||
|
|
||||||
|
|
||||||
var activeEl = document.getElementById("highlight_active");
|
var activeEl = document.getElementById("highlight_active");
|
||||||
activeEl.onchange = function() {
|
function setHighlightActiveLine() {
|
||||||
env.editor.setHighlightActiveLine(!!activeEl.checked);
|
env.editor.setHighlightActiveLine(!!activeEl.checked);
|
||||||
};
|
};
|
||||||
|
activeEl.onchange = setHighlightActiveLine;
|
||||||
|
setHighlightActiveLine();
|
||||||
|
|
||||||
onDocChange();
|
|
||||||
|
|
||||||
|
var showHiddenEl = document.getElementById("show_hidden");
|
||||||
|
function setShowInvisibles() {
|
||||||
|
env.editor.setShowInvisibles(!!showHiddenEl.checked);
|
||||||
|
};
|
||||||
|
showHiddenEl.onchange = setShowInvisibles;
|
||||||
|
setShowInvisibles();
|
||||||
|
|
||||||
|
|
||||||
|
// for debugging
|
||||||
window.jump = function() {
|
window.jump = function() {
|
||||||
var jump = document.getElementById("jump");
|
var jump = document.getElementById("jump");
|
||||||
var cursor = env.editor.getCursorPosition();
|
var cursor = env.editor.getCursorPosition();
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,10 @@
|
||||||
<label for="highlight_active">Highlight active line</label>
|
<label for="highlight_active">Highlight active line</label>
|
||||||
<input type="checkbox" name="highlight_active" id="highlight_active" checked>
|
<input type="checkbox" name="highlight_active" id="highlight_active" checked>
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
<label for="show_hidden">Show invisibles</label>
|
||||||
|
<input type="checkbox" name="show_hidden" id="show_hidden">
|
||||||
|
</td>
|
||||||
<td align="right">
|
<td align="right">
|
||||||
<img src="demo/logo.png">
|
<img src="demo/logo.png">
|
||||||
</td>
|
</td>
|
||||||
|
|
|
||||||
|
|
@ -129,14 +129,18 @@ var Text = function(parentEl) {
|
||||||
this.doc = doc;
|
this.doc = doc;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$showInvisibles = false;
|
this.showInvisibles = false;
|
||||||
this.setShowInvisibles = function(showInvisibles) {
|
this.setShowInvisibles = function(showInvisibles) {
|
||||||
this.$showInvisibles = showInvisibles;
|
if (this.showInvisibles == showInvisibles)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
this.showInvisibles = showInvisibles;
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$computeTabString = function() {
|
this.$computeTabString = function() {
|
||||||
var tabSize = this.doc.getTabSize();
|
var tabSize = this.doc.getTabSize();
|
||||||
if (this.$showInvisibles) {
|
if (this.showInvisibles) {
|
||||||
var halfTab = (tabSize) / 2;
|
var halfTab = (tabSize) / 2;
|
||||||
this.$tabString = "<span class='ace_invisible'>"
|
this.$tabString = "<span class='ace_invisible'>"
|
||||||
+ new Array(Math.floor(halfTab)).join(" ")
|
+ new Array(Math.floor(halfTab)).join(" ")
|
||||||
|
|
@ -263,7 +267,7 @@ var Text = function(parentEl) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$renderLine = function(stringBuilder, row, tokens) {
|
this.$renderLine = function(stringBuilder, row, tokens) {
|
||||||
// if (this.$showInvisibles) {
|
// if (this.showInvisibles) {
|
||||||
// var self = this;
|
// var self = this;
|
||||||
// var spaceRe = /[\v\f \u00a0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000]+/g;
|
// var spaceRe = /[\v\f \u00a0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000]+/g;
|
||||||
// var spaceReplace = function(space) {
|
// var spaceReplace = function(space) {
|
||||||
|
|
@ -294,7 +298,7 @@ var Text = function(parentEl) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.$showInvisibles) {
|
if (this.showInvisibles) {
|
||||||
if (row !== this.doc.getLength() - 1) {
|
if (row !== this.doc.getLength() - 1) {
|
||||||
stringBuilder.push("<span class='ace_invisible'>" + this.EOL_CHAR + "</span>");
|
stringBuilder.push("<span class='ace_invisible'>" + this.EOL_CHAR + "</span>");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -229,16 +229,13 @@ var VirtualRenderer = function(container, theme) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$showInvisibles = true;
|
|
||||||
this.setShowInvisibles = function(showInvisibles) {
|
this.setShowInvisibles = function(showInvisibles) {
|
||||||
this.$showInvisibles = showInvisibles;
|
if (this.$textLayer.setShowInvisibles(showInvisibles))
|
||||||
this.$textLayer.setShowInvisibles(showInvisibles);
|
this.$loop.schedule(this.CHANGE_TEXT);
|
||||||
|
|
||||||
this.$loop.schedule(this.CHANGE_TEXT);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getShowInvisibles = function() {
|
this.getShowInvisibles = function() {
|
||||||
return this.$showInvisibles;
|
return this.$textLayer.showInvisibles;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$showPrintMargin = true;
|
this.$showPrintMargin = true;
|
||||||
|
|
@ -453,7 +450,7 @@ var VirtualRenderer = function(container, theme) {
|
||||||
|
|
||||||
this.$getLongestLine = function() {
|
this.$getLongestLine = function() {
|
||||||
var charCount = this.doc.getScreenWidth();
|
var charCount = this.doc.getScreenWidth();
|
||||||
if (this.$showInvisibles)
|
if (this.$textLayer.showInvisibles)
|
||||||
charCount += 1;
|
charCount += 1;
|
||||||
|
|
||||||
return Math.max(this.$size.scrollerWidth - this.$padding * 2, Math.round(charCount * this.characterWidth));
|
return Math.max(this.$size.scrollerWidth - this.$padding * 2, Math.round(charCount * this.characterWidth));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue