From d9c0212fa1dd5e3e6c1ece37def10ae651ef2696 Mon Sep 17 00:00:00 2001 From: Ruben Daniels Date: Wed, 13 Jun 2012 22:18:15 -0700 Subject: [PATCH] * Added ability to force ace to resize * Automatically size the width via css --- lib/ace/css/editor.css | 1 + lib/ace/editor.js | 4 ++-- lib/ace/virtual_renderer.js | 38 ++++++++++++++++++++++++++++--------- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/lib/ace/css/editor.css b/lib/ace/css/editor.css index e8eec1e9..abc0bef4 100644 --- a/lib/ace/css/editor.css +++ b/lib/ace/css/editor.css @@ -9,6 +9,7 @@ .ace_scroller { position: absolute; overflow: hidden; + width : 100%; } .ace_content { diff --git a/lib/ace/editor.js b/lib/ace/editor.js index ac7c31ac..6086b735 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -249,8 +249,8 @@ var Editor = function(renderer, session) { * * {:VirtualRenderer.onResize} **/ - this.resize = function() { - this.renderer.onResize(); + this.resize = function(force) { + this.renderer.onResize(force); }; /** diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index 996315e8..6f75ac62 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -264,8 +264,13 @@ var VirtualRenderer = function(container, theme) { * * Triggers a full update of all the layers, for all the rows. **/ - this.updateFull = function() { - this.$loop.schedule(this.CHANGE_FULL); + this.updateFull = function(force) { + if (force){ + this.$renderChanges(this.CHANGE_FULL, true); + } + else { + this.$loop.schedule(this.CHANGE_FULL); + } }; /** @@ -283,11 +288,19 @@ var VirtualRenderer = function(container, theme) { * * [Triggers a resize of the editor.]{: #VirtualRenderer.onResize} **/ - this.onResize = function(force) { + this.onResize = function(force, gutterWidth, width, height) { var changes = this.CHANGE_SIZE; var size = this.$size; - var height = dom.getInnerHeight(this.container); + if (this.resizing) { + force = 2; + height = size.height; + width = size.width; + } + this.resizing = force; + + if (!height) + height = dom.getInnerHeight(this.container); if (force || size.height != height) { size.height = height; @@ -301,20 +314,27 @@ var VirtualRenderer = function(container, theme) { } } - var width = dom.getInnerWidth(this.container); + if (!width) + width = dom.getInnerWidth(this.container); if (force || size.width != width) { size.width = width; var gutterWidth = this.showGutter ? this.$gutter.offsetWidth : 0; this.scroller.style.left = gutterWidth + "px"; size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBar.getWidth()); - this.scroller.style.width = size.scrollerWidth + "px"; + //this.scroller.style.width = size.scrollerWidth + "px"; if (this.session.getUseWrapMode() && this.adjustWrapLimit() || force) changes = changes | this.CHANGE_FULL; } - this.$loop.schedule(changes); + if (force || this.resizing) + this.$renderChanges(changes, true); + else + this.$loop.schedule(changes); + + if (force === true) + delete this.resizing; }; /** @@ -630,8 +650,8 @@ var VirtualRenderer = function(container, theme) { this.scrollBar.setScrollTop(this.scrollTop); }; - this.$renderChanges = function(changes) { - if (!changes || !this.session || !this.container.offsetWidth) + this.$renderChanges = function(changes, force) { + if (!force && (!changes || !this.session || !this.container.offsetWidth)) return; // text, scrolling and resize changes can cause the view port size to change