Fix calculation of EditSession.getScreenLength.

This commit is contained in:
Julian Viereck 2011-05-17 16:16:28 +02:00
commit 55e0f8ceff
2 changed files with 24 additions and 14 deletions

View file

@ -155,6 +155,8 @@ exports.launch = function(env) {
var container = document.getElementById("editor");
var cockpitInput = document.getElementById("cockpitInput");
env.editor = new Editor(new Renderer(container, theme));
window.env = env;
window.ace = env.editor;
var modes = {
text: new TextMode(),

View file

@ -463,7 +463,7 @@ var EditSession = function(text, mode) {
this.$stopWorker();
if (this.$useWorker)
if (this.$useWorker)
this.$startWorker();
var tokenizer = mode.getTokenizer();
@ -492,10 +492,10 @@ var EditSession = function(text, mode) {
this.$stopWorker = function() {
if (this.$worker)
this.$worker.terminate();
this.$worker = null;
};
this.$startWorker = function() {
if (typeof Worker !== "undefined" && !require.noWorker) {
try {
@ -503,7 +503,7 @@ var EditSession = function(text, mode) {
} catch (e) {
console.log("Could not load worker");
console.log(e);
this.$worker = null;
this.$worker = null;
}
}
else
@ -1418,7 +1418,7 @@ var EditSession = function(text, mode) {
}
}
var docRowCacheLast = docRow;
// clamp row before clamping column, for selection on last line
// clamp row before clamping column, for selection on last line
var maxRow = this.getLength() - 1;
var foldLine = this.getNextFold(docRow);
@ -1449,7 +1449,7 @@ var EditSession = function(text, mode) {
if (foldLine && foldLine.start.row <= docRow)
line = this.getFoldDisplayLine(foldLine);
else {
else {
line = this.getLine(docRow);
foldLine = null;
}
@ -1596,21 +1596,29 @@ var EditSession = function(text, mode) {
};
this.getScreenLength = function() {
var length = this.getLength();
var screenRows = 0;
var lastFoldLine = null;
var foldLine = null;
if (!this.$useWrapMode) {
screenRows = length;
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;
}
} else {
for (var row = 0; row < this.$wrapData.length; row++) {
screenRows += this.$wrapData[row].length + 1;
if (foldLine = this.getFoldLine(row, lastFoldLine)) {
row = foldLine.end.row;
screenRows += 1;
} else {
screenRows += this.$wrapData[row].length + 1;
}
}
}
var foldData = this.$foldData;
for (var i = 0; i < foldData.length; i++) {
var foldLine = foldData[i];
screenRows -= foldLine.end.row - foldLine.start.row;
}
return screenRows;
}