Merge pull request #512 from nightwing/pullreq
fixed some bugs with wrapped foldlines
This commit is contained in:
commit
d1064ae0e1
8 changed files with 79 additions and 46 deletions
|
|
@ -1061,9 +1061,11 @@ var EditSession = function(text, mode) {
|
||||||
var row = firstRow;
|
var row = firstRow;
|
||||||
lastRow = Math.min(lastRow, lines.length - 1);
|
lastRow = Math.min(lastRow, lines.length - 1);
|
||||||
while (row <= lastRow) {
|
while (row <= lastRow) {
|
||||||
foldLine = this.getFoldLine(row);
|
foldLine = this.getFoldLine(row, foldLine);
|
||||||
if (!foldLine) {
|
if (!foldLine) {
|
||||||
tokens = this.$getDisplayTokens(lang.stringTrimRight(lines[row]));
|
tokens = this.$getDisplayTokens(lang.stringTrimRight(lines[row]));
|
||||||
|
wrapData[row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
|
||||||
|
row ++;
|
||||||
} else {
|
} else {
|
||||||
tokens = [];
|
tokens = [];
|
||||||
foldLine.walk(
|
foldLine.walk(
|
||||||
|
|
@ -1087,16 +1089,13 @@ var EditSession = function(text, mode) {
|
||||||
lines[foldLine.end.row].length + 1
|
lines[foldLine.end.row].length + 1
|
||||||
);
|
);
|
||||||
// Remove spaces/tabs from the back of the token array.
|
// Remove spaces/tabs from the back of the token array.
|
||||||
while (tokens.length != 0
|
while (tokens.length != 0 && tokens[tokens.length - 1] >= SPACE)
|
||||||
&& tokens[tokens.length - 1] >= SPACE)
|
|
||||||
{
|
|
||||||
tokens.pop();
|
tokens.pop();
|
||||||
}
|
|
||||||
}
|
|
||||||
wrapData[row] =
|
|
||||||
this.$computeWrapSplits(tokens, wrapLimit, tabSize);
|
|
||||||
|
|
||||||
row = this.getRowFoldEnd(row) + 1;
|
wrapData[foldLine.start.row]
|
||||||
|
= this.$computeWrapSplits(tokens, wrapLimit, tabSize);
|
||||||
|
row = foldLine.end.row + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1387,9 +1386,7 @@ var EditSession = function(text, mode) {
|
||||||
}
|
}
|
||||||
var doCache = !rowCache.length || i == rowCache.length;
|
var doCache = !rowCache.length || i == rowCache.length;
|
||||||
|
|
||||||
// clamp row before clamping column, for selection on last line
|
|
||||||
var maxRow = this.getLength() - 1;
|
var maxRow = this.getLength() - 1;
|
||||||
|
|
||||||
var foldLine = this.getNextFoldLine(docRow);
|
var foldLine = this.getNextFoldLine(docRow);
|
||||||
var foldStart = foldLine ? foldLine.start.row : Infinity;
|
var foldStart = foldLine ? foldLine.start.row : Infinity;
|
||||||
|
|
||||||
|
|
@ -1414,18 +1411,24 @@ var EditSession = function(text, mode) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foldLine && foldLine.start.row <= docRow)
|
if (foldLine && foldLine.start.row <= docRow) {
|
||||||
line = this.getFoldDisplayLine(foldLine);
|
line = this.getFoldDisplayLine(foldLine);
|
||||||
else {
|
docRow = foldLine.start.row;
|
||||||
|
} else if (row + rowLength <= screenRow || docRow > maxRow) {
|
||||||
|
// clip at the end of the document
|
||||||
|
return {
|
||||||
|
row: maxRow,
|
||||||
|
column: this.getLine(maxRow).length
|
||||||
|
}
|
||||||
|
} else {
|
||||||
line = this.getLine(docRow);
|
line = this.getLine(docRow);
|
||||||
foldLine = null;
|
foldLine = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var splits = [];
|
|
||||||
if (this.$useWrapMode) {
|
if (this.$useWrapMode) {
|
||||||
splits = this.$wrapData[docRow];
|
var splits = this.$wrapData[docRow];
|
||||||
if (splits) {
|
if (splits) {
|
||||||
column = splits[screenRow - row]
|
column = splits[screenRow - row];
|
||||||
if(screenRow > row && splits.length) {
|
if(screenRow > row && splits.length) {
|
||||||
docColumn = splits[screenRow - row - 1] || splits[splits.length - 1];
|
docColumn = splits[screenRow - row - 1] || splits[splits.length - 1];
|
||||||
line = line.substring(docColumn);
|
line = line.substring(docColumn);
|
||||||
|
|
@ -1435,10 +1438,6 @@ var EditSession = function(text, mode) {
|
||||||
|
|
||||||
docColumn += this.$getStringScreenWidth(line, screenColumn)[1];
|
docColumn += this.$getStringScreenWidth(line, screenColumn)[1];
|
||||||
|
|
||||||
// clip row at the end of the document
|
|
||||||
if (row + splits.length < screenRow)
|
|
||||||
docColumn = Number.MAX_VALUE;
|
|
||||||
|
|
||||||
// Need to do some clamping action here.
|
// Need to do some clamping action here.
|
||||||
if (this.$useWrapMode) {
|
if (this.$useWrapMode) {
|
||||||
if (docColumn >= column) {
|
if (docColumn >= column) {
|
||||||
|
|
@ -1577,24 +1576,29 @@ var EditSession = function(text, mode) {
|
||||||
|
|
||||||
this.getScreenLength = function() {
|
this.getScreenLength = function() {
|
||||||
var screenRows = 0;
|
var screenRows = 0;
|
||||||
var lastFoldLine = null;
|
var fold = null;
|
||||||
var foldLine = null;
|
|
||||||
if (!this.$useWrapMode) {
|
if (!this.$useWrapMode) {
|
||||||
screenRows = this.getLength();
|
screenRows = this.getLength();
|
||||||
|
|
||||||
// Remove the folded lines again.
|
// Remove the folded lines again.
|
||||||
var foldData = this.$foldData;
|
var foldData = this.$foldData;
|
||||||
for (var i = 0; i < foldData.length; i++) {
|
for (var i = 0; i < foldData.length; i++) {
|
||||||
foldLine = foldData[i];
|
fold = foldData[i];
|
||||||
screenRows -= foldLine.end.row - foldLine.start.row;
|
screenRows -= fold.end.row - fold.start.row;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (var row = 0; row < this.$wrapData.length; row++) {
|
var lastRow = this.$wrapData.length;
|
||||||
if (foldLine = this.getFoldLine(row, lastFoldLine)) {
|
var row = 0, i = 0;
|
||||||
row = foldLine.end.row;
|
var fold = this.$foldData[i++];
|
||||||
screenRows += 1;
|
var foldStart = fold ? fold.start.row :Infinity;
|
||||||
} else {
|
|
||||||
screenRows += this.$wrapData[row].length + 1;
|
while (row < lastRow) {
|
||||||
|
screenRows += this.$wrapData[row].length + 1;
|
||||||
|
row ++;
|
||||||
|
if (row > foldStart) {
|
||||||
|
row = fold.end.row+1;
|
||||||
|
fold = this.$foldData[i++];
|
||||||
|
foldStart = fold ?fold.start.row :Infinity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -363,6 +363,14 @@ module.exports = {
|
||||||
assert.position(session.screenToDocumentPosition(1, 30), 1, 12);
|
assert.position(session.screenToDocumentPosition(1, 30), 1, 12);
|
||||||
assert.position(session.screenToDocumentPosition(20, 50), 1, 12);
|
assert.position(session.screenToDocumentPosition(20, 50), 1, 12);
|
||||||
assert.position(session.screenToDocumentPosition(20, 5), 1, 12);
|
assert.position(session.screenToDocumentPosition(20, 5), 1, 12);
|
||||||
|
|
||||||
|
// and the same for folded rows
|
||||||
|
session.addFold("...", new Range(0,1,1,3));
|
||||||
|
assert.position(session.screenToDocumentPosition(1, 2), 1, 12);
|
||||||
|
// for wrapped rows
|
||||||
|
session.setUseWrapMode(true);
|
||||||
|
session.setWrapLimitRange(5,5);
|
||||||
|
assert.position(session.screenToDocumentPosition(4, 1), 1, 12);
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: wrapLine split function" : function() {
|
"test: wrapLine split function" : function() {
|
||||||
|
|
|
||||||
|
|
@ -852,7 +852,7 @@ var Editor = function(renderer, session) {
|
||||||
|
|
||||||
var rows = this.$getSelectedRows();
|
var rows = this.$getSelectedRows();
|
||||||
var range;
|
var range;
|
||||||
if (rows.last == 0 || rows.last+1 < this.session.getLength())
|
if (rows.first == 0 || rows.last+1 < this.session.getLength())
|
||||||
range = new Range(rows.first, 0, rows.last+1, 0);
|
range = new Range(rows.first, 0, rows.last+1, 0);
|
||||||
else
|
else
|
||||||
range = new Range(
|
range = new Range(
|
||||||
|
|
@ -910,14 +910,24 @@ var Editor = function(renderer, session) {
|
||||||
|
|
||||||
this.$moveLines = function(mover) {
|
this.$moveLines = function(mover) {
|
||||||
var rows = this.$getSelectedRows();
|
var rows = this.$getSelectedRows();
|
||||||
|
var selection = this.selection;
|
||||||
|
if (!selection.isMultiLine()) {
|
||||||
|
var range = selection.getRange();
|
||||||
|
var reverse = selection.isBackwards();
|
||||||
|
}
|
||||||
|
|
||||||
var linesMoved = mover.call(this, rows.first, rows.last);
|
var linesMoved = mover.call(this, rows.first, rows.last);
|
||||||
|
|
||||||
var selection = this.selection;
|
if (range) {
|
||||||
selection.setSelectionAnchor(rows.last+linesMoved+1, 0);
|
range.start.row += linesMoved;
|
||||||
selection.$moveSelection(function() {
|
range.end.row += linesMoved;
|
||||||
selection.moveCursorTo(rows.first+linesMoved, 0);
|
selection.setSelectionRange(range, reverse);
|
||||||
});
|
} else {
|
||||||
|
selection.setSelectionAnchor(rows.last+linesMoved+1, 0);
|
||||||
|
selection.$moveSelection(function() {
|
||||||
|
selection.moveCursorTo(rows.first+linesMoved, 0);
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$getSelectedRows = function() {
|
this.$getSelectedRows = function() {
|
||||||
|
|
|
||||||
|
|
@ -301,7 +301,7 @@ module.exports = {
|
||||||
assert.position(editor.getSelection().getSelectionLead(), 0, 0);
|
assert.position(editor.getSelection().getSelectionLead(), 0, 0);
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: move line without active selection should move cursor to start of the moved line" : function()
|
"test: move line without active selection should not move cursor relative to the moved line" : function()
|
||||||
{
|
{
|
||||||
var session = new EditSession(["11", "22", "33", "44"].join("\n"));
|
var session = new EditSession(["11", "22", "33", "44"].join("\n"));
|
||||||
var editor = new Editor(new MockRenderer(), session);
|
var editor = new Editor(new MockRenderer(), session);
|
||||||
|
|
@ -311,13 +311,13 @@ module.exports = {
|
||||||
|
|
||||||
editor.moveLinesDown();
|
editor.moveLinesDown();
|
||||||
assert.equal(["11", "33", "22", "44"].join("\n"), session.toString());
|
assert.equal(["11", "33", "22", "44"].join("\n"), session.toString());
|
||||||
assert.position(editor.getCursorPosition(), 2, 0);
|
assert.position(editor.getCursorPosition(), 2, 1);
|
||||||
|
|
||||||
editor.clearSelection();
|
editor.clearSelection();
|
||||||
|
|
||||||
editor.moveLinesUp();
|
editor.moveLinesUp();
|
||||||
assert.equal(["11", "22", "33", "44"].join("\n"), session.toString());
|
assert.equal(["11", "22", "33", "44"].join("\n"), session.toString());
|
||||||
assert.position(editor.getCursorPosition(), 1, 0);
|
assert.position(editor.getCursorPosition(), 1, 1);
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: copy lines down should select lines and place cursor at the selection start" : function() {
|
"test: copy lines down should select lines and place cursor at the selection start" : function() {
|
||||||
|
|
|
||||||
|
|
@ -201,6 +201,7 @@ var Text = function(parentEl) {
|
||||||
var foldLine = this.session.getFoldLine(row);
|
var foldLine = this.session.getFoldLine(row);
|
||||||
if (foldLine) {
|
if (foldLine) {
|
||||||
if (foldLine.containsRow(first)) {
|
if (foldLine.containsRow(first)) {
|
||||||
|
first = foldLine.start.row;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
row = foldLine.end.row;
|
row = foldLine.end.row;
|
||||||
|
|
@ -264,12 +265,12 @@ var Text = function(parentEl) {
|
||||||
foldStart = fold ?fold.start.row :Infinity;
|
foldStart = fold ?fold.start.row :Infinity;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if(row > foldStart) {
|
if (row > foldStart) {
|
||||||
row = fold.end.row+1;
|
row = fold.end.row+1;
|
||||||
fold = this.session.getNextFoldLine(row, fold);
|
fold = this.session.getNextFoldLine(row, fold);
|
||||||
foldStart = fold ?fold.start.row :Infinity;
|
foldStart = fold ?fold.start.row :Infinity;
|
||||||
}
|
}
|
||||||
if(row > lastRow)
|
if (row > lastRow)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
var container = dom.createElement("div");
|
var container = dom.createElement("div");
|
||||||
|
|
@ -311,12 +312,12 @@ var Text = function(parentEl) {
|
||||||
foldStart = fold ?fold.start.row :Infinity;
|
foldStart = fold ?fold.start.row :Infinity;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if(row > foldStart) {
|
if (row > foldStart) {
|
||||||
row = fold.end.row+1;
|
row = fold.end.row+1;
|
||||||
fold = this.session.getNextFoldLine(row, fold);
|
fold = this.session.getNextFoldLine(row, fold);
|
||||||
foldStart = fold ?fold.start.row :Infinity;
|
foldStart = fold ?fold.start.row :Infinity;
|
||||||
}
|
}
|
||||||
if(row > lastRow)
|
if (row > lastRow)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (this.$useLineGroups())
|
if (this.$useLineGroups())
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,16 @@ var Keys = (function() {
|
||||||
44 : "Print",
|
44 : "Print",
|
||||||
45 : "Insert",
|
45 : "Insert",
|
||||||
46 : "Delete",
|
46 : "Delete",
|
||||||
|
96 : "Numpad0",
|
||||||
|
97 : "Numpad1",
|
||||||
|
98 : "Numpad2",
|
||||||
|
99 : "Numpad3",
|
||||||
|
100: "Numpad4",
|
||||||
|
101: "Numpad5",
|
||||||
|
102: "Numpad6",
|
||||||
|
103: "Numpad7",
|
||||||
|
104: "Numpad8",
|
||||||
|
105: "Numpad9",
|
||||||
112: "F1",
|
112: "F1",
|
||||||
113: "F2",
|
113: "F2",
|
||||||
114: "F3",
|
114: "F3",
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ exports.isOldIE = exports.isIE && exports.isIE < 9;
|
||||||
exports.isGecko = exports.isMozilla = window.controllers && window.navigator.product === "Gecko";
|
exports.isGecko = exports.isMozilla = window.controllers && window.navigator.product === "Gecko";
|
||||||
|
|
||||||
/** oldGecko == rev < 2.0 **/
|
/** oldGecko == rev < 2.0 **/
|
||||||
exports.isOldGecko = exports.isGecko && /rv\:1/.test(navigator.userAgent);
|
exports.isOldGecko = exports.isGecko && parseInt((navigator.userAgent.match(/rv\:(\d+)/)||[])[1]) < 4;
|
||||||
|
|
||||||
/** Is this Opera */
|
/** Is this Opera */
|
||||||
exports.isOpera = window.opera && Object.prototype.toString.call(window.opera) == "[object Opera]";
|
exports.isOpera = window.opera && Object.prototype.toString.call(window.opera) == "[object Opera]";
|
||||||
|
|
|
||||||
|
|
@ -222,7 +222,7 @@ Search.SELECTION = 2;
|
||||||
var searchSelection = this.$options.scope == Search.SELECTION;
|
var searchSelection = this.$options.scope == Search.SELECTION;
|
||||||
|
|
||||||
var range = this.$options.range || session.getSelection().getRange();
|
var range = this.$options.range || session.getSelection().getRange();
|
||||||
var start = this.$options.start || session.getSelection().getCursor();
|
var start = this.$options.start || range[searchSelection ? "start" : "end"];
|
||||||
|
|
||||||
var firstRow = searchSelection ? range.start.row : 0;
|
var firstRow = searchSelection ? range.start.row : 0;
|
||||||
var firstColumn = searchSelection ? range.start.column : 0;
|
var firstColumn = searchSelection ? range.start.column : 0;
|
||||||
|
|
@ -284,7 +284,7 @@ Search.SELECTION = 2;
|
||||||
var searchSelection = this.$options.scope == Search.SELECTION;
|
var searchSelection = this.$options.scope == Search.SELECTION;
|
||||||
|
|
||||||
var range = this.$options.range || session.getSelection().getRange();
|
var range = this.$options.range || session.getSelection().getRange();
|
||||||
var start = this.$options.start || session.getSelection().getCursor();
|
var start = this.$options.start || range[searchSelection ? "end" : "start"];
|
||||||
|
|
||||||
var firstRow = searchSelection ? range.start.row : 0;
|
var firstRow = searchSelection ? range.start.row : 0;
|
||||||
var firstColumn = searchSelection ? range.start.column : 0;
|
var firstColumn = searchSelection ? range.start.column : 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue