You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@annotator.apache.org by ge...@apache.org on 2020/03/05 23:14:16 UTC
[incubator-annotator] 02/03: Use removeHighlight() instead of
replacing innerHTML
This is an automated email from the ASF dual-hosted git repository.
gerben pushed a commit to branch use-highlighter-in-demo
in repository https://gitbox.apache.org/repos/asf/incubator-annotator.git
commit 7f7ea7c126dc4f9a2fbc531aa1f87dab0b97cb87
Author: Gerben <ge...@treora.com>
AuthorDate: Fri Mar 6 00:08:53 2020 +0100
Use removeHighlight() instead of replacing innerHTML
---
demo/index.js | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/demo/index.js b/demo/index.js
index 629d489..0506666 100644
--- a/demo/index.js
+++ b/demo/index.js
@@ -32,8 +32,13 @@ import {
} from '@annotator/dom';
import { makeRefinable } from '@annotator/selector';
-function clear() {
- corpus.innerHTML = selectable.innerHTML;
+const cleanupFunctions = [];
+
+function cleanup() {
+ let removeHighlight;
+ while (removeHighlight = cleanupFunctions.shift()) {
+ removeHighlight();
+ }
}
const createSelector = makeRefinable(selector => {
@@ -50,7 +55,7 @@ const createSelector = makeRefinable(selector => {
});
const refresh = async () => {
- clear();
+ cleanup();
const fragment = window.location.hash.slice(1);
if (!fragment) return;
@@ -64,7 +69,8 @@ const refresh = async () => {
}
for (const range of ranges) {
- highlightRange(range);
+ const removeHighlight = highlightRange(range);
+ cleanupFunctions.push(removeHighlight);
}
parsed.innerText = JSON.stringify(selector, null, 2);