add wrapMethod:auto and fix tests

This commit is contained in:
nightwing 2013-07-24 15:48:52 +04:00
commit 62e7073b33
9 changed files with 35 additions and 31 deletions

View file

@ -946,7 +946,8 @@ var EditSession = function(text, mode) {
this.tokenRe = mode.tokenRe;
this.nonTokenRe = mode.nonTokenRe;
this.$options.wrapMethod.set.call(this, this.$wrapMethod);
if (!$isPlaceholder) {
this.$setFolding(mode.foldingRules);
this._emit("changeMode");
@ -1791,7 +1792,7 @@ var EditSession = function(text, mode) {
while (row <= lastRow) {
foldLine = this.getFoldLine(row, foldLine);
if (!foldLine) {
tokens = this.$getDisplayTokens(lang.stringTrimRight(lines[row]));
tokens = this.$getDisplayTokens(lines[row]);
wrapData[row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
row ++;
} else {
@ -1815,9 +1816,6 @@ var EditSession = function(text, mode) {
foldLine.end.row,
lines[foldLine.end.row].length + 1
);
// Remove spaces/tabs from the back of the token array.
while (tokens.length != 0 && tokens[tokens.length - 1] >= SPACE)
tokens.pop();
wrapData[foldLine.start.row]
= this.$computeWrapSplits(tokens, wrapLimit, tabSize);
@ -1931,7 +1929,7 @@ var EditSession = function(text, mode) {
// === ELSE ===
// Search for the first non space/tab/placeholder/punctuation token backwards.
var minSplit = Math.max(split - (isCode ? 10 : wrapLimit >> 1), lastSplit - 1);
var minSplit = Math.max(split - (isCode ? 10 : wrapLimit-(wrapLimit>>2)), lastSplit - 1);
while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
split --;
}
@ -2450,6 +2448,16 @@ config.defineOptions(EditSession.prototype, "session", {
return this.getUseWrapMode() ? this.getWrapLimitRange().min || "free" : "off";
},
handlesSet: true
},
wrapMethod: {
// code|text|auto
set: function(val) {
if (val == "auto")
this.$wrapAsCode = this.$mode.type != "text";
else
this.$wrapAsCode = val != "text";
},
initialValue: "auto"
},
firstLineNumber: {
set: function() {this._emit("changeBreakpoint");},
@ -2486,9 +2494,6 @@ config.defineOptions(EditSession.prototype, "session", {
set: function(val) {this.doc.setNewLineMode(val)},
get: function() {return this.doc.getNewLineMode()},
handlesSet: true
},
wrapAsCode: {
initialValue: false
}
});