diff --git a/lib/ace/layer/text.js b/lib/ace/layer/text.js index 84d2d2ec..43f24baa 100644 --- a/lib/ace/layer/text.js +++ b/lib/ace/layer/text.js @@ -50,7 +50,7 @@ var Text = function(parentEl) { this.element.className = "ace_layer ace_text-layer"; parentEl.appendChild(this.element); - this.$characterSize = this.$measureSizes(); + this.$characterSize = this.$measureSizes() || {width: 0, height: 0}; this.$pollSizeChanges(); }; @@ -75,14 +75,18 @@ var Text = function(parentEl) { return this.$characterSize.width || 1; }; + this.checkForSizeChanges = function() { + var size = this.$measureSizes(); + if (size && (this.$characterSize.width !== size.width || this.$characterSize.height !== size.height)) { + this.$characterSize = size; + this._dispatchEvent("changeCharaterSize", {data: size}); + } + }; + this.$pollSizeChanges = function() { var self = this; setInterval(function() { - var size = self.$measureSizes(); - if (self.$characterSize.width !== size.width || self.$characterSize.height !== size.height) { - self.$characterSize = size; - self._dispatchEvent("changeCharaterSize", {data: size}); - } + self.checkForSizeChanges(); }, 500); }; @@ -92,7 +96,7 @@ var Text = function(parentEl) { fontWeight : 1, fontStyle : 1, lineHeight : 1 - }, + }; this.$measureSizes = function() { var n = 1000; @@ -134,6 +138,12 @@ var Text = function(parentEl) { height: this.$measureNode.offsetHeight, width: this.$measureNode.offsetWidth / (n * 2) }; + + // Size and width can be null if the editor is not visible or + // detached from the document + if (size.width == 0 && size.height == 0) + return null; + return size; }; diff --git a/lib/ace/mode/java_highlight_rules.js b/lib/ace/mode/java_highlight_rules.js index 90f456d7..6efcd07e 100644 --- a/lib/ace/mode/java_highlight_rules.js +++ b/lib/ace/mode/java_highlight_rules.js @@ -12,13 +12,13 @@ var JavaHighlightRules = function() { // taken from http://download.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html var keywords = lang.arrayToMap( ("abstract|continue|for|new|switch|" + - "assert|default|goto|package|synchronized" + - "boolean|do|if|private|this" + - "break|double|implements|protected|throw" + - "byte|else|import|public|throws" + - "case|enum|instanceof|return|transient" + - "catch|extends|int|short|try" + - "char|final|interface|static|void" + + "assert|default|goto|package|synchronized|" + + "boolean|do|if|private|this|" + + "break|double|implements|protected|throw|" + + "byte|else|import|public|throws|" + + "case|enum|instanceof|return|transient|" + + "catch|extends|int|short|try|" + + "char|final|interface|static|void|" + "class|finally|long|strictfp|volatile|" + "const|float|native|super|while").split("|") ); @@ -27,7 +27,36 @@ var JavaHighlightRules = function() { ("null|Infinity|NaN|undefined").split("|") ); - + var langClasses = lang.arrayToMap( + ("AbstractMethodError|AssertionError|ClassCircularityError|"+ + "ClassFormatError|Deprecated|EnumConstantNotPresentException|"+ + "ExceptionInInitializerError|IllegalAccessError|"+ + "IllegalThreadStateException|InstantiationError|InternalError|"+ + "NegativeArraySizeException|NoSuchFieldError|Override|Process|"+ + "ProcessBuilder|SecurityManager|StringIndexOutOfBoundsException|"+ + "SuppressWarnings|TypeNotPresentException|UnknownError|"+ + "UnsatisfiedLinkError|UnsupportedClassVersionError|VerifyError|"+ + "InstantiationException|IndexOutOfBoundsException|"+ + "ArrayIndexOutOfBoundsException|CloneNotSupportedException|"+ + "NoSuchFieldException|IllegalArgumentException|NumberFormatException|"+ + "SecurityException|Void|InheritableThreadLocal|IllegalStateException|"+ + "InterruptedException|NoSuchMethodException|IllegalAccessException|"+ + "UnsupportedOperationException|Enum|StrictMath|Package|Compiler|"+ + "Readable|Runtime|StringBuilder|Math|IncompatibleClassChangeError|"+ + "NoSuchMethodError|ThreadLocal|RuntimePermission|ArithmeticException|"+ + "NullPointerException|Long|Integer|Short|Byte|Double|Number|Float|"+ + "Character|Boolean|StackTraceElement|Appendable|StringBuffer|"+ + "Iterable|ThreadGroup|Runnable|Thread|IllegalMonitorStateException|"+ + "StackOverflowError|OutOfMemoryError|VirtualMachineError|"+ + "ArrayStoreException|ClassCastException|LinkageError|"+ + "NoClassDefFoundError|ClassNotFoundException|RuntimeException|"+ + "Exception|ThreadDeath|Error|Throwable|System|ClassLoader|"+ + "Cloneable|Class|CharSequence|Comparable|String|Object").split("|") + ); + + var importClasses = lang.arrayToMap( + ("").split("|") + ); // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used @@ -70,6 +99,10 @@ var JavaHighlightRules = function() { return "variable.language"; else if (keywords.hasOwnProperty(value)) return "keyword"; + else if (langClasses.hasOwnProperty(value)) + return "support.function"; + else if (importClasses.hasOwnProperty(value)) + return "support.function"; else if (buildinConstants.hasOwnProperty(value)) return "constant.language"; else diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index 0027d18c..8ef081e0 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -192,6 +192,10 @@ var VirtualRenderer = function(container, theme) { this.$loop.schedule(this.CHANGE_FULL); }; + this.updateFontSize = function() { + this.$textLayer.checkForSizeChanges(); + }; + /** * Triggers resize of the editor */