Fixed some bugs and unit tests pass again

This commit is contained in:
Julian Viereck 2011-03-19 07:34:35 +08:00 • committed by Fabian Jakobs
commit e8333c2df2
3 changed files with 42 additions and 39 deletions

View file

@ -896,9 +896,9 @@ var EditSession = function(text, mode) {
// and multipleWidth characters. // and multipleWidth characters.
var len = displayed.length; var len = displayed.length;
displayed.join(""). displayed.join("").
// Get all the tabs. // Get all the tabs spaces.
replace(/4/g, function(m) { replace(/5/g, function(m) {
len -= tabSize - 1; len -= 1;
}). }).
// Get all the multipleWidth characters. // Get all the multipleWidth characters.
replace(/2/g, function(m) { replace(/2/g, function(m) {
@ -950,8 +950,8 @@ var EditSession = function(text, mode) {
var c = str.charCodeAt(i); var c = str.charCodeAt(i);
// Tab // Tab
if (c == 9) { if (c == 9) {
arr.push(TAB);
tabSize = this.getScreenTabSize(arr.length); tabSize = this.getScreenTabSize(arr.length);
arr.push(TAB);
for (var n = 1; n < tabSize; n++) { for (var n = 1; n < tabSize; n++) {
arr.push(TAB_SPACE); arr.push(TAB_SPACE);
} }
@ -1173,7 +1173,7 @@ var EditSession = function(text, mode) {
docColumn -= 1; docColumn -= 1;
} }
} else { } else {
screenColumn += 2; screenColumn += 1;
remaining -= 1; remaining -= 1;
} }
} else { } else {

View file

@ -382,19 +382,14 @@ var Selection = function(session) {
}; };
this.moveCursorBy = function(rows, chars) { this.moveCursorBy = function(rows, chars) {
if (this.session.getUseWrapMode()) { var screenPos = this.session.documentToScreenPosition(
var screenPos = this.session.documentToScreenPosition( this.selectionLead.row,
this.selectionLead.row, this.selectionLead.column
this.selectionLead.column );
); var screenCol = (chars == 0 && this.$desiredColumn) || screenPos.column;
var screenCol = (chars == 0 && this.$desiredColumn) || screenPos.column; var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenCol);
var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenCol);
this.moveCursorTo(docPos.row, docPos.column + chars, chars == 0); this.moveCursorTo(docPos.row, docPos.column + chars, chars == 0);
} else {
var docColumn = (chars == 0 && this.$desiredColumn) || this.selectionLead.column;
this.moveCursorTo(this.selectionLead.row + rows, docColumn + chars, chars == 0);
}
}; };
this.moveCursorToPosition = function(position) { this.moveCursorToPosition = function(position) {
@ -408,11 +403,9 @@ var Selection = function(session) {
}; };
this.moveCursorToScreen = function(row, column, preventUpdateDesiredColumn) { this.moveCursorToScreen = function(row, column, preventUpdateDesiredColumn) {
if (this.session.getUseWrapMode()) { var pos = this.session.screenToDocumentPosition(row, column);
var pos = this.session.screenToDocumentPosition(row, column); row = pos.row;
row = pos.row; column = pos.column;
column = pos.column;
}
this.moveCursorTo(row, column, preventUpdateDesiredColumn); this.moveCursorTo(row, column, preventUpdateDesiredColumn);
}; };

View file

@ -140,18 +140,19 @@ var Test = {
assert.equal(session.documentToScreenColumn(0, 0), 0); assert.equal(session.documentToScreenColumn(0, 0), 0);
assert.equal(session.documentToScreenColumn(0, 4), 4); assert.equal(session.documentToScreenColumn(0, 4), 4);
assert.equal(session.documentToScreenColumn(0, 5), 5); assert.equal(session.documentToScreenColumn(0, 5), 5);
assert.equal(session.documentToScreenColumn(0, 6), 9); assert.equal(session.documentToScreenColumn(0, 6), 8);
assert.equal(session.documentToScreenColumn(0, 12), 15); assert.equal(session.documentToScreenColumn(0, 12), 14);
assert.equal(session.documentToScreenColumn(0, 13), 19); assert.equal(session.documentToScreenColumn(0, 13), 16);
session.setTabSize(2); session.setTabSize(2);
assert.equal(session.documentToScreenColumn(0, 0), 0); assert.equal(session.documentToScreenColumn(0, 0), 0);
assert.equal(session.documentToScreenColumn(0, 4), 4); assert.equal(session.documentToScreenColumn(0, 4), 4);
assert.equal(session.documentToScreenColumn(0, 5), 5); assert.equal(session.documentToScreenColumn(0, 5), 5);
assert.equal(session.documentToScreenColumn(0, 6), 7); assert.equal(session.documentToScreenColumn(0, 6), 6);
assert.equal(session.documentToScreenColumn(0, 12), 13); assert.equal(session.documentToScreenColumn(0, 7), 7);
assert.equal(session.documentToScreenColumn(0, 13), 15); assert.equal(session.documentToScreenColumn(0, 12), 12);
assert.equal(session.documentToScreenColumn(0, 13), 14);
}, },
"test: convert document to screen coordinates with leading tabs": function() { "test: convert document to screen coordinates with leading tabs": function() {
@ -194,10 +195,20 @@ var Test = {
assert.equal(session.screenToDocumentColumn(0, 5), 5); assert.equal(session.screenToDocumentColumn(0, 5), 5);
assert.equal(session.screenToDocumentColumn(0, 6), 5); assert.equal(session.screenToDocumentColumn(0, 6), 5);
assert.equal(session.screenToDocumentColumn(0, 7), 5); assert.equal(session.screenToDocumentColumn(0, 7), 5);
assert.equal(session.screenToDocumentColumn(0, 8), 5); assert.equal(session.screenToDocumentColumn(0, 8), 6);
assert.equal(session.screenToDocumentColumn(0, 9), 6); assert.equal(session.screenToDocumentColumn(0, 9), 7);
assert.equal(session.screenToDocumentColumn(0, 15), 12); assert.equal(session.screenToDocumentColumn(0, 15), 12);
assert.equal(session.screenToDocumentColumn(0, 19), 13); assert.equal(session.screenToDocumentColumn(0, 19), 16);
session.setTabSize(2);
assert.equal(session.screenToDocumentColumn(0, 0), 0);
assert.equal(session.screenToDocumentColumn(0, 4), 4);
assert.equal(session.screenToDocumentColumn(0, 5), 5);
assert.equal(session.screenToDocumentColumn(0, 6), 6);
assert.equal(session.screenToDocumentColumn(0, 12), 12);
assert.equal(session.screenToDocumentColumn(0, 13), 12);
assert.equal(session.screenToDocumentColumn(0, 14), 13);
}, },
"test: screenToDocument with soft wrap and multi byte characters": function() { "test: screenToDocument with soft wrap and multi byte characters": function() {
@ -227,13 +238,12 @@ var Test = {
"test: wrapLine split function" : function() { "test: wrapLine split function" : function() {
var splits; var splits;
var computeWrapSplits = EditSession.prototype.$computeWrapSplits;
var c = 0; var c = 0;
function computeAndAssert(line, assertEqual, wrapLimit, tabSize) { function computeAndAssert(line, assertEqual, wrapLimit, tabSize) {
wrapLimit = wrapLimit || 12; wrapLimit = wrapLimit || 12;
tabSize = tabSize || 4; tabSize = tabSize || 4;
splits = computeWrapSplits.call(EditSession.prototype, line, wrapLimit, tabSize); var splits = EditSession.prototype.$computeWrapSplits(line, wrapLimit, tabSize);
// console.log("String:", line, "Result:", splits, "Expected:", assertEqual); // console.log("String:", line, "Result:", splits, "Expected:", assertEqual);
assert.ok(splits.length == assertEqual.length); assert.ok(splits.length == assertEqual.length);
for (var i = 0; i < splits.length; i++) { for (var i = 0; i < splits.length; i++) {
@ -297,7 +307,7 @@ var Test = {
assert.equal(session.$getDisplayTokens("\t").length, 4); assert.equal(session.$getDisplayTokens("\t").length, 4);
assert.equal(session.$getDisplayTokens("abc").length, 3); assert.equal(session.$getDisplayTokens("abc").length, 3);
assert.equal(session.$getDisplayTokens("abc\t").length, 7); assert.equal(session.$getDisplayTokens("abc\t").length, 4);
}, },
"test issue 83": function() { "test issue 83": function() {