From 39bfb96fde3d5339710353e0e02784a367b66c72 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Mon, 13 Sep 2010 15:13:03 +0200 Subject: [PATCH] fix text selection for documents with tabs --- src/ace/Range.js | 7 +++++++ src/ace/VirtualRenderer.js | 12 ++---------- src/ace/layer/Cursor.js | 6 +++++- src/ace/layer/Marker.js | 2 ++ 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/ace/Range.js b/src/ace/Range.js index 84f6e6c0..45e93c79 100644 --- a/src/ace/Range.js +++ b/src/ace/Range.js @@ -101,6 +101,13 @@ ace.Range = function(startRow, startColumn, endRow, endColumn) { return ace.Range.fromPoints(this.start, this.end); }; + this.toScreenRange = function(doc) { + return new ace.Range( + this.start.row, doc.documentToScreenColumn(this.start.row, this.start.column), + this.end.row, doc.documentToScreenColumn(this.end.row, this.end.column) + ); + }; + }).call(ace.Range.prototype); diff --git a/src/ace/VirtualRenderer.js b/src/ace/VirtualRenderer.js index 35f017c5..1076d7cb 100644 --- a/src/ace/VirtualRenderer.js +++ b/src/ace/VirtualRenderer.js @@ -59,6 +59,7 @@ ace.VirtualRenderer = function(container) { this.setDocument = function(doc) { this.lines = doc.lines; this.doc = doc; + this.$cursorLayer.setDocument(doc); this.$markerLayer.setDocument(doc); this.$textLayer.setDocument(doc); }; @@ -229,8 +230,6 @@ ace.VirtualRenderer = function(container) { this.addMarker = function(range, clazz, type) { - range.start = this.$documentToScreenPosition(range.start); - range.end = this.$documentToScreenPosition(range.end); return this.$markerLayer.addMarker(range, clazz, type); }; @@ -243,17 +242,10 @@ ace.VirtualRenderer = function(container) { }; this.updateCursor = function(position, overwrite) { - this.$cursorLayer.setCursor(this.$documentToScreenPosition(position), overwrite); + this.$cursorLayer.setCursor(position, overwrite); this.$cursorLayer.update(this.layerConfig); }; - this.$documentToScreenPosition = function(pos) { - return { - row: pos.row, - column: this.doc.documentToScreenColumn(pos.row, pos.column) - }; - }; - this.hideCursor = function() { this.$cursorLayer.hideCursor(); }; diff --git a/src/ace/layer/Cursor.js b/src/ace/layer/Cursor.js index 06480a7f..cc96d598 100644 --- a/src/ace/layer/Cursor.js +++ b/src/ace/layer/Cursor.js @@ -13,10 +13,14 @@ ace.layer.Cursor = function(parentEl) { (function() { + this.setDocument = function(doc) { + this.doc = doc; + }; + this.setCursor = function(position, overwrite) { this.position = { row : position.row, - column : position.column + column : this.doc.documentToScreenColumn(position.row, position.column) }; if (overwrite) { ace.addCssClass(this.cursor, "ace_overwrite"); diff --git a/src/ace/layer/Marker.js b/src/ace/layer/Marker.js index dcac23bc..8376dcfe 100644 --- a/src/ace/layer/Marker.js +++ b/src/ace/layer/Marker.js @@ -84,6 +84,7 @@ ace.layer.Marker = function(parentEl) { }; this.drawMultiLineMarker = function(stringBuilder, range, clazz, layerConfig) { + var range = range.toScreenRange(this.doc); // from selection start to the end of the line var height = layerConfig.lineHeight; @@ -125,6 +126,7 @@ ace.layer.Marker = function(parentEl) { }; this.drawSingleLineMarker = function(stringBuilder, range, clazz, layerConfig) { + var range = range.toScreenRange(this.doc); var height = layerConfig.lineHeight; var width = Math.round((range.end.column - range.start.column) * layerConfig.characterWidth);