This is an automated email from the ASF dual-hosted git repository. gerben pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-annotator.git
commit 871e51d777b6ebe11f193855e88e25cfed56cd71 Author: Gerben <[email protected]> AuthorDate: Tue Sep 8 19:13:21 2020 +0200 Support multi-selection in demo A hard-coded selection.getRangeAt(0) just looks sad. --- web/demo/index.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/web/demo/index.js b/web/demo/index.js index a821b89..cb96a40 100644 --- a/web/demo/index.js +++ b/web/demo/index.js @@ -89,6 +89,7 @@ function cleanup() { removeHighlight(); } target.normalize(); + info.innerText = ''; } const createMatcher = makeRefinable((selector) => { @@ -120,17 +121,19 @@ async function anchor(selector) { cleanupFunctions.push(removeHighlight); } - info.innerText = JSON.stringify(selector, null, 2); + info.innerText += JSON.stringify(selector, null, 2) + '\n\n'; } async function onSelectionChange() { cleanup(); - const selection = document.getSelection(); - const range = selection.getRangeAt(0); const scope = document.createRange(); scope.selectNodeContents(source); - const selector = await describeTextQuote(range, scope); - anchor(selector); + const selection = document.getSelection(); + for (let i = 0; i < selection.rangeCount; i++) { + const range = selection.getRangeAt(i); + const selector = await describeTextQuote(range, scope); + await anchor(selector); + } } function onSelectorExampleClick(event) {
