Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to highlight and small refactoring #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions common/modules/highlight.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -153,29 +153,41 @@ 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] || 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) {
newStyle = Styles.append(highlight.value || "", newStyle);
bases = highlight.extends.concat(bases);
}

if (/^\s*$/.test(newStyle))
newStyle = null;
if (newStyle == null && extend == null) {
if (highlight.defaultValue == null && highight.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)
Expand All @@ -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);
},

/**
Expand Down