From 402cdad04b364f0b145df4ec0c9bb649f06170b7 Mon Sep 17 00:00:00 2001 From: nightwing Date: Wed, 27 Feb 2013 11:39:47 +0400 Subject: [PATCH 1/3] fix #1266: Scroller is collapsed when ace initialized with empty value --- lib/ace/ace.js | 2 +- lib/ace/virtual_renderer.js | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/ace/ace.js b/lib/ace/ace.js index c8dba8f2..bb365ed1 100644 --- a/lib/ace/ace.js +++ b/lib/ace/ace.js @@ -91,7 +91,7 @@ exports.edit = function(el) { var env = { document: doc, editor: editor, - onResize: editor.resize.bind(editor) + onResize: editor.resize.bind(editor, null) }; event.addListener(window, "resize", env.onResize); editor.on("destroy", function() { diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index 499e77cc..e81dfadd 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -262,12 +262,10 @@ var VirtualRenderer = function(container, theme) { * **/ this.updateFull = function(force) { - if (force){ + if (force) this.$renderChanges(this.CHANGE_FULL, true); - } - else { + else this.$loop.schedule(this.CHANGE_FULL); - } }; /** @@ -288,7 +286,7 @@ var VirtualRenderer = function(container, theme) { * **/ this.onResize = function(force, gutterWidth, width, height) { - var changes = this.CHANGE_SIZE; + var changes = 0; var size = this.$size; if (this.resizing > 2) @@ -302,6 +300,7 @@ var VirtualRenderer = function(container, theme) { if (height && (force || size.height != height)) { size.height = height; + changes = this.CHANGE_SIZE; size.scrollerHeight = this.scroller.clientHeight; if (!size.scrollerHeight) { @@ -321,6 +320,7 @@ var VirtualRenderer = function(container, theme) { width = dom.getInnerWidth(this.container); if (width && (force || this.resizing > 1 || size.width != width)) { + changes = this.CHANGE_SIZE; size.width = width; var gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0; @@ -740,6 +740,8 @@ var VirtualRenderer = function(container, theme) { }; this.$computeLayerConfig = function() { + if (!this.$size.scrollerHeight) + return this.onResize(true); var session = this.session; var offset = this.scrollTop % this.lineHeight; From 3dcfc56a40796888adbf9345fbf1da11e377ed71 Mon Sep 17 00:00:00 2001 From: nightwing Date: Wed, 27 Feb 2013 11:50:11 +0400 Subject: [PATCH 2/3] fix #1250: remove obsolete documentation for loadMode event --- api/edit_session.html | 27 ------- lib/ace/edit_session.js | 6 -- lib/ace/virtual_renderer.js | 137 +++++++++++++++++------------------- 3 files changed, 66 insertions(+), 104 deletions(-) diff --git a/api/edit_session.html b/api/edit_session.html index bb1cb682..11e79ed0 100644 --- a/api/edit_session.html +++ b/api/edit_session.html @@ -35,8 +35,6 @@ - @@ -619,31 +617,6 @@ -
-
-
-
-
    -
  • -
      -
    • EditSession.on("loadMode", function())
    • -
    -
      -
    -
  • -
-
-
-

Emitted when the mode is loaded.

- -
-

Emitted when the mode is loaded.

- -
-
-
-
-
diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index 183d9a63..efd1270f 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -96,12 +96,6 @@ var config = require("./config"); * @param {Object} e An object containing one property, `"data"`, that contains information about the changing rows * **/ -/** - * Emitted when the mode is loaded. - * - * @event loadMode - * - **/ /** * Emitted when the current mode changes. * diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index e81dfadd..719df69a 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -3,7 +3,7 @@ * * Copyright (c) 2010, Ajax.org B.V. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ * * Neither the name of Ajax.org B.V. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -48,8 +48,6 @@ var editorCss = require("./requirejs/text!./css/editor.css"); dom.importCssString(editorCss, "ace_editor"); /** - * - * * The class that is responsible for drawing everything you see on the screen! * @class VirtualRenderer **/ @@ -59,9 +57,6 @@ dom.importCssString(editorCss, "ace_editor"); * @param {DOMElement} container The root element of the editor * @param {String} theme The starting theme * - * - * - * * @constructor **/ @@ -182,34 +177,34 @@ var VirtualRenderer = function(container, theme) { this.CHANGE_H_SCROLL = 1024; oop.implement(this, EventEmitter); - + this.updateCharacterSize = function() { if (this.$textLayer.allowBoldFonts != this.$allowBoldFonts) { this.$allowBoldFonts = this.$textLayer.allowBoldFonts; this.setStyle("ace_nobold", !this.$allowBoldFonts); } - + this.characterWidth = this.$textLayer.getCharacterWidth(); this.lineHeight = this.$textLayer.getLineHeight(); this.$updatePrintMargin(); }; /** - * + * * Associates the renderer with an [[EditSession `EditSession`]]. **/ this.setSession = function(session) { this.session = session; - + this.scroller.className = "ace_scroller"; - + this.$cursorLayer.setSession(session); this.$markerBack.setSession(session); this.$markerFront.setSession(session); this.$gutterLayer.setSession(session); this.$textLayer.setSession(session); this.$loop.schedule(this.CHANGE_FULL); - + }; /** @@ -217,7 +212,7 @@ var VirtualRenderer = function(container, theme) { * @param {Number} firstRow The first row to update * @param {Number} lastRow The last row to update * - * + * **/ this.updateLines = function(firstRow, lastRow) { if (lastRow === undefined) @@ -236,7 +231,7 @@ var VirtualRenderer = function(container, theme) { if (this.$changedLines.lastRow < lastRow) this.$changedLines.lastRow = lastRow; } - + if (this.$changedLines.firstRow > this.layerConfig.lastRow || this.$changedLines.lastRow < this.layerConfig.firstRow) return; @@ -259,7 +254,7 @@ var VirtualRenderer = function(container, theme) { * Triggers a full update of all the layers, for all the rows. * @param {Boolean} force If `true`, forces the changes through * - * + * **/ this.updateFull = function(force) { if (force) @@ -269,7 +264,7 @@ var VirtualRenderer = function(container, theme) { }; /** - * + * * Updates the font size. **/ this.updateFontSize = function() { @@ -283,7 +278,7 @@ var VirtualRenderer = function(container, theme) { * @param {Number} width The width of the editor in pixels * @param {Number} height The hiehgt of the editor, in pixels * - * + * **/ this.onResize = function(force, gutterWidth, width, height) { var changes = 0; @@ -336,10 +331,10 @@ var VirtualRenderer = function(container, theme) { this.$renderChanges(changes, true); else this.$loop.schedule(changes); - + if (force) this.$gutterLayer.$padding = null; - + if (force) delete this.resizing; }; @@ -355,7 +350,6 @@ var VirtualRenderer = function(container, theme) { }; /** - * * Adjusts the wrap limit, which is the number of characters that can fit within the width of the edit area on screen. **/ this.adjustWrapLimit = function() { @@ -400,7 +394,7 @@ var VirtualRenderer = function(container, theme) { this.getDisplayIndentGuides = function() { return this.getOption("displayIndentGuides"); }; - + this.setDisplayIndentGuides = function(display) { this.setOption("displayIndentGuides", display); }; @@ -474,7 +468,7 @@ var VirtualRenderer = function(container, theme) { this.$updateGutterLineHighlight = function() { var pos = this.$cursorLayer.$pixelPos; var height = this.layerConfig.lineHeight; - if (this.session.getUseWrapMode()) { + if (this.session.getUseWrapMode()) { var cursor = this.session.selection.getCursor(); cursor.column = 0; pos = this.$cursorLayer.getPixelPosition(cursor, true); @@ -483,7 +477,7 @@ var VirtualRenderer = function(container, theme) { this.$gutterLineHighlight.style.top = pos.top - this.layerConfig.offset + "px"; this.$gutterLineHighlight.style.height = height + "px"; }; - + this.$updatePrintMargin = function() { if (!this.$showPrintMargin && !this.$printMarginEl) return; @@ -503,7 +497,7 @@ var VirtualRenderer = function(container, theme) { }; /** - * + * * Returns the root element containing this renderer. * @returns {DOMElement} **/ @@ -512,7 +506,7 @@ var VirtualRenderer = function(container, theme) { }; /** - * + * * Returns the element that the mouse events are attached to * @returns {DOMElement} **/ @@ -521,7 +515,7 @@ var VirtualRenderer = function(container, theme) { }; /** - * + * * Returns the element to which the hidden text area is added. * @returns {DOMElement} **/ @@ -560,7 +554,7 @@ var VirtualRenderer = function(container, theme) { }; /** - * + * * [Returns the index of the first visible row.]{: #VirtualRenderer.getFirstVisibleRow} * @returns {Number} **/ @@ -569,7 +563,7 @@ var VirtualRenderer = function(container, theme) { }; /** - * + * * Returns the index of the first fully visible row. "Fully" here means that the characters in the row are not truncated; that the top and the bottom of the row are on the screen. * @returns {Number} **/ @@ -578,7 +572,7 @@ var VirtualRenderer = function(container, theme) { }; /** - * + * * Returns the index of the last fully visible row. "Fully" here means that the characters in the row are not truncated; that the top and the bottom of the row are on the screen. * @returns {Number} **/ @@ -588,7 +582,7 @@ var VirtualRenderer = function(container, theme) { }; /** - * + * * [Returns the index of the last visible row.]{: #VirtualRenderer.getLastVisibleRow} * @returns {Number} **/ @@ -601,8 +595,8 @@ var VirtualRenderer = function(container, theme) { /** * Sets the padding for all the layers. * @param {Number} padding A new padding value (in pixels) - * - * + * + * * **/ this.setPadding = function(padding) { @@ -616,7 +610,7 @@ var VirtualRenderer = function(container, theme) { }; /** - * + * * Returns whether the horizontal scrollbar is set to be always visible. * @returns {Boolean} **/ @@ -625,10 +619,10 @@ var VirtualRenderer = function(container, theme) { }; /** - * Identifies whether you want to show the horizontal scrollbar or not. + * Identifies whether you want to show the horizontal scrollbar or not. * @param {Boolean} alwaysVisible Set to `true` to make the horizontal scroll bar visible * - * + * **/ this.setHScrollBarAlwaysVisible = function(alwaysVisible) { if (this.$horizScrollAlwaysVisible != alwaysVisible) { @@ -735,13 +729,14 @@ var VirtualRenderer = function(container, theme) { if (changes & this.CHANGE_SIZE) this.$updateScrollBar(); - + this._signal("afterRender"); }; this.$computeLayerConfig = function() { if (!this.$size.scrollerHeight) return this.onResize(true); + var session = this.session; var offset = this.scrollTop % this.lineHeight; @@ -847,7 +842,7 @@ var VirtualRenderer = function(container, theme) { }; /** - * + * * Schedules an update to all the front markers in the document. **/ this.updateFrontMarkers = function() { @@ -856,7 +851,7 @@ var VirtualRenderer = function(container, theme) { }; /** - * + * * Schedules an update to all the back markers in the document. **/ this.updateBackMarkers = function() { @@ -864,8 +859,8 @@ var VirtualRenderer = function(container, theme) { this.$loop.schedule(this.CHANGE_MARKER_BACK); }; - /** - * + /** + * * Deprecated; (moved to [[EditSession]]) * @deprecated **/ @@ -873,7 +868,7 @@ var VirtualRenderer = function(container, theme) { this.$gutterLayer.addGutterDecoration(row, className); }; - /** + /** * Deprecated; (moved to [[EditSession]]) * @deprecated **/ @@ -882,7 +877,7 @@ var VirtualRenderer = function(container, theme) { }; /** - * + * * Redraw breakpoints. **/ this.updateBreakpoints = function(rows) { @@ -890,11 +885,11 @@ var VirtualRenderer = function(container, theme) { }; /** - * + * * Sets annotations for the gutter. * @param {Array} annotations An array containing annotations * - * + * **/ this.setAnnotations = function(annotations) { this.$gutterLayer.setAnnotations(annotations); @@ -902,7 +897,7 @@ var VirtualRenderer = function(container, theme) { }; /** - * + * * Updates the cursor icon. **/ this.updateCursor = function() { @@ -910,7 +905,7 @@ var VirtualRenderer = function(container, theme) { }; /** - * + * * Hides the cursor icon. **/ this.hideCursor = function() { @@ -918,7 +913,7 @@ var VirtualRenderer = function(container, theme) { }; /** - * + * * Shows the cursor icon. **/ this.showCursor = function() { @@ -932,7 +927,7 @@ var VirtualRenderer = function(container, theme) { }; /** - * + * * Scrolls the cursor into the first visibile area of the editor **/ this.scrollCursorIntoView = function(cursor, offset) { @@ -966,7 +961,7 @@ var VirtualRenderer = function(container, theme) { } }; - /** + /** * {:EditSession.getScrollTop} * @related EditSession.getScrollTop * @returns {Number} @@ -975,7 +970,7 @@ var VirtualRenderer = function(container, theme) { return this.session.getScrollTop(); }; - /** + /** * {:EditSession.getScrollLeft} * @related EditSession.getScrollLeft * @returns {Number} @@ -985,7 +980,7 @@ var VirtualRenderer = function(container, theme) { }; /** - * + * * Returns the first visible row, regardless of whether it's fully visible or not. * @returns {Number} **/ @@ -994,7 +989,7 @@ var VirtualRenderer = function(container, theme) { }; /** - * + * * Returns the last visible row, regardless of whether it's fully visible or not. * @returns {Number} **/ @@ -1002,11 +997,11 @@ var VirtualRenderer = function(container, theme) { return Math.max(0, Math.floor((this.scrollTop + this.$size.scrollerHeight) / this.lineHeight) - 1); }; - /** + /** * Gracefully scrolls from the top of the editor to the row indicated. * @param {Number} row A row id * - * + * * @related EditSession.setScrollTop **/ this.scrollToRow = function(row) { @@ -1048,7 +1043,7 @@ var VirtualRenderer = function(container, theme) { * @param {Boolean} animate If `true` animates scrolling * @param {Function} callback Function to be called after the animation has finished * - * + * **/ this.scrollToLine = function(line, center, animate, callback) { var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0}); @@ -1095,7 +1090,7 @@ var VirtualRenderer = function(container, theme) { * Scrolls the editor to the y pixel indicated. * @param {Number} scrollTop The position to scroll to * - * + * * @returns {Number} **/ this.scrollToY = function(scrollTop) { @@ -1111,7 +1106,7 @@ var VirtualRenderer = function(container, theme) { * Scrolls the editor across the x-axis to the pixel indicated. * @param {Number} scrollLeft The position to scroll to * - * + * * @returns {Number} **/ this.scrollToX = function(scrollLeft) { @@ -1128,7 +1123,7 @@ var VirtualRenderer = function(container, theme) { * @param {Number} deltaX The x value to scroll by * @param {Number} deltaY The y value to scroll by * - * + * **/ this.scrollBy = function(deltaX, deltaY) { deltaY && this.session.setScrollTop(this.session.getScrollTop() + deltaY); @@ -1140,7 +1135,7 @@ var VirtualRenderer = function(container, theme) { * @param {Number} deltaX The x value to scroll by * @param {Number} deltaY The y value to scroll by * - * + * * @returns {Boolean} **/ this.isScrollableBy = function(deltaX, deltaY) { @@ -1179,7 +1174,7 @@ var VirtualRenderer = function(container, theme) { * @param {Number} row The document row position * @param {Number} column The document column position * - * + * * * @returns {Object} **/ @@ -1197,7 +1192,7 @@ var VirtualRenderer = function(container, theme) { }; /** - * + * * Focuses the current container. **/ this.visualizeFocus = function() { @@ -1205,14 +1200,14 @@ var VirtualRenderer = function(container, theme) { }; /** - * + * * Blurs the current container. **/ this.visualizeBlur = function() { dom.removeCssClass(this.container, "ace_focus"); }; - /** + /** * @param {Number} position * * @private @@ -1240,7 +1235,7 @@ var VirtualRenderer = function(container, theme) { }; /** - * + * * Hides the current composition. **/ this.hideComposition = function() { @@ -1257,13 +1252,13 @@ var VirtualRenderer = function(container, theme) { * [Sets a new theme for the editor. `theme` should exist, and be a directory path, like `ace/theme/textmate`.]{: #VirtualRenderer.setTheme} * @param {String} theme The path to a theme * - * + * **/ this.setTheme = function(theme) { var _self = this; this.$themeValue = theme; _self._dispatchEvent('themeChange',{theme:theme}); - + if (!theme || typeof theme == "string") { var moduleName = theme || "ace/theme/textmate"; config.loadModule(["theme", moduleName], afterLoad); @@ -1297,7 +1292,7 @@ var VirtualRenderer = function(container, theme) { _self.$size.width = 0; _self.onResize(); } - + _self._dispatchEvent('themeLoaded',{theme:theme}); } }; @@ -1318,7 +1313,7 @@ var VirtualRenderer = function(container, theme) { * [Adds a new class, `style`, to the editor.]{: #VirtualRenderer.setStyle} * @param {String} style A class name * - * + * **/ this.setStyle = function setStyle(style, include) { dom.setCssClass(this.container, style, include != false); @@ -1328,14 +1323,14 @@ var VirtualRenderer = function(container, theme) { * [Removes the class `style` from the editor.]{: #VirtualRenderer.unsetStyle} * @param {String} style A class name * - * + * **/ this.unsetStyle = function unsetStyle(style) { dom.removeCssClass(this.container, style); }; /** - * + * * Destroys the text and cursor layers for this renderer. **/ this.destroy = function() { From 7f85b2584d11eb013921bd8bea03143c0ba81c21 Mon Sep 17 00:00:00 2001 From: nightwing Date: Thu, 28 Feb 2013 20:13:12 +0400 Subject: [PATCH 3/3] restore defferedCall --- lib/ace/lib/lang.js | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/ace/lib/lang.js b/lib/ace/lib/lang.js index 37b880bb..4e6ebf2c 100644 --- a/lib/ace/lib/lang.js +++ b/lib/ace/lib/lang.js @@ -144,9 +144,34 @@ exports.getMatchOffsets = function(string, regExp) { /* deprecated */ exports.deferredCall = function(fcn) { - if (typeof console != "undefined" && console.error) - console.error("Deprecated: use lang.delayedCall") - return exports.delayedCall(fcn); + + var timer = null; + var callback = function() { + timer = null; + fcn(); + }; + + var deferred = function(timeout) { + deferred.cancel(); + timer = setTimeout(callback, timeout || 0); + return deferred; + }; + + deferred.schedule = deferred; + + deferred.call = function() { + this.cancel(); + fcn(); + return deferred; + }; + + deferred.cancel = function() { + clearTimeout(timer); + timer = null; + return deferred; + }; + + return deferred; };