Fix a lot of screen dimension calculation functions.
This commit is contained in:
parent
155115035c
commit
af6dcc2253
1 changed files with 63 additions and 48 deletions
|
|
@ -471,11 +471,25 @@ var EditSession = function(text, mode) {
|
||||||
var longestScreenLine = 0;
|
var longestScreenLine = 0;
|
||||||
|
|
||||||
for ( var i = 0; i < lines.length; i++) {
|
for ( var i = 0; i < lines.length; i++) {
|
||||||
var line = lines[i],
|
var foldLine = this.getFoldLine(i),
|
||||||
len = line.length,
|
line, len;
|
||||||
screenLen = this.$getStringScreenWidth(line)[0];
|
|
||||||
|
line = lines[i];
|
||||||
|
if (foldLine) {
|
||||||
|
var end = foldLine.range.end;
|
||||||
|
line = this.getFoldDisplayLine(foldLine, end.row, line.length);
|
||||||
|
// Continue after the foldLine.end.row. All the lines in
|
||||||
|
// between are folded.
|
||||||
|
i = end.row;
|
||||||
|
}
|
||||||
|
len = line.length;
|
||||||
longestLine = Math.max(longestLine, len);
|
longestLine = Math.max(longestLine, len);
|
||||||
longestScreenLine = Math.max(longestScreenLine, screenLen);
|
if (!this.$useWrapMode) {
|
||||||
|
longestScreenLine = Math.max(
|
||||||
|
longestScreenLine,
|
||||||
|
this.$getStringScreenWidth(line)[0]
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.width = longestLine;
|
this.width = longestLine;
|
||||||
|
|
||||||
|
|
@ -875,7 +889,7 @@ var EditSession = function(text, mode) {
|
||||||
start = e.data.range.start,
|
start = e.data.range.start,
|
||||||
end = e.data.range.end;
|
end = e.data.range.end;
|
||||||
|
|
||||||
console.log("onChange", action, e.data.range + "");
|
// console.log("onChange", action, e.data.range + "");
|
||||||
|
|
||||||
if (action.indexOf("Lines") != -1) {
|
if (action.indexOf("Lines") != -1) {
|
||||||
if (action == "insertLines") {
|
if (action == "insertLines") {
|
||||||
|
|
@ -1147,34 +1161,16 @@ var EditSession = function(text, mode) {
|
||||||
return this.getRowLength(row) * config.lineHeight;
|
return this.getRowLength(row) * config.lineHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getScreenLastRowColumn = function(screenRow, returnDocPosition) {
|
this.getScreenLastRowColumn = function(screenRow) {
|
||||||
if (!this.$useWrapMode) {
|
// Note: This won't work if someone has more then
|
||||||
return this.$getStringScreenWidth(this.getLine(screenRow))[0];
|
// 1.7976931348623158e+307 characters in one row. But I think we can
|
||||||
}
|
// live with this limitation ;)
|
||||||
|
return this.screenToDocumentColumn(screenRow, Number.MAX_VALUE / 10)
|
||||||
var rowData = this.$screenToDocumentRow(screenRow);
|
|
||||||
var docRow = rowData[0],
|
|
||||||
row = rowData[1];
|
|
||||||
|
|
||||||
var start, end;
|
|
||||||
if (this.$wrapData[docRow][row]) {
|
|
||||||
start = (this.$wrapData[docRow][row - 1] || 0);
|
|
||||||
end = this.$wrapData[docRow][row];
|
|
||||||
returnDocPosition && end--;
|
|
||||||
} else {
|
|
||||||
end = this.getLine(docRow).length;
|
|
||||||
start = (this.$wrapData[docRow][row - 1] || 0);
|
|
||||||
}
|
|
||||||
if (!returnDocPosition) {
|
|
||||||
return this.$getStringScreenWidth(this.getLine(docRow).substring(start, end))[0];
|
|
||||||
} else {
|
|
||||||
return end;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getDocumentLastRowColumn = function(docRow, docColumn) {
|
this.getDocumentLastRowColumn = function(docRow, docColumn) {
|
||||||
var screenRow = this.documentToScreenRow(docRow, docColumn);
|
var screenRow = this.documentToScreenRow(docRow, docColumn);
|
||||||
return this.getScreenLastRowColumn(screenRow, true);
|
return this.getScreenLastRowColumn(screenRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getRowSplitData = function(row) {
|
this.getRowSplitData = function(row) {
|
||||||
|
|
@ -1201,7 +1197,7 @@ var EditSession = function(text, mode) {
|
||||||
foldLineRowLength;
|
foldLineRowLength;
|
||||||
|
|
||||||
var row = 0,
|
var row = 0,
|
||||||
rowLength;
|
rowLength = 0;
|
||||||
|
|
||||||
while (row <= screenRow) {
|
while (row <= screenRow) {
|
||||||
foldLine = this.getFoldLine(docRow, lastFoldLine);
|
foldLine = this.getFoldLine(docRow, lastFoldLine);
|
||||||
|
|
@ -1209,7 +1205,7 @@ var EditSession = function(text, mode) {
|
||||||
lastFoldLine = foldLine;
|
lastFoldLine = foldLine;
|
||||||
rowLength = foldLine.getRowLength();
|
rowLength = foldLine.getRowLength();
|
||||||
} else {
|
} else {
|
||||||
rowLength = this.getRowLength(row);
|
rowLength = this.getRowLength(docRow);
|
||||||
}
|
}
|
||||||
if (row + rowLength - 1 >= screenRow) {
|
if (row + rowLength - 1 >= screenRow) {
|
||||||
break;
|
break;
|
||||||
|
|
@ -1294,6 +1290,17 @@ var EditSession = function(text, mode) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.doc2Screen = function(docRow, docColumn) {
|
this.doc2Screen = function(docRow, docColumn) {
|
||||||
|
var wrapData;
|
||||||
|
if (this.$useWrapMode) {
|
||||||
|
wrapData = this.$wrapData;
|
||||||
|
if (docRow > wrapData.length - 1) {
|
||||||
|
return [
|
||||||
|
this.getScreenLength(),
|
||||||
|
wrapData.length == 0 ? 0 : (wrapData[wrapData.length - 1].length - 1)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var screenRow = 0,
|
var screenRow = 0,
|
||||||
screenColumn = 0,
|
screenColumn = 0,
|
||||||
foldStartRow = null,
|
foldStartRow = null,
|
||||||
|
|
@ -1331,30 +1338,19 @@ var EditSession = function(text, mode) {
|
||||||
textLine = this.getLine(docRow).substring(0, docColumn);
|
textLine = this.getLine(docRow).substring(0, docColumn);
|
||||||
foldStartRow = docRow;
|
foldStartRow = docRow;
|
||||||
} else {
|
} else {
|
||||||
// Build the textline using the FoldLine walker.
|
textLine = this.getFoldDisplayLine(foldLine, docRow, docColumn);
|
||||||
var line;
|
|
||||||
foldLine.walk(function(placeholder, row, column, lastColumn, isNewRow) {
|
|
||||||
if (placeholder) {
|
|
||||||
textLine += placeholder;
|
|
||||||
} else {
|
|
||||||
if (isNewRow) {
|
|
||||||
line = this.getLine(row);
|
|
||||||
}
|
|
||||||
textLine += line.substring(lastColumn, column);
|
|
||||||
}
|
|
||||||
}.bind(this), docRow, docColumn)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clamp textLine if in wrapMode.
|
// Clamp textLine if in wrapMode.
|
||||||
if (this.$useWrapMode) {
|
if (this.$useWrapMode) {
|
||||||
var wrapData = this.$wrapData[foldStartRow];
|
var wrapRow = wrapData[foldStartRow];
|
||||||
var screenRowOffset = 0;
|
var screenRowOffset = 0;
|
||||||
while (docColumn >= wrapData[screenRowOffset]) {
|
while (docColumn >= wrapRow[screenRowOffset]) {
|
||||||
screenRow ++;
|
screenRow ++;
|
||||||
screenRowOffset++;
|
screenRowOffset++;
|
||||||
}
|
}
|
||||||
textLine = textLine.substring(
|
textLine = textLine.substring(
|
||||||
wrapData[screenRowOffset - 1] || 0, textLine.length);
|
wrapRow[screenRowOffset - 1] || 0, textLine.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [screenRow, this.$getStringScreenWidth(textLine)[0], textLine];
|
return [screenRow, this.$getStringScreenWidth(textLine)[0], textLine];
|
||||||
|
|
@ -1868,10 +1864,9 @@ var EditSession = function(text, mode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Recalculate wrapData
|
// TODO: Recalculate wrapData
|
||||||
// TODO: Recalculate width etc.
|
|
||||||
// TODO: Mark as dirty etc.
|
|
||||||
|
|
||||||
// Notify that fold data has changed.
|
// Notify that fold data has changed.
|
||||||
|
this.$modified = true;
|
||||||
this._dispatchEvent("changeFold");
|
this._dispatchEvent("changeFold");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1917,6 +1912,7 @@ var EditSession = function(text, mode) {
|
||||||
// TODO: Update wrapData.
|
// TODO: Update wrapData.
|
||||||
|
|
||||||
// Notify that fold data has changed.
|
// Notify that fold data has changed.
|
||||||
|
this.$modified = true;
|
||||||
this._dispatchEvent("changeFold");
|
this._dispatchEvent("changeFold");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1932,6 +1928,7 @@ var EditSession = function(text, mode) {
|
||||||
cloneFolds.forEach(function(fold) {
|
cloneFolds.forEach(function(fold) {
|
||||||
this.removeFold(fold);
|
this.removeFold(fold);
|
||||||
}, this);
|
}, this);
|
||||||
|
this.$modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1949,6 +1946,24 @@ var EditSession = function(text, mode) {
|
||||||
: docRow)
|
: docRow)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.getFoldDisplayLine = function(foldLine, endRow, endColumn) {
|
||||||
|
// Build the textline using the FoldLine walker.
|
||||||
|
var line = "",
|
||||||
|
textLine = "";
|
||||||
|
|
||||||
|
foldLine.walk(function(placeholder, row, column, lastColumn, isNewRow) {
|
||||||
|
if (placeholder) {
|
||||||
|
textLine += placeholder;
|
||||||
|
} else {
|
||||||
|
if (isNewRow) {
|
||||||
|
line = this.getLine(row);
|
||||||
|
}
|
||||||
|
textLine += line.substring(lastColumn, column);
|
||||||
|
}
|
||||||
|
}.bind(this), endRow, endColumn);
|
||||||
|
return textLine;
|
||||||
|
}
|
||||||
|
|
||||||
}).call(EditSession.prototype);
|
}).call(EditSession.prototype);
|
||||||
|
|
||||||
exports.EditSession = EditSession;
|
exports.EditSession = EditSession;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue