fix cursor on lines with tab
This commit is contained in:
parent
bcba9bea6e
commit
6d2fbb3ed5
4 changed files with 18 additions and 52 deletions
|
|
@ -170,17 +170,13 @@ var Cursor = function(parentEl) {
|
||||||
if (!position)
|
if (!position)
|
||||||
position = this.session.selection.getCursor();
|
position = this.session.selection.getCursor();
|
||||||
var pos = this.session.documentToScreenPosition(position);
|
var pos = this.session.documentToScreenPosition(position);
|
||||||
var textWidth = this.config.textWidth(pos.row, pos.column);
|
var textWidth = this.config.textWidth(pos.row, position.column);
|
||||||
var cursorLeft = this.$padding + textWidth;
|
var cursorLeft = this.$padding + textWidth;
|
||||||
var cursorTop = (pos.row - (onScreen ? this.config.firstRowScreen : 0)) *
|
var cursorTop = (pos.row - (onScreen ? this.config.firstRowScreen : 0)) *
|
||||||
this.config.lineHeight;
|
this.config.lineHeight;
|
||||||
var cursorWidth = (this.config.textWidth(pos.row, pos.column + 1) - textWidth) || this.config.characterWidth;
|
var cursorWidth = (this.config.textWidth(pos.row, pos.column + 1) - textWidth) || this.config.characterWidth;
|
||||||
|
|
||||||
return {
|
return {left : cursorLeft, top : cursorTop, width: cursorWidth};
|
||||||
left : cursorLeft,
|
|
||||||
top : cursorTop,
|
|
||||||
width: cursorWidth
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.update = function(config) {
|
this.update = function(config) {
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,10 @@ var Marker = function(parentEl) {
|
||||||
var range = marker.range.clipRows(config.firstRow, config.lastRow);
|
var range = marker.range.clipRows(config.firstRow, config.lastRow);
|
||||||
if (range.isEmpty()) continue;
|
if (range.isEmpty()) continue;
|
||||||
|
|
||||||
|
var docRange = range;
|
||||||
range = range.toScreenRange(this.session);
|
range = range.toScreenRange(this.session);
|
||||||
|
range.start.column = docRange.start.column;
|
||||||
|
range.end.column = docRange.end.column;
|
||||||
if (marker.renderer) {
|
if (marker.renderer) {
|
||||||
var top = this.$getTop(range.start.row, config);
|
var top = this.$getTop(range.start.row, config);
|
||||||
var left = this.$padding + config.textWidth(range.start.row, range.start.column);
|
var left = this.$padding + config.textWidth(range.start.row, range.start.column);
|
||||||
|
|
|
||||||
|
|
@ -346,7 +346,7 @@ var Text = function(parentEl) {
|
||||||
var classes = "ace_" + token.type.replace(/\./g, " ace_");
|
var classes = "ace_" + token.type.replace(/\./g, " ace_");
|
||||||
var style = "";
|
var style = "";
|
||||||
if (token.type == "fold")
|
if (token.type == "fold")
|
||||||
style = " style='width:" + (token.value.length * this.config.characterWidth) + "px;' ";
|
style = " style='width:" + (value.length * this.config.characterWidth) + "px;' ";
|
||||||
stringBuilder.push("<span class='", classes, "'", style, ">", output, "</span>");
|
stringBuilder.push("<span class='", classes, "'", style, ">", output, "</span>");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -360,36 +360,9 @@ var Text = function(parentEl) {
|
||||||
var stringBuilder = [];
|
var stringBuilder = [];
|
||||||
var len = 0;
|
var len = 0;
|
||||||
var i = 0;
|
var i = 0;
|
||||||
var screenColumn = 0; // TODO
|
var screenColumn = 0;
|
||||||
while (len < column && i < tokens.length) {
|
while (len < column && i < tokens.length) {
|
||||||
var token = tokens[i++];
|
var token = tokens[i++];
|
||||||
|
|
||||||
var self = this;
|
|
||||||
var replaceReg = /\t|&|<|( +)|([\v\f \u00a0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000])/g;
|
|
||||||
var replaceFunc = function(c, a, b, tabIdx, idx4) {
|
|
||||||
if (c.charCodeAt(0) == 32) {
|
|
||||||
return new Array(c.length+1).join(" ");
|
|
||||||
} else if (c == "\t") {
|
|
||||||
var tabSize = self.session.getScreenTabSize(screenColumn + tabIdx);
|
|
||||||
screenColumn += tabSize - 1;
|
|
||||||
return self.$tabStrings[tabSize];
|
|
||||||
} else if (c == "&") {
|
|
||||||
if (useragent.isOldGecko)
|
|
||||||
return "&";
|
|
||||||
else
|
|
||||||
return "&";
|
|
||||||
} else if (c == "<") {
|
|
||||||
return "<";
|
|
||||||
} else if (c.match(/[\v\f \u00a0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000]/)) {
|
|
||||||
if (self.showInvisibles) {
|
|
||||||
var space = new Array(c.length+1).join(self.SPACE_CHAR);
|
|
||||||
return "<span class='ace_invisible'>" + space + "</span>";
|
|
||||||
} else {
|
|
||||||
return " ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var value = token.value;
|
var value = token.value;
|
||||||
|
|
||||||
// truncate once length is larger than 'column'
|
// truncate once length is larger than 'column'
|
||||||
|
|
@ -397,16 +370,7 @@ var Text = function(parentEl) {
|
||||||
if (len > column)
|
if (len > column)
|
||||||
value = value.substring(0, value.length - (len - column));
|
value = value.substring(0, value.length - (len - column));
|
||||||
|
|
||||||
var output = value.replace(replaceReg, replaceFunc);
|
screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value);
|
||||||
|
|
||||||
|
|
||||||
if (!this.$textToken[token.type]) {
|
|
||||||
var classes = "ace_" + token.type.replace(/\./g, " ace_");
|
|
||||||
stringBuilder.push("<span class='", classes, "'>", output, "</span>");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
stringBuilder.push(output);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// render line off screen
|
// render line off screen
|
||||||
|
|
|
||||||
|
|
@ -1413,7 +1413,7 @@ var VirtualRenderer = function(container, theme) {
|
||||||
else {
|
else {
|
||||||
// same as Math.floor((max-min)/2) but faster
|
// same as Math.floor((max-min)/2) but faster
|
||||||
var pivot = min + ((max - min) >> 1);
|
var pivot = min + ((max - min) >> 1);
|
||||||
var w = this.$textLayer.textWidth(row, pivot);
|
var w = this.$textLayer.textWidth(row, pivot, true);
|
||||||
if (w == width)
|
if (w == width)
|
||||||
return pivot;
|
return pivot;
|
||||||
else if (w > width)
|
else if (w > width)
|
||||||
|
|
@ -1426,13 +1426,16 @@ var VirtualRenderer = function(container, theme) {
|
||||||
|
|
||||||
this.screenToTextCoordinates = function(x, y) {
|
this.screenToTextCoordinates = function(x, y) {
|
||||||
var canvasPos = this.scroller.getBoundingClientRect();
|
var canvasPos = this.scroller.getBoundingClientRect();
|
||||||
|
|
||||||
var width = x + this.scroller.scrollLeft - canvasPos.left - this.$padding - dom.getPageScrollLeft();
|
|
||||||
var col = this.$findColumn(row, width);
|
|
||||||
|
|
||||||
var row = (y + this.scrollTop - canvasPos.top) / this.lineHeight;
|
var row = (y + this.scrollTop - canvasPos.top) / this.lineHeight;
|
||||||
|
|
||||||
return this.session.screenToDocumentPosition(row, Math.max(col, 0));
|
var width = x + this.scroller.scrollLeft - canvasPos.left - this.$padding - dom.getPageScrollLeft();
|
||||||
|
|
||||||
|
|
||||||
|
var pos = this.session.screenToDocumentPosition(row, Math.max(col, 0));
|
||||||
|
|
||||||
|
var col = this.$findColumn(pos.row, width);
|
||||||
|
pos.column = col
|
||||||
|
return pos
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue