From daacc6e9dd784b760352fe649324b2a7b59c3b1a Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 24 Sep 2014 02:58:30 +0200 Subject: [PATCH 1/5] fix typo --- common/modules/highlight.jsm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/modules/highlight.jsm b/common/modules/highlight.jsm index ab03dec7d..2099ec44c 100644 --- a/common/modules/highlight.jsm +++ b/common/modules/highlight.jsm @@ -166,7 +166,7 @@ var Highlights = Module("Highlight", { if (/^\s*$/.test(newStyle)) newStyle = null; if (newStyle == null && extend == null) { - if (highlight.defaultValue == null && highight.defaultExtends.length == 0) { + if (highlight.defaultValue == null && highlight.defaultExtends.length == 0) { highlight.style.enabled = false; delete this.loaded[highlight.class]; delete this.highlight[highlight.class]; From 333c565a827d833bf7cf467e8231218b9d13a1c7 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 24 Sep 2014 03:00:11 +0200 Subject: [PATCH 2/5] Use null as defaultValue for new highlights, e.g. ':hi Foo ...' --- common/modules/highlight.jsm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/common/modules/highlight.jsm b/common/modules/highlight.jsm index 2099ec44c..8727fda9e 100644 --- a/common/modules/highlight.jsm +++ b/common/modules/highlight.jsm @@ -155,7 +155,11 @@ var Highlights = Module("Highlight", { set: function set(key, newStyle, force, append, extend) { let [, class_, selectors] = key.match(/^([a-zA-Z_-]+)(.*)/); - let highlight = this.highlight[key] || this._create(false, [key]); + let highlight = this.highlight[key]; + if (!highlight) { + highlight = this._create(false, [key]); + highlight.defaultValue = null; + } let bases = extend || highlight.extends; if (append) { From c5ea925c565cc26f6a9f066bf955a7f430e0edc1 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 24 Sep 2014 03:00:54 +0200 Subject: [PATCH 3/5] Remove unnecessary regexp matcher --- common/modules/highlight.jsm | 2 -- 1 file changed, 2 deletions(-) diff --git a/common/modules/highlight.jsm b/common/modules/highlight.jsm index 8727fda9e..ec1d264f2 100644 --- a/common/modules/highlight.jsm +++ b/common/modules/highlight.jsm @@ -153,8 +153,6 @@ var Highlights = Module("Highlight", { get: function get(k) this.highlight[k], set: function set(key, newStyle, force, append, extend) { - let [, class_, selectors] = key.match(/^([a-zA-Z_-]+)(.*)/); - let highlight = this.highlight[key]; if (!highlight) { highlight = this._create(false, [key]); From b9b7f97812635864f1efabd7d21a70d22286b0b3 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 24 Sep 2014 03:16:17 +0200 Subject: [PATCH 4/5] Do not cast empty newStyle to null, used to init 'Find' style --- common/modules/highlight.jsm | 2 -- 1 file changed, 2 deletions(-) diff --git a/common/modules/highlight.jsm b/common/modules/highlight.jsm index ec1d264f2..125ad7fb6 100644 --- a/common/modules/highlight.jsm +++ b/common/modules/highlight.jsm @@ -165,8 +165,6 @@ var Highlights = Module("Highlight", { bases = highlight.extends.concat(bases); } - if (/^\s*$/.test(newStyle)) - newStyle = null; if (newStyle == null && extend == null) { if (highlight.defaultValue == null && highlight.defaultExtends.length == 0) { highlight.style.enabled = false; From 6c1954f21031e449c7682c5ca39aab0436cf06db Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 24 Sep 2014 03:16:27 +0200 Subject: [PATCH 5/5] Refactor highlight.set into `_reset`/`_set`, trying to make `clear` faster --- common/modules/highlight.jsm | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/common/modules/highlight.jsm b/common/modules/highlight.jsm index 125ad7fb6..207d36c21 100644 --- a/common/modules/highlight.jsm +++ b/common/modules/highlight.jsm @@ -166,16 +166,28 @@ var Highlights = Module("Highlight", { } if (newStyle == null && extend == null) { - if (highlight.defaultValue == null && highlight.defaultExtends.length == 0) { - highlight.style.enabled = false; - delete this.loaded[highlight.class]; - delete this.highlight[highlight.class]; - return null; - } - newStyle = highlight.defaultValue; - bases = highlight.defaultExtends; + return this._reset(highlight, force, bases, extend); + } else { + return this._set(highlight, newStyle, force, bases, extend); } + }, + + _reset: function set(highlight, force, bases, extend) { + if (highlight.defaultValue == null && highlight.defaultExtends.length == 0) { + highlight.style.enabled = false; + delete this.loaded[highlight.class]; + delete this.highlight[highlight.class]; + return null; + } + highlight.set("value", highlight.defaultValue || ""); + highlight.extends = highlight.defaultExtends; + if (force) + highlight.style.enabled = true; + this.highlight[highlight.class] = highlight; + return highlight; + }, + _set: function set(highlight, newStyle, force, bases, extend) { highlight.set("value", newStyle || ""); highlight.extends = array.uniq(bases, true); if (force) @@ -190,7 +202,7 @@ var Highlights = Module("Highlight", { */ clear: function clear() { for (let [k, v] in Iterator(this.highlight)) - this.set(k, null, true); + this._reset(v, true); }, /**