Merge remote-tracking branch 'remotes/pull/2187'
This commit is contained in:
commit
0753f9aa12
4 changed files with 63 additions and 14 deletions
|
|
@ -1835,7 +1835,7 @@ var EditSession = function(text, mode) {
|
||||||
TAB_SPACE = 12;
|
TAB_SPACE = 12;
|
||||||
|
|
||||||
|
|
||||||
this.$computeWrapSplits = function(tokens, wrapLimit) {
|
this.$computeWrapSplits = function(tokens, wrapLimit, tabSize) {
|
||||||
if (tokens.length == 0) {
|
if (tokens.length == 0) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
@ -1846,6 +1846,32 @@ var EditSession = function(text, mode) {
|
||||||
|
|
||||||
var isCode = this.$wrapAsCode;
|
var isCode = this.$wrapAsCode;
|
||||||
|
|
||||||
|
var indentSubsequentLines = this.$indentSubsequentLines;
|
||||||
|
|
||||||
|
var maxIndent = wrapLimit > 8 ? Math.floor(wrapLimit / 2) : 0;
|
||||||
|
|
||||||
|
function getIndentation() {
|
||||||
|
var indentation = 0;
|
||||||
|
if (maxIndent === 0)
|
||||||
|
return indentation;
|
||||||
|
if (indentSubsequentLines) {
|
||||||
|
for (var i = 0; i < tokens.length; i++) {
|
||||||
|
var token = tokens[i];
|
||||||
|
if (token == SPACE)
|
||||||
|
indentation += 1;
|
||||||
|
else if (token == TAB)
|
||||||
|
indentation += tabSize;
|
||||||
|
else if (token == TAB_SPACE)
|
||||||
|
continue;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isCode)
|
||||||
|
indentation += tabSize;
|
||||||
|
return Math.min(indentation, maxIndent);
|
||||||
|
}
|
||||||
|
|
||||||
function addSplit(screenPos) {
|
function addSplit(screenPos) {
|
||||||
var displayed = tokens.slice(lastSplit, screenPos);
|
var displayed = tokens.slice(lastSplit, screenPos);
|
||||||
|
|
||||||
|
|
@ -1862,14 +1888,18 @@ var EditSession = function(text, mode) {
|
||||||
len -= 1;
|
len -= 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (splits.length === 0) {
|
||||||
|
indent = getIndentation();
|
||||||
|
splits.indent = indent;
|
||||||
|
}
|
||||||
lastDocSplit += len;
|
lastDocSplit += len;
|
||||||
splits.push(lastDocSplit);
|
splits.push(lastDocSplit);
|
||||||
lastSplit = screenPos;
|
lastSplit = screenPos;
|
||||||
}
|
}
|
||||||
|
var indent = 0;
|
||||||
while (displayLength - lastSplit > wrapLimit) {
|
while (displayLength - lastSplit > wrapLimit - indent) {
|
||||||
// This is, where the split should be.
|
// This is, where the split should be.
|
||||||
var split = lastSplit + wrapLimit;
|
var split = lastSplit + wrapLimit - indent;
|
||||||
|
|
||||||
// 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.
|
||||||
|
|
@ -1957,7 +1987,7 @@ var EditSession = function(text, mode) {
|
||||||
// around -> force a split.
|
// around -> force a split.
|
||||||
if (tokens[split] == CHAR_EXT)
|
if (tokens[split] == CHAR_EXT)
|
||||||
split--;
|
split--;
|
||||||
addSplit(split);
|
addSplit(split - indent);
|
||||||
}
|
}
|
||||||
return splits;
|
return splits;
|
||||||
};
|
};
|
||||||
|
|
@ -2064,6 +2094,17 @@ var EditSession = function(text, mode) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.getRowWrapIndent = function(screenRow) {
|
||||||
|
if (!this.$useWrapMode) {
|
||||||
|
return 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the position (on screen) for the last character in the provided screen row.
|
* Returns the position (on screen) for the last character in the provided screen row.
|
||||||
* @param {Number} screenRow The screen row to check
|
* @param {Number} screenRow The screen row to check
|
||||||
|
|
@ -2201,20 +2242,21 @@ var EditSession = function(text, mode) {
|
||||||
line = this.getLine(docRow);
|
line = this.getLine(docRow);
|
||||||
foldLine = null;
|
foldLine = null;
|
||||||
}
|
}
|
||||||
|
var wrapIndent = 0;
|
||||||
if (this.$useWrapMode) {
|
if (this.$useWrapMode) {
|
||||||
var splits = this.$wrapData[docRow];
|
var splits = this.$wrapData[docRow];
|
||||||
if (splits) {
|
if (splits) {
|
||||||
var splitIndex = Math.floor(screenRow - row);
|
var splitIndex = Math.floor(screenRow - row);
|
||||||
column = splits[splitIndex];
|
column = splits[splitIndex];
|
||||||
if(splitIndex > 0 && splits.length) {
|
if(splitIndex > 0 && splits.length) {
|
||||||
|
wrapIndent = splits.indent;
|
||||||
docColumn = splits[splitIndex - 1] || splits[splits.length - 1];
|
docColumn = splits[splitIndex - 1] || splits[splits.length - 1];
|
||||||
line = line.substring(docColumn);
|
line = line.substring(docColumn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
docColumn += this.$getStringScreenWidth(line, screenColumn)[1];
|
docColumn += this.$getStringScreenWidth(line, screenColumn - wrapIndent)[1];
|
||||||
|
|
||||||
// We remove one character at the end so that the docColumn
|
// We remove one character at the end so that the docColumn
|
||||||
// position returned is not associated to the next row on the screen.
|
// position returned is not associated to the next row on the screen.
|
||||||
|
|
@ -2306,6 +2348,7 @@ var EditSession = function(text, mode) {
|
||||||
textLine = this.getLine(docRow).substring(0, docColumn);
|
textLine = this.getLine(docRow).substring(0, docColumn);
|
||||||
foldStartRow = docRow;
|
foldStartRow = docRow;
|
||||||
}
|
}
|
||||||
|
var wrapIndent = 0;
|
||||||
// Clamp textLine if in wrapMode.
|
// Clamp textLine if in wrapMode.
|
||||||
if (this.$useWrapMode) {
|
if (this.$useWrapMode) {
|
||||||
var wrapRow = this.$wrapData[foldStartRow];
|
var wrapRow = this.$wrapData[foldStartRow];
|
||||||
|
|
@ -2318,12 +2361,13 @@ var EditSession = function(text, mode) {
|
||||||
textLine = textLine.substring(
|
textLine = textLine.substring(
|
||||||
wrapRow[screenRowOffset - 1] || 0, textLine.length
|
wrapRow[screenRowOffset - 1] || 0, textLine.length
|
||||||
);
|
);
|
||||||
|
wrapIndent = screenRowOffset > 0 ? wrapRow.indent : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
row: screenRow,
|
row: screenRow,
|
||||||
column: this.$getStringScreenWidth(textLine)[0]
|
column: wrapIndent + this.$getStringScreenWidth(textLine)[0]
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -2503,6 +2547,7 @@ config.defineOptions(EditSession.prototype, "session", {
|
||||||
},
|
},
|
||||||
initialValue: "auto"
|
initialValue: "auto"
|
||||||
},
|
},
|
||||||
|
indentSubsequentLines: {initialValue: true},
|
||||||
firstLineNumber: {
|
firstLineNumber: {
|
||||||
set: function() {this._signal("changeBreakpoint");},
|
set: function() {this._signal("changeBreakpoint");},
|
||||||
initialValue: 1
|
initialValue: 1
|
||||||
|
|
|
||||||
|
|
@ -280,7 +280,7 @@ module.exports = {
|
||||||
session.setUseWrapMode(true);
|
session.setUseWrapMode(true);
|
||||||
session.setWrapLimitRange(12, 12);
|
session.setWrapLimitRange(12, 12);
|
||||||
session.adjustWrapLimit(80);
|
session.adjustWrapLimit(80);
|
||||||
|
session.setOption("wrapMethod", "text");
|
||||||
assert.position(session.documentToScreenPosition(0, 11), 0, 11);
|
assert.position(session.documentToScreenPosition(0, 11), 0, 11);
|
||||||
assert.position(session.documentToScreenPosition(0, 12), 1, 0);
|
assert.position(session.documentToScreenPosition(0, 12), 1, 0);
|
||||||
},
|
},
|
||||||
|
|
@ -388,26 +388,27 @@ module.exports = {
|
||||||
}
|
}
|
||||||
|
|
||||||
EditSession.prototype.$wrapAsCode = true;
|
EditSession.prototype.$wrapAsCode = true;
|
||||||
|
EditSession.prototype.$indentSubsequentLines = false;
|
||||||
// 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", [ 12 ]); // 14 if we enable
|
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, 20]);
|
||||||
|
|
||||||
// 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.
|
||||||
computeAndAssert("foo foo foo \t \t", [ ]);
|
computeAndAssert("foo foo foo \t \t", [ ]);
|
||||||
|
|
||||||
// If there is no space to split, force split.
|
// If there is no space to split, force split.
|
||||||
computeAndAssert("foooooooooooooo", [ 12 ]);
|
computeAndAssert("foooooooooooooo", [ 12 ]);
|
||||||
computeAndAssert("fooooooooooooooooooooooooooo", [12, 24]);
|
computeAndAssert("fooooooooooooooooooooooooooo", [12, 20]);
|
||||||
computeAndAssert("foo bar fooooooooooobooooooo", [8, 20]);
|
computeAndAssert("foo bar fooooooooooobooooooo", [8, 16, 24]);
|
||||||
|
|
||||||
// Basic splitting + tabs.
|
// Basic splitting + tabs.
|
||||||
computeAndAssert("foo \t\tbar", [ 6 ]);
|
computeAndAssert("foo \t\tbar", [ 6 ]);
|
||||||
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", [ 7 ]); // 14
|
computeAndAssert("foo \t \t \t \t bar", [7, 13]); // 14
|
||||||
|
|
||||||
// Test wrapping for asian characters.
|
// Test wrapping for asian characters.
|
||||||
computeAndAssert("ぁぁ", [1], 2);
|
computeAndAssert("ぁぁ", [1], 2);
|
||||||
|
|
|
||||||
|
|
@ -113,11 +113,12 @@ var Marker = function(parentEl) {
|
||||||
|
|
||||||
// selection end
|
// selection end
|
||||||
row = range.end.row;
|
row = range.end.row;
|
||||||
lineRange = new Range(row, 0, row, range.end.column);
|
lineRange = new Range(row, this.session.getRowWrapIndent(row), row, range.end.column);
|
||||||
this.drawSingleLineMarker(stringBuilder, lineRange, clazz, layerConfig, 0, extraStyle);
|
this.drawSingleLineMarker(stringBuilder, lineRange, clazz, layerConfig, 0, extraStyle);
|
||||||
|
|
||||||
for (row = range.start.row + 1; row < range.end.row; row++) {
|
for (row = range.start.row + 1; row < range.end.row; row++) {
|
||||||
lineRange.start.row = row;
|
lineRange.start.row = row;
|
||||||
|
lineRange.start.column = this.session.getRowWrapIndent(row);
|
||||||
lineRange.end.row = row;
|
lineRange.end.row = row;
|
||||||
lineRange.end.column = this.session.getScreenLastRowColumn(row);
|
lineRange.end.column = this.session.getScreenLastRowColumn(row);
|
||||||
this.drawSingleLineMarker(stringBuilder, lineRange, clazz, layerConfig, 1, extraStyle);
|
this.drawSingleLineMarker(stringBuilder, lineRange, clazz, layerConfig, 1, extraStyle);
|
||||||
|
|
|
||||||
|
|
@ -420,6 +420,8 @@ var Text = function(parentEl) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stringBuilder.push(lang.stringRepeat("\xa0", splits.indent));
|
||||||
|
|
||||||
split ++;
|
split ++;
|
||||||
screenColumn = 0;
|
screenColumn = 0;
|
||||||
splitChars = splits[split] || Number.MAX_VALUE;
|
splitChars = splits[split] || Number.MAX_VALUE;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue