Use getStringScreenWidth in Session.computeWidth
This commit is contained in:
parent
af5d11770f
commit
d4a46aa467
1 changed files with 14 additions and 17 deletions
|
|
@ -348,16 +348,16 @@ var EditSession = function(text, mode) {
|
|||
this.setUseWorker = function(useWorker) {
|
||||
if (this.$useWorker == useWorker)
|
||||
return;
|
||||
|
||||
|
||||
if (useWorker && !this.$worker && window.Worker)
|
||||
this.$worker = mode.createWorker(this);
|
||||
|
||||
|
||||
if (!useWorker && this.$worker) {
|
||||
this.$worker.terminate();
|
||||
this.$worker = null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
this.getUseWorker = function() {
|
||||
return this.$useWorker;
|
||||
};
|
||||
|
|
@ -417,14 +417,11 @@ var EditSession = function(text, mode) {
|
|||
var tabSize = this.getTabSize();
|
||||
|
||||
for ( var i = 0; i < lines.length; i++) {
|
||||
var len = lines[i].length;
|
||||
var line = lines[i],
|
||||
len = line.length,
|
||||
screenLen = this.$getStringScreenWidth(line);
|
||||
longestLine = Math.max(longestLine, len);
|
||||
|
||||
lines[i].replace(/\t/g, function(m) {
|
||||
len += tabSize-1;
|
||||
return m;
|
||||
});
|
||||
longestScreenLine = Math.max(longestScreenLine, len);
|
||||
longestScreenLine = Math.max(longestScreenLine, screenLen);
|
||||
}
|
||||
this.width = longestLine;
|
||||
|
||||
|
|
@ -601,7 +598,7 @@ var EditSession = function(text, mode) {
|
|||
|
||||
|
||||
var actions = [{}];
|
||||
|
||||
|
||||
// collapse insert and remove operations
|
||||
for (var i=0; i<deltas.length; i++) {
|
||||
var delta = deltas[i];
|
||||
|
|
@ -615,7 +612,7 @@ var EditSession = function(text, mode) {
|
|||
})
|
||||
}
|
||||
else {
|
||||
if (isInsert)
|
||||
if (isInsert)
|
||||
action.end = delta.range.end;
|
||||
else
|
||||
action.start = delta.range.start;
|
||||
|
|
@ -625,12 +622,12 @@ var EditSession = function(text, mode) {
|
|||
// update selection based on last operation
|
||||
this.selection.clearSelection();
|
||||
var action = actions[actions.length-1];
|
||||
if (action.isInsert)
|
||||
if (action.isInsert)
|
||||
this.selection.setSelectionRange(Range.fromPoints(action.start, action.end));
|
||||
else
|
||||
else
|
||||
this.selection.moveCursorToPosition(action.end);
|
||||
},
|
||||
|
||||
|
||||
this.replace = function(range, text) {
|
||||
return this.doc.replace(range, text);
|
||||
};
|
||||
|
|
@ -988,7 +985,7 @@ var EditSession = function(text, mode) {
|
|||
this.$getStringScreenWidth = function(str) {
|
||||
var screenColumn = 0;
|
||||
var tabSize = this.getTabSize();
|
||||
|
||||
|
||||
for (var i=0; i<str.length; i++) {
|
||||
var c = str.charCodeAt(i);
|
||||
// tab
|
||||
|
|
@ -1008,7 +1005,7 @@ var EditSession = function(text, mode) {
|
|||
screenColumn += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return screenColumn;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue