fixes for indentedSoftWrap option
This commit is contained in:
parent
0753f9aa12
commit
ef9cc542e7
3 changed files with 39 additions and 29 deletions
|
|
@ -1846,15 +1846,15 @@ var EditSession = function(text, mode) {
|
|||
|
||||
var isCode = this.$wrapAsCode;
|
||||
|
||||
var indentSubsequentLines = this.$indentSubsequentLines;
|
||||
var indentedSoftWrap = this.$indentedSoftWrap;
|
||||
var maxIndent = wrapLimit <= Math.max(2 * tabSize, 8)
|
||||
|| indentedSoftWrap === false ? 0 : Math.floor(wrapLimit / 2);
|
||||
|
||||
var maxIndent = wrapLimit > 8 ? Math.floor(wrapLimit / 2) : 0;
|
||||
|
||||
function getIndentation() {
|
||||
function getWrapIndent() {
|
||||
var indentation = 0;
|
||||
if (maxIndent === 0)
|
||||
return indentation;
|
||||
if (indentSubsequentLines) {
|
||||
if (indentedSoftWrap) {
|
||||
for (var i = 0; i < tokens.length; i++) {
|
||||
var token = tokens[i];
|
||||
if (token == SPACE)
|
||||
|
|
@ -1867,11 +1867,10 @@ var EditSession = function(text, mode) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (isCode)
|
||||
if (isCode && indentedSoftWrap !== false)
|
||||
indentation += tabSize;
|
||||
return Math.min(indentation, maxIndent);
|
||||
}
|
||||
|
||||
function addSplit(screenPos) {
|
||||
var displayed = tokens.slice(lastSplit, screenPos);
|
||||
|
||||
|
|
@ -1888,8 +1887,8 @@ var EditSession = function(text, mode) {
|
|||
len -= 1;
|
||||
});
|
||||
|
||||
if (splits.length === 0) {
|
||||
indent = getIndentation();
|
||||
if (!splits.length) {
|
||||
indent = getWrapIndent();
|
||||
splits.indent = indent;
|
||||
}
|
||||
lastDocSplit += len;
|
||||
|
|
@ -1959,7 +1958,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-(wrapLimit>>2)), lastSplit - 1);
|
||||
var minSplit = Math.max(split - (wrapLimit -(wrapLimit>>2)), lastSplit - 1);
|
||||
while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
|
||||
split --;
|
||||
}
|
||||
|
|
@ -2095,13 +2094,12 @@ var EditSession = function(text, mode) {
|
|||
};
|
||||
|
||||
this.getRowWrapIndent = function(screenRow) {
|
||||
if (!this.$useWrapMode) {
|
||||
return 0;
|
||||
if (this.$useWrapMode) {
|
||||
var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
|
||||
var splits = this.$wrapData[pos.row];
|
||||
return splits.length && splits[0] < pos.column ? splits.indent : 0;
|
||||
} else {
|
||||
var row = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE).row;
|
||||
var splits = this.$wrapData[row];
|
||||
var splitIndex = Math.floor(screenRow - row);
|
||||
return splits.length && splitIndex > 0 ? splits.indent : 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2547,7 +2545,7 @@ config.defineOptions(EditSession.prototype, "session", {
|
|||
},
|
||||
initialValue: "auto"
|
||||
},
|
||||
indentSubsequentLines: {initialValue: true},
|
||||
indentedSoftWrap: { initialValue: true },
|
||||
firstLineNumber: {
|
||||
set: function() {this._signal("changeBreakpoint");},
|
||||
initialValue: 1
|
||||
|
|
|
|||
|
|
@ -380,7 +380,8 @@ module.exports = {
|
|||
line = lang.stringTrimRight(line);
|
||||
var tokens = EditSession.prototype.$getDisplayTokens(line);
|
||||
var splits = EditSession.prototype.$computeWrapSplits(tokens, wrapLimit, tabSize);
|
||||
// console.log("String:", line, "Result:", splits, "Expected:", assertEqual);
|
||||
console.log("String:", line, "Result:", splits, "Expected:", assertEqual);
|
||||
|
||||
assert.ok(splits.length == assertEqual.length);
|
||||
for (var i = 0; i < splits.length; i++) {
|
||||
assert.ok(splits[i] == assertEqual[i]);
|
||||
|
|
@ -388,42 +389,52 @@ module.exports = {
|
|||
}
|
||||
|
||||
EditSession.prototype.$wrapAsCode = true;
|
||||
EditSession.prototype.$indentSubsequentLines = false;
|
||||
EditSession.prototype.$indentedSoftWrap = false;
|
||||
// Basic splitting.
|
||||
computeAndAssert("foo bar foo bar", [ 12 ]);
|
||||
computeAndAssert("foo bar f bar", [ 12 ]);
|
||||
computeAndAssert("foo bar f r", [ 12 ]); // 14 if we enable
|
||||
computeAndAssert("foo bar foo bar foo bara foo", [12, 20]);
|
||||
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.
|
||||
computeAndAssert("foo foo foo \t \t", [ ]);
|
||||
|
||||
// If there is no space to split, force split.
|
||||
computeAndAssert("foooooooooooooo", [ 12 ]);
|
||||
computeAndAssert("fooooooooooooooooooooooooooo", [12, 20]);
|
||||
computeAndAssert("foo bar fooooooooooobooooooo", [8, 16, 24]);
|
||||
computeAndAssert("fooooooooooooooooooooooooooo", [12, 24]);
|
||||
computeAndAssert("foo bar fooooooooooobooooooo", [8, 20]);
|
||||
|
||||
// Basic splitting + tabs.
|
||||
computeAndAssert("foo \t\tbar", [ 6 ]);
|
||||
computeAndAssert("foo \t \tbar", [ 7 ]);
|
||||
|
||||
// Ignore spaces/tabs at beginning of split.
|
||||
computeAndAssert("foo \t \t \t \t bar", [7, 13]); // 14
|
||||
computeAndAssert("foo \t \t \t \t bar", [ 7 ]); // 14
|
||||
|
||||
// Test wrapping for asian characters.
|
||||
computeAndAssert("ぁぁ", [1], 2);
|
||||
computeAndAssert(" ぁぁ", [1, 2], 2);
|
||||
computeAndAssert(" ぁ\tぁ", [1, 3], 2);
|
||||
computeAndAssert(" ぁぁ\tぁ", [1, 4], 4);
|
||||
computeAndAssert(" ぁぁ\tぁ", [2, 4], 4);
|
||||
computeAndAssert("ぁぁ ぁぁ\tぁ", [3, 6], 6);
|
||||
|
||||
// Test wrapping for punctuation.
|
||||
computeAndAssert(" ab.c;ef++", [1, 3, 5, 7, 8], 2);
|
||||
computeAndAssert(" ab.c;ef++", [2, 4, 6, 8], 2);
|
||||
computeAndAssert(" ab.c;ef++", [3, 5, 8], 3);
|
||||
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 indented wrapping
|
||||
EditSession.prototype.$indentedSoftWrap = true;
|
||||
computeAndAssert("foo bar foo bar foo bara foo", [12, 25]);
|
||||
computeAndAssert("fooooooooooooooooooooooooooo", [12, 24]);
|
||||
computeAndAssert("\t\tfoo bar fooooooooooobooooooo", [6, 10, 16, 22, 28]);
|
||||
computeAndAssert("\t\t\tfoo bar fooooooooooobooooooo", [3, 7, 11, 17, 23, 29]);
|
||||
computeAndAssert("\tfoo \t \t \t \t bar", [6, 12]); // 14
|
||||
},
|
||||
|
||||
"test get longest line" : function() {
|
||||
|
|
|
|||
|
|
@ -104,23 +104,24 @@ var Marker = function(parentEl) {
|
|||
this.drawTextMarker = function(stringBuilder, range, clazz, layerConfig, extraStyle) {
|
||||
// selection start
|
||||
var row = range.start.row;
|
||||
var session = this.session;
|
||||
|
||||
var lineRange = new Range(
|
||||
row, range.start.column,
|
||||
row, this.session.getScreenLastRowColumn(row)
|
||||
row, session.getScreenLastRowColumn(row)
|
||||
);
|
||||
this.drawSingleLineMarker(stringBuilder, lineRange, clazz + " ace_start", layerConfig, 1, extraStyle);
|
||||
|
||||
// selection end
|
||||
row = range.end.row;
|
||||
lineRange = new Range(row, this.session.getRowWrapIndent(row), row, range.end.column);
|
||||
lineRange = new Range(row, session.getRowWrapIndent(row), row, range.end.column);
|
||||
this.drawSingleLineMarker(stringBuilder, lineRange, clazz, layerConfig, 0, extraStyle);
|
||||
|
||||
for (row = range.start.row + 1; row < range.end.row; row++) {
|
||||
lineRange.start.row = row;
|
||||
lineRange.start.column = this.session.getRowWrapIndent(row);
|
||||
lineRange.start.column = session.getRowWrapIndent(row);
|
||||
lineRange.end.row = row;
|
||||
lineRange.end.column = this.session.getScreenLastRowColumn(row);
|
||||
lineRange.end.column = session.getScreenLastRowColumn(row);
|
||||
this.drawSingleLineMarker(stringBuilder, lineRange, clazz, layerConfig, 1, extraStyle);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue