update applies-to widget on any style changes

This commit is contained in:
tophf 2017-11-15 08:32:22 +03:00
parent 9868a1819c
commit 14dbfdd915

View File

@ -38,6 +38,7 @@ function createAppliesToLineWidget(cm) {
// is it possible to avoid flickering?
window.addEventListener('load', updateWidgetStyle);
chrome.runtime.onMessage.addListener(onRuntimeMessage);
update();
}
@ -50,6 +51,7 @@ function createAppliesToLineWidget(cm) {
cm.off('change', onChange);
cm.off('optionChange', onOptionChange);
window.removeEventListener('load', updateWidgetStyle);
chrome.runtime.onMessage.removeListener(onRuntimeMessage);
}
function onChange(cm, {from, to, origin}) {
@ -72,6 +74,14 @@ function createAppliesToLineWidget(cm) {
}
}
function onRuntimeMessage(msg) {
if (msg.style || msg.styles ||
msg.prefs && 'disableAll' in msg.prefs ||
msg.method === 'styleDeleted') {
requestAnimationFrame(updateWidgetStyle);
}
}
function update() {
cm.operation(doUpdate);
}