diff options
| author | Alex Yatskov <alex@foosoft.net> | 2017-09-24 11:01:40 -0700 | 
|---|---|---|
| committer | Alex Yatskov <alex@foosoft.net> | 2017-09-24 11:01:40 -0700 | 
| commit | 00c20aed4253da6506194d90a6102920d3235ced (patch) | |
| tree | cfb2fd51a441241cb333a208b3ce3130add93953 /ext/fg/js | |
| parent | 3a1aad07d61411f634e86f905babd6fbbac2eae1 (diff) | |
| parent | 29812c1b036d3eae9b5b222219f556aec712c3e8 (diff) | |
Merge branch 'master' into firefox-amo
Diffstat (limited to 'ext/fg/js')
| -rw-r--r-- | ext/fg/js/document.js | 2 | ||||
| -rw-r--r-- | ext/fg/js/float.js | 2 | ||||
| -rw-r--r-- | ext/fg/js/frontend.js | 38 | ||||
| -rw-r--r-- | ext/fg/js/popup.js | 15 | ||||
| -rw-r--r-- | ext/fg/js/source.js | 4 | 
5 files changed, 35 insertions, 26 deletions
| diff --git a/ext/fg/js/document.js b/ext/fg/js/document.js index b1e71777..a1806d77 100644 --- a/ext/fg/js/document.js +++ b/ext/fg/js/document.js @@ -86,7 +86,7 @@ function docRangeFromPoint(point) {      }      const range = document.caretRangeFromPoint(point.x, point.y); -    if (range) { +    if (range && range.startContainer.nodeType === 3 && range.endContainer.nodeType === 3) {          return new TextSourceRange(range);      }  } diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js index 22374f8b..ff50483d 100644 --- a/ext/fg/js/float.js +++ b/ext/fg/js/float.js @@ -27,7 +27,7 @@ class DisplayFloat extends Display {          if (window.yomichan_orphaned) {              this.onOrphaned();          } else { -            window.alert(`Error: ${error}`); +            window.alert(`Error: ${error.toString ? error.toString() : error}`);          }      } diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 41c93f00..3a90b3ad 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -80,7 +80,6 @@ class Frontend {          const search = async () => {              try {                  await this.searchAt({x: e.clientX, y: e.clientY}); -                this.pendingLookup = false;              } catch (e) {                  this.onError(e);              } @@ -153,7 +152,7 @@ class Frontend {      }      onError(error) { -        window.alert(`Error: ${error}`); +        window.alert(`Error: ${error.toString ? error.toString() : error}`);      }      popupTimerSet(callback) { @@ -169,27 +168,17 @@ class Frontend {      }      async searchAt(point) { -        let textSource = null; - -        try { -            if (this.pendingLookup) { -                return; -            } - -            textSource = docRangeFromPoint(point); -            if (!textSource || !textSource.containsPoint(point)) { -                docImposterDestroy(); -                return; -            } - -            if (this.textSourceLast && this.textSourceLast.equals(textSource)) { -                return; -            } +        if (this.pendingLookup || this.popup.containsPoint(point)) { +            return; +        } -            this.pendingLookup = true; +        const textSource = docRangeFromPoint(point); +        let hideResults = !textSource || !textSource.containsPoint(point); -            if (!await this.searchTerms(textSource)) { -                await this.searchKanji(textSource); +        try { +            if (!hideResults && (!this.textSourceLast || !this.textSourceLast.equals(textSource))) { +                this.pendingLookup = true; +                hideResults = !await this.searchTerms(textSource) && !await this.searchKanji(textSource);              }          } catch (e) {              if (window.yomichan_orphaned) { @@ -200,7 +189,12 @@ class Frontend {                  this.onError(e);              }          } finally { -            docImposterDestroy(); +            if (hideResults && this.options.scanning.autoHideResults) { +                this.searchClear(); +            } else { +                docImposterDestroy(); +            } +              this.pendingLookup = false;          }      } diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index 03958832..d1009fe9 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -100,6 +100,21 @@ class Popup {          return this.injected && this.container.style.visibility !== 'hidden';      } +    containsPoint(point) { +        if (!this.isVisible()) { +            return false; +        } + +        const rect = this.container.getBoundingClientRect(); +        const contained = +            point.x >= rect.left && +            point.y >= rect.top && +            point.x < rect.right && +            point.y < rect.bottom; + +        return contained; +    } +      async termsShow(elementRect, definitions, options, context) {          await this.show(elementRect, options);          this.invokeApi('termsShow', {definitions, options, context}); diff --git a/ext/fg/js/source.js b/ext/fg/js/source.js index 3b6ecb2a..664dbec7 100644 --- a/ext/fg/js/source.js +++ b/ext/fg/js/source.js @@ -82,7 +82,7 @@ class TextSourceRange {      }      equals(other) { -        return other.range && other.range.compareBoundaryPoints(Range.START_TO_START, this.range) === 0; +        return other && other.range && other.range.compareBoundaryPoints(Range.START_TO_START, this.range) === 0;      }      static shouldEnter(node) { @@ -239,6 +239,6 @@ class TextSourceElement {      }      equals(other) { -        return other.element === this.element && other.content === this.content; +        return other && other.element === this.element && other.content === this.content;      }  } |