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,6 +946,7 @@ var EditSession = function(text, mode) {
this.tokenRe = mode.tokenRe; this.tokenRe = mode.tokenRe;
this.nonTokenRe = mode.nonTokenRe; this.nonTokenRe = mode.nonTokenRe;
this.$options.wrapMethod.set.call(this, this.$wrapMethod);
if (!$isPlaceholder) { if (!$isPlaceholder) {
this.$setFolding(mode.foldingRules); this.$setFolding(mode.foldingRules);
@ -1791,7 +1792,7 @@ var EditSession = function(text, mode) {
while (row <= lastRow) { while (row <= lastRow) {
foldLine = this.getFoldLine(row, foldLine); foldLine = this.getFoldLine(row, foldLine);
if (!foldLine) { if (!foldLine) {
tokens = this.$getDisplayTokens(lang.stringTrimRight(lines[row])); tokens = this.$getDisplayTokens(lines[row]);
wrapData[row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize); wrapData[row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
row ++; row ++;
} else { } else {
@ -1815,9 +1816,6 @@ var EditSession = function(text, mode) {
foldLine.end.row, foldLine.end.row,
lines[foldLine.end.row].length + 1 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] wrapData[foldLine.start.row]
= this.$computeWrapSplits(tokens, wrapLimit, tabSize); = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
@ -1931,7 +1929,7 @@ var EditSession = function(text, mode) {
// === ELSE === // === ELSE ===
// Search for the first non space/tab/placeholder/punctuation token backwards. // 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) { while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
split --; split --;
} }
@ -2451,6 +2449,16 @@ config.defineOptions(EditSession.prototype, "session", {
}, },
handlesSet: true 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: { firstLineNumber: {
set: function() {this._emit("changeBreakpoint");}, set: function() {this._emit("changeBreakpoint");},
initialValue: 1 initialValue: 1
@ -2486,9 +2494,6 @@ config.defineOptions(EditSession.prototype, "session", {
set: function(val) {this.doc.setNewLineMode(val)}, set: function(val) {this.doc.setNewLineMode(val)},
get: function() {return this.doc.getNewLineMode()}, get: function() {return this.doc.getNewLineMode()},
handlesSet: true handlesSet: true
},
wrapAsCode: {
initialValue: false
} }
}); });

View file

@ -387,10 +387,11 @@ module.exports = {
} }
} }
EditSession.prototype.$wrapAsCode = true;
// Basic splitting. // Basic splitting.
computeAndAssert("foo bar foo bar", [ 12 ]); computeAndAssert("foo bar foo bar", [ 12 ]);
computeAndAssert("foo bar f 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]); 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. // 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 ]); computeAndAssert("foo \t \tbar", [ 7 ]);
// Ignore spaces/tabs at beginning of split. // 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. // Test wrapping for asian characters.
computeAndAssert("ぁぁ", [1], 2); computeAndAssert("ぁぁ", [1], 2);
@ -418,6 +419,10 @@ module.exports = {
computeAndAssert(" ab.c;ef++", [1, 3, 5, 7, 8], 2); computeAndAssert(" ab.c;ef++", [1, 3, 5, 7, 8], 2);
computeAndAssert(" a.b", [1, 2, 3], 1); computeAndAssert(" a.b", [1, 2, 3], 1);
computeAndAssert("#>>", [1, 2], 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() { "test get longest line" : function() {

View file

@ -226,7 +226,7 @@ var Editor = function(renderer, session) {
_self.keyBinding.setKeyboardHandler(module && module.handler); _self.keyBinding.setKeyboardHandler(module && module.handler);
}); });
} else { } else {
delete this.$keybindingId; this.$keybindingId = null;
this.keyBinding.setKeyboardHandler(keyboardHandler); this.keyBinding.setKeyboardHandler(keyboardHandler);
} }
}; };

View file

@ -457,9 +457,9 @@ var Text = function(parentEl) {
return screenColumn + value.length; return screenColumn + value.length;
}; };
this.renderIndentGuide = function(stringBuilder, value) { this.renderIndentGuide = function(stringBuilder, value, max) {
var cols = value.search(this.$indentGuideRe); var cols = value.search(this.$indentGuideRe);
if (cols <= 0) if (cols <= 0 || cols >= max)
return value; return value;
if (value[0] == " ") { if (value[0] == " ") {
cols -= cols % this.tabSize; cols -= cols % this.tabSize;
@ -483,7 +483,7 @@ var Text = function(parentEl) {
var value = token.value; var value = token.value;
if (i == 0 && this.displayIndentGuides) { if (i == 0 && this.displayIndentGuides) {
chars = value.length; chars = value.length;
value = this.renderIndentGuide(stringBuilder, value); value = this.renderIndentGuide(stringBuilder, value, splitChars);
if (!value) if (!value)
continue; continue;
chars -= value.length; chars -= value.length;

View file

@ -46,6 +46,7 @@ var Mode = function() {
oop.inherits(Mode, TextMode); oop.inherits(Mode, TextMode);
(function() { (function() {
this.type = "text";
this.getNextLineIndent = function(state, line, tab) { this.getNextLineIndent = function(state, line, tab) {
if (state == "listblock") { if (state == "listblock") {
var match = /^((?:.+)?)([-+*][ ]+)/.exec(line); var match = /^((?:.+)?)([-+*][ ]+)/.exec(line);

View file

@ -26,11 +26,6 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
*
* Contributor(s):
*
*
*
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
/* /*

View file

@ -56,7 +56,7 @@ var Mode = function() {
oop.inherits(Mode, TextMode); oop.inherits(Mode, TextMode);
(function() { (function() {
this.type = "text";
this.lineCommentStart = ">"; this.lineCommentStart = ">";
this.getNextLineIndent = function(state, line, tab) { this.getNextLineIndent = function(state, line, tab) {

View file

@ -45,11 +45,10 @@ var Mode = function() {
oop.inherits(Mode, TextMode); oop.inherits(Mode, TextMode);
(function() { (function() {
this.type = "text";
this.getNextLineIndent = function(state, line, tab) { this.getNextLineIndent = function(state, line, tab) {
return ''; return '';
}; };
}).call(Mode.prototype); }).call(Mode.prototype);
exports.Mode = Mode; exports.Mode = Mode;

View file

@ -8,8 +8,7 @@
background: #f6f6f6 background: #f6f6f6
} }
.ace-tomorrow, .ace-tomorrow {
.ace-tomorrow .ace_scroller {
background-color: #FFFFFF; background-color: #FFFFFF;
color: #4D4D4C color: #4D4D4C
} }