From c6523b8feae57e418284a03e4425fce76c970be3 Mon Sep 17 00:00:00 2001 From: nightwing Date: Mon, 1 Oct 2012 19:29:04 +0400 Subject: [PATCH] disable bold style if font doesn't support it --- lib/ace/layer/text.js | 7 ++++++- lib/ace/theme/github.css | 2 +- lib/ace/virtual_renderer.js | 28 ++++++++++++++++------------ 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/lib/ace/layer/text.js b/lib/ace/layer/text.js index c021069d..c53c7169 100644 --- a/lib/ace/layer/text.js +++ b/lib/ace/layer/text.js @@ -42,7 +42,8 @@ var Text = function(parentEl) { this.element.className = "ace_layer ace_text-layer"; parentEl.appendChild(this.element); - this.$characterSize = this.$measureSizes() || {width: 0, height: 0}; + this.$characterSize = {width: 0, height: 0}; + this.checkForSizeChanges(); this.$pollSizeChanges(); }; @@ -72,7 +73,11 @@ var Text = function(parentEl) { this.checkForSizeChanges = function() { var size = this.$measureSizes(); if (size && (this.$characterSize.width !== size.width || this.$characterSize.height !== size.height)) { + this.$measureNode.style.fontWeight = "bold"; + var boldSize = this.$measureSizes(); + this.$measureNode.style.fontWeight = ""; this.$characterSize = size; + this.allowBoldFonts = boldSize && boldSize.width === size.width && boldSize.height === size.height; this._emit("changeCharacterSize", {data: size}); } }; diff --git a/lib/ace/theme/github.css b/lib/ace/theme/github.css index 6233b427..1f7864f9 100644 --- a/lib/ace/theme/github.css +++ b/lib/ace/theme/github.css @@ -100,7 +100,7 @@ } /* bold keywords cause cursor issues for some fonts */ /* this disables bold style for editor and keeps for static highlighter */ -.ace-github.ace_editor .ace_line > span { +.ace-github.ace_nobold .ace_line > span { font-weight: normal !important; } diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index 5ec1ffc5..f5996eaa 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -103,9 +103,6 @@ var VirtualRenderer = function(container, theme) { this.$markerFront = new MarkerLayer(this.content); - this.characterWidth = textLayer.getCharacterWidth(); - this.lineHeight = textLayer.getLineHeight(); - this.$cursorLayer = new CursorLayer(this.content); this.$cursorPadding = 8; @@ -136,12 +133,8 @@ var VirtualRenderer = function(container, theme) { }; this.$textLayer.addEventListener("changeCharacterSize", function() { - _self.characterWidth = textLayer.getCharacterWidth(); - _self.lineHeight = textLayer.getLineHeight(); - _self.$updatePrintMargin(); + _self.updateCharacterSize(); _self.onResize(true); - - _self.$loop.schedule(_self.CHANGE_FULL); }); this.$size = { @@ -172,7 +165,7 @@ var VirtualRenderer = function(container, theme) { this.$loop.schedule(this.CHANGE_FULL); this.setPadding(4); - this.$updatePrintMargin(); + this.updateCharacterSize(); }; (function() { @@ -191,6 +184,17 @@ 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(); + }; /** * VirtualRenderer.setSession(session) @@ -1362,8 +1366,8 @@ var VirtualRenderer = function(container, theme) { * * [Adds a new class, `style`, to the editor.]{: #VirtualRenderer.setStyle} **/ - this.setStyle = function setStyle(style) { - dom.addCssClass(this.container, style); + this.setStyle = function setStyle(style, include) { + dom.setCssClass(this.container, style, include != false); }; /** @@ -1373,7 +1377,7 @@ var VirtualRenderer = function(container, theme) { * [Removes the class `style` from the editor.]{: #VirtualRenderer.unsetStyle} **/ this.unsetStyle = function unsetStyle(style) { - dom.removeCssClass(this.container, style); + dom.removeCssClass(this.container, style); }; /**