Merge pull request #1520 from ajaxorg/wrap

Wrapping issues
This commit is contained in:
Lennart Kats 2013-08-07 07:10:21 -07:00
commit 42d243df4b
11 changed files with 61 additions and 80 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);
@ -1846,6 +1844,8 @@ var EditSession = function(text, mode) {
var displayLength = tokens.length; var displayLength = tokens.length;
var lastSplit = 0, lastDocSplit = 0; var lastSplit = 0, lastDocSplit = 0;
var isCode = this.$wrapAsCode;
function addSplit(screenPos) { function addSplit(screenPos) {
var displayed = tokens.slice(lastSplit, screenPos); var displayed = tokens.slice(lastSplit, screenPos);
@ -1873,11 +1873,12 @@ var EditSession = function(text, mode) {
// If there is a space or tab at this split position, then making // If there is a space or tab at this split position, then making
// a split is simple. // a split is simple.
if (tokens[split] >= SPACE) { if (tokens[split - 1] >= SPACE && tokens[split] >= SPACE) {
/* disabled see https://github.com/ajaxorg/ace/issues/1186
// Include all following spaces + tabs in this split as well. // Include all following spaces + tabs in this split as well.
while (tokens[split] >= SPACE) { while (tokens[split] >= SPACE) {
split ++; split ++;
} } */
addSplit(split); addSplit(split);
continue; continue;
} }
@ -1886,9 +1887,7 @@ var EditSession = function(text, mode) {
// Check if split is inside of a placeholder. Placeholder are // Check if split is inside of a placeholder. Placeholder are
// not splitable. Therefore, seek the beginning of the placeholder // not splitable. Therefore, seek the beginning of the placeholder
// and try to place the split beofre the placeholder's start. // and try to place the split beofre the placeholder's start.
if (tokens[split] == PLACEHOLDER_START if (tokens[split] == PLACEHOLDER_START || tokens[split] == PLACEHOLDER_BODY) {
|| tokens[split] == PLACEHOLDER_BODY)
{
// Seek the start of the placeholder and do the split // Seek the start of the placeholder and do the split
// before the placeholder. By definition there always // before the placeholder. By definition there always
// a PLACEHOLDER_START between split and lastSplit. // a PLACEHOLDER_START between split and lastSplit.
@ -1912,8 +1911,7 @@ var EditSession = function(text, mode) {
// placeholder. So, let's seek for the end of the placeholder. // placeholder. So, let's seek for the end of the placeholder.
split = lastSplit + wrapLimit; split = lastSplit + wrapLimit;
for (split; split < tokens.length; split++) { for (split; split < tokens.length; split++) {
if (tokens[split] != PLACEHOLDER_BODY) if (tokens[split] != PLACEHOLDER_BODY) {
{
break; break;
} }
} }
@ -1931,12 +1929,21 @@ 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 - 10, 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 --;
} }
while (split > minSplit && tokens[split] == PUNCTUATION) { if (isCode) {
split --; while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
split --;
}
while (split > minSplit && tokens[split] == PUNCTUATION) {
split --;
}
} else {
while (split > minSplit && tokens[split] < SPACE) {
split --;
}
} }
// If we found one, then add the split. // If we found one, then add the split.
if (split > minSplit) { if (split > minSplit) {
@ -2442,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

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

@ -1075,50 +1075,15 @@ exports.register = function (linter) {
}, },
{}], {}],
7:[function(req,module,exports){ 7:[function(req,module,exports){
(function(global){/*global window, global*/ [
var functions = [ "log", "info", "warn", "error", "time",
[log, "log"] "timeEnd", "trace", "dir", "assert"
, [info, "info"] ].forEach(function(x) {
, [warn, "warn"] exports[x] = nop;
, [error, "error"] });
, [time, "time"]
, [timeEnd, "timeEnd"]
, [trace, "trace"]
, [dir, "dir"]
, [assert, "assert"]
]
for (var i = 0; i < functions.length; i++) { function nop() {}
var tuple = functions[i]
var f = tuple[0]
var name = tuple[1]
if (!console[name]) {
console[name] = f
}
}
module.exports = console
function log() {}
function info() {}
function warn() {}
function error() {}
function time(label) {}
function timeEnd(label) {}
function trace() {}
function dir(object) {}
function assert(expression) {}
})(window)
}, },
{}], {}],
"jshint":[function(req,module,exports){ "jshint":[function(req,module,exports){

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

@ -38,18 +38,17 @@ var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var Behaviour = require("./behaviour").Behaviour; var Behaviour = require("./behaviour").Behaviour;
var Mode = function() { var Mode = function() {
this.$tokenizer = new Tokenizer(new TextHighlightRules().getRules()); this.$tokenizer = new Tokenizer(new TextHighlightRules().getRules());
this.$behaviour = new Behaviour(); this.$behaviour = new Behaviour();
}; };
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
} }

View file

@ -990,7 +990,7 @@ var VirtualRenderer = function(container, theme) {
this.$getLongestLine = function() { this.$getLongestLine = function() {
var charCount = this.session.getScreenWidth(); var charCount = this.session.getScreenWidth();
if (this.$textLayer.showInvisibles) if (this.showInvisibles && !this.session.$useWrapMode)
charCount += 1; charCount += 1;
return Math.max(this.$size.scrollerWidth - 2 * this.$padding, Math.round(charCount * this.characterWidth)); return Math.max(this.$size.scrollerWidth - 2 * this.$padding, Math.round(charCount * this.characterWidth));