From 78585a9c5d15b7ca061fb28706f80f9269ab30b2 Mon Sep 17 00:00:00 2001 From: nightwing Date: Tue, 25 Jun 2013 23:50:00 +0400 Subject: [PATCH] add demo/autoresize.html --- demo/autoresize.html | 48 +++++++++++++++++++++++++++++++++++++ lib/ace/editor.js | 2 ++ lib/ace/virtual_renderer.js | 20 +++++++++++++--- 3 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 demo/autoresize.html diff --git a/demo/autoresize.html b/demo/autoresize.html new file mode 100644 index 00000000..cc1dc5e3 --- /dev/null +++ b/demo/autoresize.html @@ -0,0 +1,48 @@ + + + + + + Editor + + + +
autoresizing editor
+
+
minHeight = 2 lines
+ + + + + + diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 62a4c37f..088fbaae 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -2259,6 +2259,8 @@ config.defineOptions(Editor.prototype, "editor", { displayIndentGuides: "renderer", fontSize: "renderer", fontFamily: "renderer", + maxLines: "renderer", + minLines: "renderer", scrollSpeed: "$mouseHandler", dragDelay: "$mouseHandler", diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index a3afedc5..90403095 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -808,7 +808,10 @@ var VirtualRenderer = function(container, theme) { this.$autosize = function(height, width) { var height = this.session.getScreenLength() * this.lineHeight; var maxHeight = this.$maxLines * this.lineHeight; - var desiredHeight = Math.max(this.lineHeight, Math.min(maxHeight, height)); + var desiredHeight = Math.max( + (this.$minLines||1) * this.lineHeight, + Math.min(maxHeight, height) + ); var vScroll = height > maxHeight; if (desiredHeight != this.desiredHeight || @@ -817,9 +820,10 @@ var VirtualRenderer = function(container, theme) { this.$vScroll = vScroll; this.scrollBarV.setVisible(vScroll); } - + + var w = this.container.clientWidth; this.container.style.height = desiredHeight + "px"; - this.$updateCachedSize(true, this.$gutterWidth, this.$size.width, desiredHeight); + this.$updateCachedSize(true, this.$gutterWidth, w, desiredHeight); // this.$loop.changes = 0; this.desiredHeight = desiredHeight; } @@ -1557,6 +1561,16 @@ config.defineOptions(VirtualRenderer.prototype, "renderer", { this.container.style.fontFamily = name; this.updateFontSize(); } + }, + maxLines: { + set: function(val) { + this.updateFull(); + } + }, + minLines: { + set: function(name) { + this.updateFull(); + } } });