diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index e3cbcbee..8af5f169 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -318,18 +318,18 @@ var EditSession = function(text, mode) { }; this.getWidth = function() { - this.$computeWidth(!this.width); + this.$computeWidth(); return this.width; }; this.getScreenWidth = function() { - this.$computeWidth(!this.screenWidth); + this.$computeWidth(); return this.screenWidth; }; this.$computeWidth = function(force) { - if (this.modified || force) { - this.modified = false; + if (this.$modified || force) { + this.$modified = false; var lines = this.doc.getAllLines(); var longestLine = 0; @@ -340,7 +340,7 @@ var EditSession = function(text, mode) { var len = lines[i].length; longestLine = Math.max(longestLine, len); - lines[i].replace("\t", function(m) { + lines[i].replace(/\t/g, function(m) { len += tabSize-1; return m; }); diff --git a/lib/ace/keyboard/textinput.js b/lib/ace/keyboard/textinput.js index 459f9e0e..b6faa25f 100644 --- a/lib/ace/keyboard/textinput.js +++ b/lib/ace/keyboard/textinput.js @@ -56,15 +56,17 @@ var TextInput = function(parentNode, host) { style.opacity = 0; style.width = "10px"; style.height = "30px"; - + var changeCursor = function() { + if (host.renderer.isMockRenderer) return; + var cursor = host.getCursorPosition(); var pos = host.renderer.textToScreenCoordinates(cursor.row, cursor.column); var epos = parentNode.getBoundingClientRect(); style.left = (pos.pageX - epos.left - 6) + "px"; style.top = (pos.pageY - epos.top + 52) + "px"; }; - + host.addEventListener("changeSession", function(e) { if (e.oldSession) e.oldSession.getSelection().removeEventListener("changeCursor", changeCursor); diff --git a/lib/ace/test/document_test.js b/lib/ace/test/document_test.js index 4a33dcb0..b2705f4e 100644 --- a/lib/ace/test/document_test.js +++ b/lib/ace/test/document_test.js @@ -285,7 +285,7 @@ var Test = { var splits; var tabSize = 4; var wrapLimit = 12; - var computeWrapSplits = Document.prototype.$computeWrapSplits; + var computeWrapSplits = EditSession.prototype.$computeWrapSplits; var c = 0; function computeAndAssert(line, assertEqual) { diff --git a/lib/ace/test/edit_session_test.js b/lib/ace/test/edit_session_test.js index 967783cb..6ef7e4d7 100644 --- a/lib/ace/test/edit_session_test.js +++ b/lib/ace/test/edit_session_test.js @@ -257,6 +257,7 @@ var Test = { session.doc.insertNewLine(0); session.doc.insertLines(1, ["\t\t"]); + assert.equal(session.getWidth(), 3); assert.equal(session.getScreenWidth(), 8); diff --git a/lib/ace/test/mockrenderer.js b/lib/ace/test/mockrenderer.js index 412a418a..b076cc78 100644 --- a/lib/ace/test/mockrenderer.js +++ b/lib/ace/test/mockrenderer.js @@ -50,6 +50,8 @@ MockRenderer = function(visibleRowCount) { firstVisibleRow : 0, lastVisibleRow : this.visibleRowCount }; + + this.isMockRenderer = true; }; @@ -117,10 +119,10 @@ MockRenderer.prototype.addMarker = function() { MockRenderer.prototype.setBreakpoints = function() { }; -MockRenderer.prototype.updateFull = function() { +MockRenderer.prototype.updateFull = function() { }; -MockRenderer.prototype.updateText = function() { +MockRenderer.prototype.updateText = function() { }; MockRenderer.prototype.showCursor = function() { @@ -132,5 +134,12 @@ MockRenderer.prototype.visualizeFocus = function() { MockRenderer.prototype.setAnnotations = function() { }; +MockRenderer.prototype.textToScreenCoordinates = function() { + return { + pageX: 0, + pageY: 0 + } +}; + return MockRenderer; });