Merge branch 'master' of github.com:ajaxorg/ace
This commit is contained in:
commit
67a366df13
8 changed files with 84 additions and 15 deletions
12
demo/demo.js
12
demo/demo.js
|
|
@ -84,6 +84,7 @@ exports.launch = function(env) {
|
||||||
}
|
}
|
||||||
docs.plain = new EditSession(loreIpsum);
|
docs.plain = new EditSession(loreIpsum);
|
||||||
docs.plain.setUseWrapMode(true);
|
docs.plain.setUseWrapMode(true);
|
||||||
|
docs.plain.setWrapLimitRange(80, 80)
|
||||||
docs.plain.setMode(new TextMode());
|
docs.plain.setMode(new TextMode());
|
||||||
docs.plain.setUndoManager(new UndoManager());
|
docs.plain.setUndoManager(new UndoManager());
|
||||||
|
|
||||||
|
|
@ -189,7 +190,7 @@ exports.launch = function(env) {
|
||||||
if (!doc.getUseWrapMode()) {
|
if (!doc.getUseWrapMode()) {
|
||||||
wrapModeEl.value = "off";
|
wrapModeEl.value = "off";
|
||||||
} else {
|
} else {
|
||||||
wrapModeEl.value = doc.getWrapLimit();
|
wrapModeEl.value = doc.getWrapLimitRange().min || "free";
|
||||||
}
|
}
|
||||||
env.editor.focus();
|
env.editor.focus();
|
||||||
});
|
});
|
||||||
|
|
@ -220,12 +221,17 @@ exports.launch = function(env) {
|
||||||
break;
|
break;
|
||||||
case "40":
|
case "40":
|
||||||
session.setUseWrapMode(true);
|
session.setUseWrapMode(true);
|
||||||
session.setWrapLimit(40);
|
session.setWrapLimitRange(40, 40);
|
||||||
renderer.setPrintMarginColumn(40);
|
renderer.setPrintMarginColumn(40);
|
||||||
break;
|
break;
|
||||||
case "80":
|
case "80":
|
||||||
session.setUseWrapMode(true);
|
session.setUseWrapMode(true);
|
||||||
session.setWrapLimit(80);
|
session.setWrapLimitRange(80, 80);
|
||||||
|
renderer.setPrintMarginColumn(80);
|
||||||
|
break;
|
||||||
|
case "free":
|
||||||
|
session.setUseWrapMode(true);
|
||||||
|
session.setWrapLimitRange(null, null);
|
||||||
renderer.setPrintMarginColumn(80);
|
renderer.setPrintMarginColumn(80);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,7 @@
|
||||||
<option value="off">Off</option>
|
<option value="off">Off</option>
|
||||||
<option value="40">40 Chars</option>
|
<option value="40">40 Chars</option>
|
||||||
<option value="80">80 Chars</option>
|
<option value="80">80 Chars</option>
|
||||||
|
<option value="free">Free</option>
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
<td align="right">
|
<td align="right">
|
||||||
|
|
|
||||||
|
|
@ -642,6 +642,10 @@ var EditSession = function(text, mode) {
|
||||||
// WRAPMODE
|
// WRAPMODE
|
||||||
this.$wrapLimit = 80;
|
this.$wrapLimit = 80;
|
||||||
this.$useWrapMode = false;
|
this.$useWrapMode = false;
|
||||||
|
this.$wrapLimitRange = {
|
||||||
|
min : null,
|
||||||
|
max : null
|
||||||
|
};
|
||||||
|
|
||||||
this.setUseWrapMode = function(useWrapMode) {
|
this.setUseWrapMode = function(useWrapMode) {
|
||||||
if (useWrapMode != this.$useWrapMode) {
|
if (useWrapMode != this.$useWrapMode) {
|
||||||
|
|
@ -666,21 +670,61 @@ var EditSession = function(text, mode) {
|
||||||
return this.$useWrapMode;
|
return this.$useWrapMode;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.setWrapLimit = function(wrapLimit) {
|
// Allow the wrap limit to move freely between min and max. Either
|
||||||
if (wrapLimit != this.$wrapLimit) {
|
// parameter can be null to allow the wrap limit to be unconstrained
|
||||||
this.$wrapLimit = wrapLimit;
|
// in that direction. Or set both parameters to the same number to pin
|
||||||
|
// the limit to that value.
|
||||||
|
this.setWrapLimitRange = function(min, max) {
|
||||||
|
if (this.$wrapLimitRange.min !== min || this.$wrapLimitRange.max !== max) {
|
||||||
|
this.$wrapLimitRange.min = min;
|
||||||
|
this.$wrapLimitRange.max = max;
|
||||||
this.$modified = true;
|
this.$modified = true;
|
||||||
if (this.$useWrapMode) {
|
// This will force a recalculation of the wrap limit
|
||||||
this.$updateWrapData(0, this.getLength() - 1);
|
|
||||||
}
|
|
||||||
this._dispatchEvent("changeWrapMode");
|
this._dispatchEvent("changeWrapMode");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// This should generally only be called by the renderer when a resize
|
||||||
|
// is detected.
|
||||||
|
this.adjustWrapLimit = function(desiredLimit) {
|
||||||
|
var wrapLimit = this.$constrainWrapLimit(desiredLimit);
|
||||||
|
if (wrapLimit != this.$wrapLimit && wrapLimit > 0) {
|
||||||
|
this.$wrapLimit = wrapLimit;
|
||||||
|
this.$modified = true;
|
||||||
|
if (this.$useWrapMode) {
|
||||||
|
this.$updateWrapData(0, this.getLength() - 1);
|
||||||
|
this._dispatchEvent("changeWrapLimit");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.$constrainWrapLimit = function(wrapLimit) {
|
||||||
|
var min = this.$wrapLimitRange.min;
|
||||||
|
if (min)
|
||||||
|
wrapLimit = Math.max(min, wrapLimit);
|
||||||
|
|
||||||
|
var max = this.$wrapLimitRange.max;
|
||||||
|
if (max)
|
||||||
|
wrapLimit = Math.min(max, wrapLimit);
|
||||||
|
|
||||||
|
// What would a limit of 0 even mean?
|
||||||
|
return Math.max(1, wrapLimit);
|
||||||
|
};
|
||||||
|
|
||||||
this.getWrapLimit = function() {
|
this.getWrapLimit = function() {
|
||||||
return this.$wrapLimit;
|
return this.$wrapLimit;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.getWrapLimitRange = function() {
|
||||||
|
// Avoid unexpected mutation by returning a copy
|
||||||
|
return {
|
||||||
|
min : this.$wrapLimitRange.min,
|
||||||
|
max : this.$wrapLimitRange.max
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
this.$updateWrapDataOnChange = function(e) {
|
this.$updateWrapDataOnChange = function(e) {
|
||||||
if (!this.$useWrapMode) {
|
if (!this.$useWrapMode) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,7 @@ var Editor =function(renderer, session) {
|
||||||
this.session.removeEventListener("change", this.$onDocumentChange);
|
this.session.removeEventListener("change", this.$onDocumentChange);
|
||||||
this.session.removeEventListener("changeMode", this.$onDocumentModeChange);
|
this.session.removeEventListener("changeMode", this.$onDocumentModeChange);
|
||||||
this.session.removeEventListener("changeTabSize", this.$onDocumentChangeTabSize);
|
this.session.removeEventListener("changeTabSize", this.$onDocumentChangeTabSize);
|
||||||
|
this.session.removeEventListener("changeWrapLimit", this.$onDocumentChangeWrapLimit);
|
||||||
this.session.removeEventListener("changeWrapMode", this.$onDocumentChangeWrapMode);
|
this.session.removeEventListener("changeWrapMode", this.$onDocumentChangeWrapMode);
|
||||||
this.session.removeEventListener("changeBreakpoint", this.$onDocumentChangeBreakpoint);
|
this.session.removeEventListener("changeBreakpoint", this.$onDocumentChangeBreakpoint);
|
||||||
this.session.removeEventListener("changeAnnotation", this.$onDocumentChangeAnnotation);
|
this.session.removeEventListener("changeAnnotation", this.$onDocumentChangeAnnotation);
|
||||||
|
|
@ -149,6 +150,9 @@ var Editor =function(renderer, session) {
|
||||||
this.$onDocumentChangeTabSize = this.renderer.updateText.bind(this.renderer);
|
this.$onDocumentChangeTabSize = this.renderer.updateText.bind(this.renderer);
|
||||||
session.addEventListener("changeTabSize", this.$onDocumentChangeTabSize);
|
session.addEventListener("changeTabSize", this.$onDocumentChangeTabSize);
|
||||||
|
|
||||||
|
this.$onDocumentChangeWrapLimit = this.onDocumentChangeWrapLimit.bind(this);
|
||||||
|
session.addEventListener("changeWrapLimit", this.$onDocumentChangeWrapLimit);
|
||||||
|
|
||||||
this.$onDocumentChangeWrapMode = this.onDocumentChangeWrapMode.bind(this);
|
this.$onDocumentChangeWrapMode = this.onDocumentChangeWrapMode.bind(this);
|
||||||
session.addEventListener("changeWrapMode", this.$onDocumentChangeWrapMode);
|
session.addEventListener("changeWrapMode", this.$onDocumentChangeWrapMode);
|
||||||
|
|
||||||
|
|
@ -348,11 +352,15 @@ var Editor =function(renderer, session) {
|
||||||
this.renderer.setTokenizer(this.bgTokenizer);
|
this.renderer.setTokenizer(this.bgTokenizer);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.onDocumentChangeWrapMode = function() {
|
this.onDocumentChangeWrapLimit = function() {
|
||||||
this.renderer.updateCursor(this.getCursorPosition(), this.$overwrite);
|
this.renderer.updateCursor(this.getCursorPosition(), this.$overwrite);
|
||||||
this.renderer.updateFull();
|
this.renderer.updateFull();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.onDocumentChangeWrapMode = function() {
|
||||||
|
this.renderer.onResize(true);
|
||||||
|
};
|
||||||
|
|
||||||
this.getCopyText = function() {
|
this.getCopyText = function() {
|
||||||
if (!this.selection.isEmpty()) {
|
if (!this.selection.isEmpty()) {
|
||||||
return this.session.getTextRange(this.getSelectionRange());
|
return this.session.getTextRange(this.getSelectionRange());
|
||||||
|
|
|
||||||
|
|
@ -197,7 +197,7 @@ StateHandler.prototype = {
|
||||||
// If we pressed any command key but no other key, then ignore the input.
|
// If we pressed any command key but no other key, then ignore the input.
|
||||||
// Otherwise "shift-" is added to the buffer, and later on "shift-g"
|
// Otherwise "shift-" is added to the buffer, and later on "shift-g"
|
||||||
// which results in "shift-shift-g" which doesn't make senese.
|
// which results in "shift-shift-g" which doesn't make senese.
|
||||||
if (hashId != 0 && (key == "" || key == String.fromCharCode(0))) {
|
if (hashId != 0 && (key == "" || String.fromCharCode(0))) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -169,14 +169,14 @@ var Test = {
|
||||||
var wrapLimit = 12;
|
var wrapLimit = 12;
|
||||||
var session = new EditSession(["foo bar foo bar"]);
|
var session = new EditSession(["foo bar foo bar"]);
|
||||||
session.setUseWrapMode(true);
|
session.setUseWrapMode(true);
|
||||||
session.setWrapLimit(12);
|
session.setWrapLimitRange(12, 12);
|
||||||
|
|
||||||
assert.position(session.documentToScreenPosition(0, 11), 0, 11);
|
assert.position(session.documentToScreenPosition(0, 11), 0, 11);
|
||||||
assert.position(session.documentToScreenPosition(0, 12), 1, 0);
|
assert.position(session.documentToScreenPosition(0, 12), 1, 0);
|
||||||
|
|
||||||
session = new EditSession(["ぁぁa"]);
|
session = new EditSession(["ぁぁa"]);
|
||||||
session.setUseWrapMode(true);
|
session.setUseWrapMode(true);
|
||||||
session.setWrapLimit(2);
|
session.setWrapLimitRange(2, 2);
|
||||||
assert.position(session.documentToScreenPosition(0, 1), 1, 0);
|
assert.position(session.documentToScreenPosition(0, 1), 1, 0);
|
||||||
assert.position(session.documentToScreenPosition(0, 2), 2, 0);
|
assert.position(session.documentToScreenPosition(0, 2), 2, 0);
|
||||||
assert.position(session.documentToScreenPosition(0, 4), 2, 1);
|
assert.position(session.documentToScreenPosition(0, 4), 2, 1);
|
||||||
|
|
@ -202,7 +202,7 @@ var Test = {
|
||||||
var wrapLimit = 12;
|
var wrapLimit = 12;
|
||||||
var session = new EditSession(["foo bar foo bar"]);
|
var session = new EditSession(["foo bar foo bar"]);
|
||||||
session.setUseWrapMode(true);
|
session.setUseWrapMode(true);
|
||||||
session.setWrapLimit(12);
|
session.setWrapLimitRange(12, 12);
|
||||||
|
|
||||||
assert.position(session.screenToDocumentPosition(1, 0), 0, 12);
|
assert.position(session.screenToDocumentPosition(1, 0), 0, 12);
|
||||||
assert.position(session.screenToDocumentPosition(0, 11), 0, 11);
|
assert.position(session.screenToDocumentPosition(0, 11), 0, 11);
|
||||||
|
|
@ -378,7 +378,7 @@ var Test = {
|
||||||
var document = session.getDocument();
|
var document = session.getDocument();
|
||||||
|
|
||||||
session.setUseWrapMode(true);
|
session.setUseWrapMode(true);
|
||||||
session.setWrapLimit(3);
|
session.setWrapLimitRange(3, 3);
|
||||||
|
|
||||||
// Test if wrapData is there and was computed.
|
// Test if wrapData is there and was computed.
|
||||||
assert.equal(session.$wrapData.length, 2);
|
assert.equal(session.$wrapData.length, 2);
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,9 @@ define(function(require, exports, module) {
|
||||||
.ace-twilight.normal-mode .ace_cursor.ace_overwrite {\
|
.ace-twilight.normal-mode .ace_cursor.ace_overwrite {\
|
||||||
border: 1px solid #FFE300;\
|
border: 1px solid #FFE300;\
|
||||||
background: #766B13;\
|
background: #766B13;\
|
||||||
|
}\
|
||||||
|
.ace-twilight.normal-mode .ace_cursor-layer {\
|
||||||
|
z-index: 0;\
|
||||||
}\
|
}\
|
||||||
\
|
\
|
||||||
.ace-twilight .ace_marker-layer .ace_selection {\
|
.ace-twilight .ace_marker-layer .ace_selection {\
|
||||||
|
|
|
||||||
|
|
@ -210,6 +210,13 @@ var VirtualRenderer = function(container, theme) {
|
||||||
var gutterWidth = this.showGutter ? this.$gutter.offsetWidth : 0;
|
var gutterWidth = this.showGutter ? this.$gutter.offsetWidth : 0;
|
||||||
this.scroller.style.left = gutterWidth + "px";
|
this.scroller.style.left = gutterWidth + "px";
|
||||||
this.scroller.style.width = Math.max(0, width - gutterWidth - this.scrollBar.getWidth()) + "px";
|
this.scroller.style.width = Math.max(0, width - gutterWidth - this.scrollBar.getWidth()) + "px";
|
||||||
|
|
||||||
|
if (this.session.getUseWrapMode()) {
|
||||||
|
var limit = Math.floor(this.scroller.clientWidth / this.characterWidth);
|
||||||
|
if (this.session.adjustWrapLimit(limit) || force) {
|
||||||
|
changes = changes | this.CHANGE_FULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$size.scrollerWidth = this.scroller.clientWidth;
|
this.$size.scrollerWidth = this.scroller.clientWidth;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue