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)
|
||||
position = this.session.selection.getCursor();
|
||||
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 cursorTop = (pos.row - (onScreen ? this.config.firstRowScreen : 0)) *
|
||||
this.config.lineHeight;
|
||||
var cursorWidth = (this.config.textWidth(pos.row, pos.column + 1) - textWidth) || this.config.characterWidth;
|
||||
|
||||
return {
|
||||
left : cursorLeft,
|
||||
top : cursorTop,
|
||||
width: cursorWidth
|
||||
};
|
||||
return {left : cursorLeft, top : cursorTop, width: cursorWidth};
|
||||
};
|
||||
|
||||
this.update = function(config) {
|
||||
|
|
|
|||
|
|
@ -75,7 +75,10 @@ var Marker = function(parentEl) {
|
|||
var range = marker.range.clipRows(config.firstRow, config.lastRow);
|
||||
if (range.isEmpty()) continue;
|
||||
|
||||
var docRange = range;
|
||||
range = range.toScreenRange(this.session);
|
||||
range.start.column = docRange.start.column;
|
||||
range.end.column = docRange.end.column;
|
||||
if (marker.renderer) {
|
||||
var top = this.$getTop(range.start.row, config);
|
||||
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 style = "";
|
||||
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>");
|
||||
}
|
||||
else {
|
||||
|
|
@ -360,53 +360,17 @@ var Text = function(parentEl) {
|
|||
var stringBuilder = [];
|
||||
var len = 0;
|
||||
var i = 0;
|
||||
var screenColumn = 0; // TODO
|
||||
var screenColumn = 0;
|
||||
while (len < column && i < tokens.length) {
|
||||
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;
|
||||
|
||||
|
||||
// truncate once length is larger than 'column'
|
||||
len += value.length;
|
||||
if (len > column)
|
||||
value = value.substring(0, value.length - (len - column));
|
||||
|
||||
var output = value.replace(replaceReg, replaceFunc);
|
||||
|
||||
|
||||
if (!this.$textToken[token.type]) {
|
||||
var classes = "ace_" + token.type.replace(/\./g, " ace_");
|
||||
stringBuilder.push("<span class='", classes, "'>", output, "</span>");
|
||||
}
|
||||
else {
|
||||
stringBuilder.push(output);
|
||||
}
|
||||
screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value);
|
||||
}
|
||||
|
||||
// render line off screen
|
||||
|
|
|
|||
|
|
@ -1413,7 +1413,7 @@ var VirtualRenderer = function(container, theme) {
|
|||
else {
|
||||
// same as Math.floor((max-min)/2) but faster
|
||||
var pivot = min + ((max - min) >> 1);
|
||||
var w = this.$textLayer.textWidth(row, pivot);
|
||||
var w = this.$textLayer.textWidth(row, pivot, true);
|
||||
if (w == width)
|
||||
return pivot;
|
||||
else if (w > width)
|
||||
|
|
@ -1426,13 +1426,16 @@ var VirtualRenderer = function(container, theme) {
|
|||
|
||||
this.screenToTextCoordinates = function(x, y) {
|
||||
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;
|
||||
|
||||
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