From b4dd81b4136babeced01e9f04ce27b9f8bfe0c9b Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 14 Sep 2023 15:13:46 +0200 Subject: [PATCH] wip #6188 @1 --- js/libs/fluidbook/fluidbook.search.js | 44 ++++++++++++++++++++++----- style/fluidbook.less | 11 ++++--- style/mixins.less | 6 ++-- 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/js/libs/fluidbook/fluidbook.search.js b/js/libs/fluidbook/fluidbook.search.js index 9e7b006c..96b17fae 100644 --- a/js/libs/fluidbook/fluidbook.search.js +++ b/js/libs/fluidbook/fluidbook.search.js @@ -357,6 +357,7 @@ FluidbookSearch.prototype = { }, _find: function (q, callback) { + this.resultPages = []; if (this.robust) { return this._findRobust(q, callback); } @@ -370,7 +371,7 @@ FluidbookSearch.prototype = { var terms = []; var total = 0; var doublePages = []; - this.resultPages = []; + var matchedWord, indexWord, searchTerm, term, page; var maxPage = this.fluidbook.contentlock.getMaxPage(); @@ -560,9 +561,41 @@ FluidbookSearch.prototype = { setRobustHighlightTerms: function (terms) { let term = terms.join(''); - let firstLetter = term.split('')[0]; - var h = {occurences: HIGHLIGHTS[firstLetter], color: 0, word: firstLetter, term: term}; - this.highlights.push(h); + let letters = term.split(''); + + let occurences = []; + + for (let i = 0; i < letters.length; i++) { + let letter = letters[i]; + if (i === 0) { + occurences = HIGHLIGHTS[letter]; + } else { + let filteredOccurences = []; + for (let j in occurences) { + let o = occurences[j]; + for (let k in HIGHLIGHTS[letter]) { + if (HIGHLIGHTS[letter][k].o === o.o + i) { + if (o.next === undefined) { + o.next = []; + } + o.next.push(HIGHLIGHTS[letter][k]); + filteredOccurences.push(o); + } + } + } + occurences = filteredOccurences; + } + } + + if (!occurences.length) { + return; + } + + for (let i in occurences) { + let o = occurences[i]; + this.highlights.push({occurences: [o], color: 0, word: term, term: term}); + this.highlights.push({occurences: o.next, color: 0, word: term, term: term}); + } }, clearHighlights: function () { @@ -660,9 +693,6 @@ FluidbookSearch.prototype = { width: (width + 2 * padding) * z, height: (position.height + padding * 3) * z }; - if (this.robust) { - coords.width = coords.height; - } var transform = {}; if (position.rotation) { transform.rotate = -position.rotation + 'deg'; diff --git a/style/fluidbook.less b/style/fluidbook.less index bdc5b86a..f8b13ce8 100644 --- a/style/fluidbook.less +++ b/style/fluidbook.less @@ -656,6 +656,7 @@ body, html { left: 0px; z-index: 6; pointer-events: none; + opacity: 0.3; .highlight { position: absolute; @@ -665,11 +666,11 @@ body, html { transform-origin: 0 0; - &.robust { - border-radius: 50% 50%; - animation: pulse 1s infinite alternate linear; - transform-origin: 50% 50%; - } + //&.robust { + // border-radius: 50% 50%; + // animation: pulse 1s infinite alternate linear; + // transform-origin: 50% 50%; + //} &[data-color="0"], &[data-color="5"], &[data-color="10"] { .highlight-area(#00ff00); diff --git a/style/mixins.less b/style/mixins.less index 43c01105..127faf94 100644 --- a/style/mixins.less +++ b/style/mixins.less @@ -10,9 +10,9 @@ .highlight-area(@color) { border-color: @color; - background-color: fade(@color, 30%); - &.robust{ - border-color: fade(@color, 35%); + background-color: @color; + &.robust { + border: 0; } } -- 2.39.5