From defe4e5759354178c8a16d9df0bee0817abae99b Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 23 Apr 2016 21:09:33 -0700 Subject: WIP --- ext/fg/js/client.js | 14 ++++++-------- ext/fg/js/range.js | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) (limited to 'ext/fg/js') diff --git a/ext/fg/js/client.js b/ext/fg/js/client.js index 3df713a3..7e9a9896 100644 --- a/ext/fg/js/client.js +++ b/ext/fg/js/client.js @@ -57,7 +57,7 @@ class Client { if (this.enabled && (e.shiftKey || e.which === 2)) { this.searchAt(this.lastMousePos); } else { - this.popup.hide(); + this.hidePopup(); } } @@ -87,7 +87,7 @@ class Client { return; } - if (this.lastRange !== null && this.lastRange.equalTo(range)) { + if (this.lastRange !== null && this.lastRange.equals(range)) { return; } @@ -110,15 +110,13 @@ class Client { } showPopup(range, length, content) { - if (this.options.highlightText) { - range.setEnd(range.endContainer, range.startOffset + length); + this.popup.showNextTo(range, content); - const selection = window.getSelection(); - selection.removeAllRanges(); - selection.addRange(range); + if (this.options.highlightText) { + this.range.select(length); } - this.popup.showNextTo(range, content); + this.lastRange = range; } hidePopup() { diff --git a/ext/fg/js/range.js b/ext/fg/js/range.js index 473cc449..a5c38e39 100644 --- a/ext/fg/js/range.js +++ b/ext/fg/js/range.js @@ -67,10 +67,10 @@ class Range { deselect() { const selection = window.getSelection(); - selection.removeRange(this.range); + selection.removeAllRanges(); } - equalTo(range) { + equals(range) { const equal = range.compareBoundaryPoints(Range.END_TO_END, this.range) === 0 && range.compareBoundaryPoints(Range.START_TO_START, this.range) === 0; -- cgit v1.2.3