diff --git a/demo/editor.html b/demo/editor.html index fee837f5..56629d02 100644 --- a/demo/editor.html +++ b/demo/editor.html @@ -55,16 +55,20 @@ - - - + + + +
- - -
+ + + + + +
@@ -87,6 +91,16 @@ function getMode() { return modes[modeEl.value]; } +var selectEl = document.getElementById("select_style"); +selectEl.onchange = function() { + if (selectEl.checked) { + editor.setSelectionStyle("line"); + } else { + editor.setSelectionStyle("text"); + } +}; + + var container = document.getElementById("container"); var editor = new ace.Editor( new ace.VirtualRenderer(container), diff --git a/src/Editor.js b/src/Editor.js index cb9deb7e..7a3436bb 100644 --- a/src/Editor.js +++ b/src/Editor.js @@ -21,6 +21,8 @@ ace.Editor = function(renderer, doc, mode) { this.renderer.draw(); this.onCursorChange(); this.onSelectionChange(); + + this._initialized = true; }; ace.Editor.prototype.setDocument = function(doc) { @@ -69,6 +71,10 @@ ace.Editor.prototype.setMode = function(mode) { } this.renderer.setTokenizer(this.bgTokenizer); + + if (this._initialized) { + this.renderer.draw(); + } }; @@ -79,7 +85,6 @@ ace.Editor.prototype.resize = function() }; ace.Editor.prototype._highlightBrackets = function() { - if (this._bracketHighlight) { this.renderer.removeMarker(this._bracketHighlight); this._bracketHighlight = null; @@ -146,7 +151,8 @@ ace.Editor.prototype.onSelectionChange = function() { if (!this.selection.isEmpty()) { var range = this.selection.getRange(); - this.selectionMarker = this.renderer.addMarker(range, "selection", "text"); + var style = this.getSelectionStyle(); + this.selectionMarker = this.renderer.addMarker(range, "selection", style); } this.onCursorChange(); @@ -256,6 +262,18 @@ ace.Editor.prototype.onTextInput = function(text) { this.renderer.scrollCursorIntoView(); }; +ace.Editor.prototype._selectionStyle = "line"; +ace.Editor.prototype.setSelectionStyle = function(style) { + if (this._selectionStyle == style) return; + + this._selectionStyle = style; + this.onSelectionChange(); +}; + +ace.Editor.prototype.getSelectionStyle = function() { + return this._selectionStyle; +}; + ace.Editor.prototype.removeRight = function() { if (this.selection.isEmpty()) { this.selection.selectRight(); diff --git a/src/MarkerLayer.js b/src/MarkerLayer.js index cfa019e2..90d28b65 100644 --- a/src/MarkerLayer.js +++ b/src/MarkerLayer.js @@ -67,7 +67,7 @@ ace.MarkerLayer.prototype.update = function(config) { } if (range.start.row !== range.end.row) { - if (marker.type == "line") { + if (marker.type == "text") { this.drawTextMarker(html, range, marker.clazz, config); } else { this.drawMultiLineMarker(html, range, marker.clazz, config); diff --git a/src/VirtualRenderer.js b/src/VirtualRenderer.js index bff44bc9..7f9b6cd9 100644 --- a/src/VirtualRenderer.js +++ b/src/VirtualRenderer.js @@ -111,8 +111,8 @@ ace.VirtualRenderer.prototype.draw = function() { this.gutterLayer.update(layerConfig); }; -ace.VirtualRenderer.prototype.addMarker = function(range, clazz) { - return this.markerLayer.addMarker(range, clazz); +ace.VirtualRenderer.prototype.addMarker = function(range, clazz, type) { + return this.markerLayer.addMarker(range, clazz, type); }; ace.VirtualRenderer.prototype.removeMarker = function(markerId) {