Merge pull request #512 from nightwing/pullreq

fixed some bugs with wrapped foldlines
This commit is contained in:
Zef Hemel 2011-11-21 00:01:39 -08:00
commit d1064ae0e1
8 changed files with 79 additions and 46 deletions

View file

@ -1061,9 +1061,11 @@ var EditSession = function(text, mode) {
var row = firstRow;
lastRow = Math.min(lastRow, lines.length - 1);
while (row <= lastRow) {
foldLine = this.getFoldLine(row);
foldLine = this.getFoldLine(row, foldLine);
if (!foldLine) {
tokens = this.$getDisplayTokens(lang.stringTrimRight(lines[row]));
wrapData[row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize);
row ++;
} else {
tokens = [];
foldLine.walk(
@ -1087,16 +1089,13 @@ var EditSession = function(text, mode) {
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)
{
while (tokens.length != 0 && tokens[tokens.length - 1] >= SPACE)
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;
// clamp row before clamping column, for selection on last line
var maxRow = this.getLength() - 1;
var foldLine = this.getNextFoldLine(docRow);
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);
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);
foldLine = null;
}
var splits = [];
if (this.$useWrapMode) {
splits = this.$wrapData[docRow];
var splits = this.$wrapData[docRow];
if (splits) {
column = splits[screenRow - row]
column = splits[screenRow - row];
if(screenRow > row && splits.length) {
docColumn = splits[screenRow - row - 1] || splits[splits.length - 1];
line = line.substring(docColumn);
@ -1435,10 +1438,6 @@ var EditSession = function(text, mode) {
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.
if (this.$useWrapMode) {
if (docColumn >= column) {
@ -1577,24 +1576,29 @@ var EditSession = function(text, mode) {
this.getScreenLength = function() {
var screenRows = 0;
var lastFoldLine = null;
var foldLine = null;
var fold = null;
if (!this.$useWrapMode) {
screenRows = this.getLength();
// Remove the folded lines again.
var foldData = this.$foldData;
for (var i = 0; i < foldData.length; i++) {
foldLine = foldData[i];
screenRows -= foldLine.end.row - foldLine.start.row;
fold = foldData[i];
screenRows -= fold.end.row - fold.start.row;
}
} else {
for (var row = 0; row < this.$wrapData.length; row++) {
if (foldLine = this.getFoldLine(row, lastFoldLine)) {
row = foldLine.end.row;
screenRows += 1;
} else {
screenRows += this.$wrapData[row].length + 1;
var lastRow = this.$wrapData.length;
var row = 0, i = 0;
var fold = this.$foldData[i++];
var foldStart = fold ? fold.start.row :Infinity;
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;
}
}
}

View file

@ -363,6 +363,14 @@ module.exports = {
assert.position(session.screenToDocumentPosition(1, 30), 1, 12);
assert.position(session.screenToDocumentPosition(20, 50), 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() {

View file

@ -852,7 +852,7 @@ var Editor = function(renderer, session) {
var rows = this.$getSelectedRows();
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);
else
range = new Range(
@ -910,14 +910,24 @@ var Editor = function(renderer, session) {
this.$moveLines = function(mover) {
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 selection = this.selection;
selection.setSelectionAnchor(rows.last+linesMoved+1, 0);
selection.$moveSelection(function() {
selection.moveCursorTo(rows.first+linesMoved, 0);
});
if (range) {
range.start.row += linesMoved;
range.end.row += linesMoved;
selection.setSelectionRange(range, reverse);
} else {
selection.setSelectionAnchor(rows.last+linesMoved+1, 0);
selection.$moveSelection(function() {
selection.moveCursorTo(rows.first+linesMoved, 0);
});
}
};
this.$getSelectedRows = function() {

View file

@ -301,7 +301,7 @@ module.exports = {
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 editor = new Editor(new MockRenderer(), session);
@ -311,13 +311,13 @@ module.exports = {
editor.moveLinesDown();
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.moveLinesUp();
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() {

View file

@ -201,6 +201,7 @@ var Text = function(parentEl) {
var foldLine = this.session.getFoldLine(row);
if (foldLine) {
if (foldLine.containsRow(first)) {
first = foldLine.start.row;
break;
} else {
row = foldLine.end.row;
@ -264,12 +265,12 @@ var Text = function(parentEl) {
foldStart = fold ?fold.start.row :Infinity;
while (true) {
if(row > foldStart) {
if (row > foldStart) {
row = fold.end.row+1;
fold = this.session.getNextFoldLine(row, fold);
foldStart = fold ?fold.start.row :Infinity;
}
if(row > lastRow)
if (row > lastRow)
break;
var container = dom.createElement("div");
@ -311,12 +312,12 @@ var Text = function(parentEl) {
foldStart = fold ?fold.start.row :Infinity;
while (true) {
if(row > foldStart) {
if (row > foldStart) {
row = fold.end.row+1;
fold = this.session.getNextFoldLine(row, fold);
foldStart = fold ?fold.start.row :Infinity;
}
if(row > lastRow)
if (row > lastRow)
break;
if (this.$useLineGroups())

View file

@ -67,6 +67,16 @@ var Keys = (function() {
44 : "Print",
45 : "Insert",
46 : "Delete",
96 : "Numpad0",
97 : "Numpad1",
98 : "Numpad2",
99 : "Numpad3",
100: "Numpad4",
101: "Numpad5",
102: "Numpad6",
103: "Numpad7",
104: "Numpad8",
105: "Numpad9",
112: "F1",
113: "F2",
114: "F3",

View file

@ -60,7 +60,7 @@ exports.isOldIE = exports.isIE && exports.isIE < 9;
exports.isGecko = exports.isMozilla = window.controllers && window.navigator.product === "Gecko";
/** 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 */
exports.isOpera = window.opera && Object.prototype.toString.call(window.opera) == "[object Opera]";

View file

@ -222,7 +222,7 @@ Search.SELECTION = 2;
var searchSelection = this.$options.scope == Search.SELECTION;
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 firstColumn = searchSelection ? range.start.column : 0;
@ -284,7 +284,7 @@ Search.SELECTION = 2;
var searchSelection = this.$options.scope == Search.SELECTION;
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 firstColumn = searchSelection ? range.start.column : 0;