From 2852638c45a0a6f770594a13c5e67acc3548ecff Mon Sep 17 00:00:00 2001 From: nightwing Date: Wed, 19 Jun 2013 21:25:39 +0400 Subject: [PATCH 1/6] fix initial highlighting in hidden editor --- doc/site/js/main.js | 4 ++-- lib/ace/virtual_renderer.js | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/doc/site/js/main.js b/doc/site/js/main.js index b52d6f6b..b7d61fae 100644 --- a/doc/site/js/main.js +++ b/doc/site/js/main.js @@ -64,8 +64,6 @@ $(function() { tabs.find(tab_a_selector).click(function(e) { e.preventDefault(); - embedded_editor.resize(); - editor.resize(); if ($(this).attr("href") === "/") { window.location = "http://ace.ajax.org"; return; @@ -102,6 +100,8 @@ $(function() { } $(this).tab("show"); + embedded_editor.resize(); + editor.resize(); var state = {}; state.nav = $(this).attr("href").substr(1); diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index 8449b958..3bd0fcc3 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -270,6 +270,7 @@ var VirtualRenderer = function(container, theme) { this.$textLayer.checkForSizeChanges(); }; + this.$changes = 0; /** * [Triggers a resize of the editor.]{: #VirtualRenderer.onResize} * @param {Boolean} force If `true`, recomputes the size, even if the height and width haven't changed @@ -280,7 +281,7 @@ var VirtualRenderer = function(container, theme) { * **/ this.onResize = function(force, gutterWidth, width, height) { - var changes = 0; + var changes = this.$changes || 0; var size = this.$size; if (this.resizing > 2) @@ -644,8 +645,10 @@ var VirtualRenderer = function(container, theme) { }; this.$renderChanges = function(changes, force) { - if (!force && (!changes || !this.session || !this.container.offsetWidth)) - return; + if (!force && (!changes || !this.session || !this.container.offsetWidth)) { + this.$changes = changes; + return; + } this._signal("beforeRender"); // text, scrolling and resize changes can cause the view port size to change From 2d9225326cd9003891826c3176e53f0419ed061e Mon Sep 17 00:00:00 2001 From: nightwing Date: Wed, 19 Jun 2013 21:38:11 +0400 Subject: [PATCH 2/6] cleanup --- lib/ace/scrollbar.js | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/lib/ace/scrollbar.js b/lib/ace/scrollbar.js index 36619bd5..642e2d3e 100644 --- a/lib/ace/scrollbar.js +++ b/lib/ace/scrollbar.js @@ -37,8 +37,6 @@ var event = require("./lib/event"); var EventEmitter = require("./lib/event_emitter").EventEmitter; /** - * - * * A set of methods for setting and retrieving the editor's scrollbar. * @class ScrollBar **/ @@ -47,9 +45,6 @@ var EventEmitter = require("./lib/event_emitter").EventEmitter; * Creates a new `ScrollBar`. `parent` is the owner of the scroll bar. * @param {DOMElement} parent A DOM element * - * - * - * * @constructor **/ var ScrollBar = function(parent) { @@ -62,8 +57,8 @@ var ScrollBar = function(parent) { parent.appendChild(this.element); - // in OSX lion the scrollbars appear to have no width. In this case resize - // the to show the scrollbar but still pretend that the scrollbar has a width + // in OSX lion the scrollbars appear to have no width. In this case resize the + // element to show the scrollbar but still pretend that the scrollbar has a width // of 0px // in Firefox 6+ scrollbar is hidden if element has the same width as scrollbar // make element a little bit wider to retain scrollbar when page is zoomed @@ -80,9 +75,6 @@ var ScrollBar = function(parent) { * Emitted when the scroll bar, well, scrolls. * @event scroll * @param {Object} e Contains one property, `"data"`, which indicates the current scroll top position - * - * - * **/ this.onScroll = function() { if (!this.skipEvent) { @@ -93,7 +85,6 @@ var ScrollBar = function(parent) { }; /** - * * Returns the width of the scroll bar. * @returns {Number} **/ @@ -104,9 +95,6 @@ var ScrollBar = function(parent) { /** * Sets the height of the scroll bar, in pixels. * @param {Number} height The new height - * - * - * **/ this.setHeight = function(height) { this.element.style.height = height + "px"; @@ -115,9 +103,6 @@ var ScrollBar = function(parent) { /** * Sets the inner height of the scroll bar, in pixels. * @param {Number} height The new inner height - * - * - * **/ this.setInnerHeight = function(height) { this.inner.style.height = height + "px"; @@ -129,9 +114,6 @@ var ScrollBar = function(parent) { /** * Sets the scroll top of the scroll bar. * @param {Number} scrollTop The new scroll top - * - * - * **/ this.setScrollTop = function(scrollTop) { if (this.scrollTop != scrollTop) { From 43f1788ad403899c847421fc4b757120b6412ee7 Mon Sep 17 00:00:00 2001 From: nightwing Date: Thu, 20 Jun 2013 15:44:07 +0400 Subject: [PATCH 3/6] use fake horizontal scrollbar --- lib/ace/css/editor.css | 20 ++- lib/ace/edit_session.js | 4 +- lib/ace/ext/textarea.js | 30 +--- lib/ace/scrollbar.js | 85 ++++++++++- lib/ace/virtual_renderer.js | 289 ++++++++++++++++++++++++------------ 5 files changed, 302 insertions(+), 126 deletions(-) diff --git a/lib/ace/css/editor.css b/lib/ace/css/editor.css index 8ebc1616..0063ba2d 100644 --- a/lib/ace/css/editor.css +++ b/lib/ace/css/editor.css @@ -71,8 +71,8 @@ .ace_scrollbar { position: absolute; - overflow-x: hidden; - overflow-y: scroll; + overflow: hidden; + overflow-y: auto; right: 0; top: 0; bottom: 0; @@ -84,6 +84,22 @@ left: 0; } +.ace_scrollbar-h { + position: absolute; + overflow-x: auto; + overflow-y: hidden; + right: 0; + left: 0; + bottom: 0; +} + +.ace_scrollbar-inner { + position: absolute; + height: 1px; + left: 0; +} + + .ace_print-margin { position: absolute; height: 100%; diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index 4f9ace1f..90b727ef 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -985,7 +985,7 @@ var EditSession = function(text, mode) { * **/ this.setScrollTop = function(scrollTop) { - scrollTop = Math.round(Math.max(0, scrollTop)); + scrollTop = Math.round(scrollTop); if (this.$scrollTop === scrollTop || isNaN(scrollTop)) return; @@ -1006,7 +1006,7 @@ var EditSession = function(text, mode) { * [Sets the value of the distance between the left of the editor and the leftmost part of the visible content.]{: #EditSession.setScrollLeft} **/ this.setScrollLeft = function(scrollLeft) { - scrollLeft = Math.round(Math.max(0, scrollLeft)); + scrollLeft = Math.round(scrollLeft); if (this.$scrollLeft === scrollLeft || isNaN(scrollLeft)) return; diff --git a/lib/ace/ext/textarea.js b/lib/ace/ext/textarea.js index a402e65f..fee9b9b2 100644 --- a/lib/ace/ext/textarea.js +++ b/lib/ace/ext/textarea.js @@ -288,21 +288,18 @@ function setupApi(editor, editorDiv, settingDiv, ace, options, loader) { settingDiv.hideButton.focus(); editor.on("focus", function onFocus() { editor.removeListener("focus", onFocus); - settingDiv.style.display = "none" + settingDiv.style.display = "none"; }); } else { editor.focus(); - }; + } }; + editor.$setOption = editor.setOption; editor.setOption = function(key, value) { if (options[key] == value) return; switch (key) { - case "gutter": - renderer.setShowGutter(toBool(value)); - break; - case "mode": if (value != "text") { // Load the required mode file. Files get loaded only once. @@ -366,18 +363,9 @@ function setupApi(editor, editorDiv, settingDiv, ace, options, loader) { break; } break; - - case "useSoftTabs": - session.setUseSoftTabs(toBool(value)); - break; - - case "showPrintMargin": - renderer.setShowPrintMargin(toBool(value)); - break; - - case "showInvisibles": - editor.setShowInvisibles(toBool(value)); - break; + + default: + editor.$setOption(key, toBool(value)); } options[key] = value; @@ -391,9 +379,7 @@ function setupApi(editor, editorDiv, settingDiv, ace, options, loader) { return options; }; - for (var option in exports.options) { - editor.setOption(option, exports.options[option]); - } + editor.setOptions(exports.options); return editor; } @@ -493,7 +479,7 @@ function setupSettingPanel(settingDiv, settingOpener, editor, options) { cValue == "true" ? "checked='true'" : "", "'>" ); - return + return; } builder.push("