Highlighting now works with the web worker

This commit is contained in:
n1474335 2017-09-19 23:34:03 +01:00
parent 8c960f0661
commit 13f07abb8a
10 changed files with 200 additions and 95 deletions

View file

@ -53,6 +53,13 @@ self.addEventListener("message", function(e) {
// imported into an inline worker.
self.docURL = e.data.data;
break;
case "highlight":
calculateHighlights(
e.data.data.recipeConfig,
e.data.data.direction,
e.data.data.pos
);
break;
default:
break;
}
@ -121,6 +128,25 @@ function loadRequiredModules(recipeConfig) {
}
/**
* Calculates highlight offsets if possible.
*
* @param {Object[]} recipeConfig
* @param {string} direction
* @param {Object} pos - The position object for the highlight.
* @param {number} pos.start - The start offset.
* @param {number} pos.end - The end offset.
*/
function calculateHighlights(recipeConfig, direction, pos) {
pos = self.chef.calculateHighlights(recipeConfig, direction, pos);
self.postMessage({
action: "highlightsCalculated",
data: pos
});
}
/**
* Send status update to the app.
*