From d9c0212fa1dd5e3e6c1ece37def10ae651ef2696 Mon Sep 17 00:00:00 2001 From: Ruben Daniels Date: Wed, 13 Jun 2012 22:18:15 -0700 Subject: [PATCH 1/3] * 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 From 5e6d40f462f06ef6e0aef70d0fb992c93b7f7c20 Mon Sep 17 00:00:00 2001 From: Ruben Daniels Date: Wed, 13 Jun 2012 23:29:19 -0700 Subject: [PATCH 2/3] * Fixed recursion issue --- lib/ace/virtual_renderer.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index b8a060ea..c41d976a 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -291,12 +291,12 @@ var VirtualRenderer = function(container, theme) { var changes = this.CHANGE_SIZE; var size = this.$size; - if (this.resizing) { - force = 2; - height = size.height; - width = size.width; - } - this.resizing = force; + if (this.resizing > 2) + return; + else if (this.resizing > 1) + this.resizing++; + else + this.resizing = force ? 1 : 0; if (!height) height = dom.getInnerHeight(this.container); @@ -315,7 +315,7 @@ var VirtualRenderer = function(container, theme) { if (!width) width = dom.getInnerWidth(this.container); - if (force || size.width != width) { + if (force || this.resizing > 1 || size.width != width) { size.width = width; var gutterWidth = this.showGutter ? this.$gutter.offsetWidth : 0; @@ -327,12 +327,12 @@ var VirtualRenderer = function(container, theme) { changes = changes | this.CHANGE_FULL; } - if (force || this.resizing) + if (force) this.$renderChanges(changes, true); else this.$loop.schedule(changes); - if (force === true) + if (force) delete this.resizing; }; From 72c733e829d6ec6573c0512769086a256aeb2bd8 Mon Sep 17 00:00:00 2001 From: Ruben Daniels Date: Mon, 18 Jun 2012 21:52:55 -0700 Subject: [PATCH 3/3] * Fix for editor that can be null if no editor is loaded. --- lib/ace/commands/multi_select_commands.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ace/commands/multi_select_commands.js b/lib/ace/commands/multi_select_commands.js index ed396fb3..ebac5cc7 100644 --- a/lib/ace/commands/multi_select_commands.js +++ b/lib/ace/commands/multi_select_commands.js @@ -92,7 +92,7 @@ exports.multiSelectCommands = [{ bindKey: "esc", exec: function(editor) { editor.exitMultiSelectMode(); }, readonly: true, - isAvailable: function(editor) {return editor.inMultiSelectMode} + isAvailable: function(editor) {return editor && editor.inMultiSelectMode} }]; var HashHandler = require("../keyboard/hash_handler").HashHandler;