aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js/util.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-05-25 23:06:10 -0700
committerAlex Yatskov <alex@foosoft.net>2017-05-25 23:06:10 -0700
commit16baf9a400ac11a1c4f53ba6665db03a900511e0 (patch)
tree685096179093f112a9263f15d3cf081f50e9634d /ext/fg/js/util.js
parent1cdf496824709b4e4579d700c333e832d790925e (diff)
parent618a3cb319c247c7196b1b83389d5f43241ab0c6 (diff)
Merge branch 'master' into firefox-amo
Diffstat (limited to 'ext/fg/js/util.js')
-rw-r--r--ext/fg/js/util.js22
1 files changed, 12 insertions, 10 deletions
diff --git a/ext/fg/js/util.js b/ext/fg/js/util.js
index e5705ffd..c6270ce6 100644
--- a/ext/fg/js/util.js
+++ b/ext/fg/js/util.js
@@ -112,18 +112,12 @@ function docImposterDestroy() {
}
}
-function docImposterHide() {
- for (const element of document.getElementsByClassName('yomichan-imposter')) {
- element.style.visibility = 'hidden';
- }
-}
-
-function docRangeFromPoint(point, imposter) {
+function docRangeFromPoint(point) {
const element = document.elementFromPoint(point.x, point.y);
if (element !== null) {
if (element.nodeName === 'IMG' || element.nodeName === 'BUTTON') {
return new TextSourceElement(element);
- } else if (imposter && (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA')) {
+ } else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {
docImposterCreate(element);
}
}
@@ -144,11 +138,9 @@ function docRangeFromPoint(point, imposter) {
const range = document.caretRangeFromPoint(point.x, point.y);
if (range !== null) {
- docImposterHide();
return new TextSourceRange(range);
}
- docImposterDestroy();
return null;
}
@@ -168,6 +160,11 @@ function docSentenceExtract(source, extent) {
for (let i = position; i >= startPos; --i) {
const c = content[i];
+ if (c === '\n') {
+ startPos = i + 1;
+ break;
+ }
+
if (quoteStack.length === 0 && (terminators.includes(c) || c in quotesFwd)) {
startPos = i + 1;
break;
@@ -186,6 +183,11 @@ function docSentenceExtract(source, extent) {
for (let i = position; i <= endPos; ++i) {
const c = content[i];
+ if (c === '\n') {
+ endPos = i + 1;
+ break;
+ }
+
if (quoteStack.length === 0) {
if (terminators.includes(c)) {
endPos = i + 1;