add wrapMethod:auto and fix tests
This commit is contained in:
parent
9f068dc45d
commit
62e7073b33
9 changed files with 35 additions and 31 deletions
|
|
@ -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
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -386,11 +386,12 @@ module.exports = {
|
|||
assert.ok(splits[i] == assertEqual[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
EditSession.prototype.$wrapAsCode = true;
|
||||
// Basic splitting.
|
||||
computeAndAssert("foo bar foo bar", [ 12 ]);
|
||||
computeAndAssert("foo bar f bar", [ 12 ]);
|
||||
computeAndAssert("foo bar f r", [ 14 ]);
|
||||
computeAndAssert("foo bar f r", [ 12 ]); // 14 if we enable
|
||||
computeAndAssert("foo bar foo bar foo bara foo", [12, 25]);
|
||||
|
||||
// Don't split if there is only whitespaces/tabs at the end of the line.
|
||||
|
|
@ -406,7 +407,7 @@ module.exports = {
|
|||
computeAndAssert("foo \t \tbar", [ 7 ]);
|
||||
|
||||
// Ignore spaces/tabs at beginning of split.
|
||||
computeAndAssert("foo \t \t \t \t bar", [ 14 ]);
|
||||
computeAndAssert("foo \t \t \t \t bar", [ 7 ]); // 14
|
||||
|
||||
// Test wrapping for asian characters.
|
||||
computeAndAssert("ぁぁ", [1], 2);
|
||||
|
|
@ -418,6 +419,10 @@ module.exports = {
|
|||
computeAndAssert(" ab.c;ef++", [1, 3, 5, 7, 8], 2);
|
||||
computeAndAssert(" a.b", [1, 2, 3], 1);
|
||||
computeAndAssert("#>>", [1, 2], 1);
|
||||
|
||||
// Test wrapping for punctuation in
|
||||
EditSession.prototype.$wrapAsCode = false;
|
||||
computeAndAssert("ab cde, Juhu kinners", [3, 8, 13, 19], 6);
|
||||
},
|
||||
|
||||
"test get longest line" : function() {
|
||||
|
|
|
|||
|
|
@ -226,7 +226,7 @@ var Editor = function(renderer, session) {
|
|||
_self.keyBinding.setKeyboardHandler(module && module.handler);
|
||||
});
|
||||
} else {
|
||||
delete this.$keybindingId;
|
||||
this.$keybindingId = null;
|
||||
this.keyBinding.setKeyboardHandler(keyboardHandler);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -457,9 +457,9 @@ var Text = function(parentEl) {
|
|||
return screenColumn + value.length;
|
||||
};
|
||||
|
||||
this.renderIndentGuide = function(stringBuilder, value) {
|
||||
this.renderIndentGuide = function(stringBuilder, value, max) {
|
||||
var cols = value.search(this.$indentGuideRe);
|
||||
if (cols <= 0)
|
||||
if (cols <= 0 || cols >= max)
|
||||
return value;
|
||||
if (value[0] == " ") {
|
||||
cols -= cols % this.tabSize;
|
||||
|
|
@ -483,7 +483,7 @@ var Text = function(parentEl) {
|
|||
var value = token.value;
|
||||
if (i == 0 && this.displayIndentGuides) {
|
||||
chars = value.length;
|
||||
value = this.renderIndentGuide(stringBuilder, value);
|
||||
value = this.renderIndentGuide(stringBuilder, value, splitChars);
|
||||
if (!value)
|
||||
continue;
|
||||
chars -= value.length;
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ var Mode = function() {
|
|||
oop.inherits(Mode, TextMode);
|
||||
|
||||
(function() {
|
||||
this.type = "text";
|
||||
this.getNextLineIndent = function(state, line, tab) {
|
||||
if (state == "listblock") {
|
||||
var match = /^((?:.+)?)([-+*][ ]+)/.exec(line);
|
||||
|
|
|
|||
|
|
@ -26,11 +26,6 @@
|
|||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ var Mode = function() {
|
|||
oop.inherits(Mode, TextMode);
|
||||
|
||||
(function() {
|
||||
|
||||
this.type = "text";
|
||||
this.lineCommentStart = ">";
|
||||
|
||||
this.getNextLineIndent = function(state, line, tab) {
|
||||
|
|
|
|||
|
|
@ -38,18 +38,17 @@ var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
|
|||
var Behaviour = require("./behaviour").Behaviour;
|
||||
|
||||
var Mode = function() {
|
||||
this.$tokenizer = new Tokenizer(new TextHighlightRules().getRules());
|
||||
this.$behaviour = new Behaviour();
|
||||
this.$tokenizer = new Tokenizer(new TextHighlightRules().getRules());
|
||||
this.$behaviour = new Behaviour();
|
||||
};
|
||||
|
||||
oop.inherits(Mode, TextMode);
|
||||
|
||||
(function() {
|
||||
|
||||
this.getNextLineIndent = function(state, line, tab) {
|
||||
return '';
|
||||
};
|
||||
|
||||
this.type = "text";
|
||||
this.getNextLineIndent = function(state, line, tab) {
|
||||
return '';
|
||||
};
|
||||
}).call(Mode.prototype);
|
||||
|
||||
exports.Mode = Mode;
|
||||
|
|
|
|||
|
|
@ -8,8 +8,7 @@
|
|||
background: #f6f6f6
|
||||
}
|
||||
|
||||
.ace-tomorrow,
|
||||
.ace-tomorrow .ace_scroller {
|
||||
.ace-tomorrow {
|
||||
background-color: #FFFFFF;
|
||||
color: #4D4D4C
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue