From b04c4d8be79a476bf408eb3ad74648baf7ba8cf5 Mon Sep 17 00:00:00 2001
From: Alex Yatskov
Date: Sat, 20 May 2017 18:15:51 -0700
Subject: block RT and some other tags when scanning, fixes #50, #30
---
ext/fg/js/source-range.js | 54 +++++++++++++++++++++++++++++------------------
1 file changed, 34 insertions(+), 20 deletions(-)
(limited to 'ext/fg')
diff --git a/ext/fg/js/source-range.js b/ext/fg/js/source-range.js
index 6d445f54..5db0ffc7 100644
--- a/ext/fg/js/source-range.js
+++ b/ext/fg/js/source-range.js
@@ -20,27 +20,30 @@
class TextSourceRange {
constructor(range) {
this.rng = range;
+ this.content = '';
}
clone() {
- return new TextSourceRange(this.rng.cloneRange());
+ const tmp = new TextSourceRange(this.rng.cloneRange());
+ tmp.content = this.content;
+ return tmp;
}
text() {
- return this.rng.toString();
+ return this.content;
}
setEndOffset(length) {
- const lengthAdj = length + this.rng.startOffset;
- const state = TextSourceRange.seekForward(this.rng.startContainer, lengthAdj);
+ const state = TextSourceRange.seekForward(this.rng.startContainer, this.rng.startOffset, length);
this.rng.setEnd(state.node, state.offset);
+ this.content = state.content;
return length - state.length;
}
setStartOffset(length) {
- const lengthAdj = length + (this.rng.startContainer.length - this.rng.startOffset);
- const state = TextSourceRange.seekBackward(this.rng.startContainer, lengthAdj);
+ const state = TextSourceRange.seekBackward(this.rng.startContainer, this.rng.startOffset, length);
this.rng.setStart(state.node, state.offset);
+ this.content = state.content;
return length - state.length;
}
@@ -80,8 +83,13 @@ class TextSourceRange {
return other.rng && other.rng.compareBoundaryPoints(Range.START_TO_START, this.rng) === 0;
}
- static seekForward(node, length) {
- const state = {node, length, offset: 0};
+ static shouldEnter(node) {
+ const skip = ['RT', 'SCRIPT', 'STYLE'];
+ return !skip.includes(node.nodeName);
+ }
+
+ static seekForward(node, offset, length) {
+ const state = {node, offset, remainder: length, content: ''};
if (!TextSourceRange.seekForwardHelper(node, state)) {
return state;
}
@@ -99,11 +107,14 @@ class TextSourceRange {
static seekForwardHelper(node, state) {
if (node.nodeType === 3) {
- const consumed = Math.min(node.length, state.length);
+ const offset = state.node === node ? state.offset : 0;
+ const remaining = node.length - offset;
+ const consumed = Math.min(remaining, state.remainder);
+ state.content = state.content + node.nodeValue.substring(offset, offset + consumed);
state.node = node;
- state.offset = consumed;
- state.length -= consumed;
- } else {
+ state.offset = offset + consumed;
+ state.remainder -= consumed;
+ } else if (TextSourceRange.shouldEnter(node)) {
for (let i = 0; i < node.childNodes.length; ++i) {
if (!TextSourceRange.seekForwardHelper(node.childNodes[i], state)) {
break;
@@ -111,11 +122,11 @@ class TextSourceRange {
}
}
- return state.length > 0;
+ return state.remainder > 0;
}
- static seekBackward(node, length) {
- const state = {node, length, offset: node.length};
+ static seekBackward(node, offset, length) {
+ const state = {node, offset, remainder: length, content: ''};
if (!TextSourceRange.seekBackwardHelper(node, state)) {
return state;
}
@@ -133,11 +144,14 @@ class TextSourceRange {
static seekBackwardHelper(node, state) {
if (node.nodeType === 3) {
- const consumed = Math.min(node.length, state.length);
+ const offset = state.node === node ? state.offset : node.length;
+ const remaining = offset;
+ const consumed = Math.min(remaining, state.remainder);
+ state.content = node.nodeValue.substring(offset - consumed, offset) + state.content;
state.node = node;
- state.offset = node.length - consumed;
- state.length -= consumed;
- } else {
+ state.offset = offset - consumed;
+ state.remainder -= consumed;
+ } else if (TextSourceRange.shouldEnter(node)) {
for (let i = node.childNodes.length - 1; i >= 0; --i) {
if (!TextSourceRange.seekBackwardHelper(node.childNodes[i], state)) {
break;
@@ -145,6 +159,6 @@ class TextSourceRange {
}
}
- return state.length > 0;
+ return state.remainder > 0;
}
}
--
cgit v1.2.3
From 52f092f0d2709e4fb8b1c00a4aea1fba97920509 Mon Sep 17 00:00:00 2001
From: Alex Yatskov
Date: Sat, 20 May 2017 18:34:13 -0700
Subject: fixing old variable name
---
ext/fg/js/source-range.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'ext/fg')
diff --git a/ext/fg/js/source-range.js b/ext/fg/js/source-range.js
index 5db0ffc7..58b6a415 100644
--- a/ext/fg/js/source-range.js
+++ b/ext/fg/js/source-range.js
@@ -37,14 +37,14 @@ class TextSourceRange {
const state = TextSourceRange.seekForward(this.rng.startContainer, this.rng.startOffset, length);
this.rng.setEnd(state.node, state.offset);
this.content = state.content;
- return length - state.length;
+ return length - state.remainder;
}
setStartOffset(length) {
const state = TextSourceRange.seekBackward(this.rng.startContainer, this.rng.startOffset, length);
this.rng.setStart(state.node, state.offset);
this.content = state.content;
- return length - state.length;
+ return length - state.remainder;
}
containsPoint(point) {
--
cgit v1.2.3
From 84f5954ad52e82b795b1e493a9111355ddaa0f07 Mon Sep 17 00:00:00 2001
From: Alex Yatskov
Date: Sun, 21 May 2017 22:44:22 -0700
Subject: handle scanning text for janky websites better #23
---
ext/fg/js/source-range.js | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
(limited to 'ext/fg')
diff --git a/ext/fg/js/source-range.js b/ext/fg/js/source-range.js
index 58b6a415..95177f0b 100644
--- a/ext/fg/js/source-range.js
+++ b/ext/fg/js/source-range.js
@@ -84,8 +84,22 @@ class TextSourceRange {
}
static shouldEnter(node) {
+ if (node.nodeType !== 1) {
+ return false;
+ }
+
const skip = ['RT', 'SCRIPT', 'STYLE'];
- return !skip.includes(node.nodeName);
+ if (skip.includes(node.nodeName)) {
+ return false;
+ }
+
+ const style = window.getComputedStyle(node);
+ const hidden =
+ style.visibility === 'hidden' ||
+ style.display === 'none' ||
+ parseFloat(style.fontSize) === 0;
+
+ return !hidden;
}
static seekForward(node, offset, length) {
@@ -106,7 +120,7 @@ class TextSourceRange {
}
static seekForwardHelper(node, state) {
- if (node.nodeType === 3) {
+ if (node.nodeType === 3 && node.parentElement && TextSourceRange.shouldEnter(node.parentElement)) {
const offset = state.node === node ? state.offset : 0;
const remaining = node.length - offset;
const consumed = Math.min(remaining, state.remainder);
@@ -143,7 +157,7 @@ class TextSourceRange {
}
static seekBackwardHelper(node, state) {
- if (node.nodeType === 3) {
+ if (node.nodeType === 3 && node.parentElement && TextSourceRange.shouldEnter(node.parentElement)) {
const offset = state.node === node ? state.offset : node.length;
const remaining = offset;
const consumed = Math.min(remaining, state.remainder);
--
cgit v1.2.3
From fd346ae44b75afa2a081d3ce270568258dd8390b Mon Sep 17 00:00:00 2001
From: Alex Yatskov
Date: Mon, 22 May 2017 21:07:25 -0700
Subject: wip
---
ext/fg/js/source-element.js | 33 +++++++++++++++++----------------
ext/fg/js/source-range.js | 26 ++++++++++++--------------
2 files changed, 29 insertions(+), 30 deletions(-)
(limited to 'ext/fg')
diff --git a/ext/fg/js/source-element.js b/ext/fg/js/source-element.js
index 69fbc5ab..a8101382 100644
--- a/ext/fg/js/source-element.js
+++ b/ext/fg/js/source-element.js
@@ -18,41 +18,42 @@
class TextSourceElement {
- constructor(element, length=-1) {
+ constructor(element, content='') {
this.element = element;
- this.length = length;
+ this.content = content;
}
clone() {
- return new TextSourceElement(this.element, this.length);
+ return new TextSourceElement(this.element, this.content);
}
text() {
- const text = this.textRaw();
- return this.length < 0 ? text : text.substring(0, this.length);
+ return this.content;
}
- textRaw() {
+ setEndOffset(length) {
switch (this.element.nodeName) {
case 'BUTTON':
- return this.element.innerHTML;
+ this.content = this.element.innerHTML;
+ break;
case 'IMG':
- return this.element.getAttribute('alt');
+ this.content = this.element.getAttribute('alt');
+ break;
default:
- return this.element.value || '';
+ this.content = this.element.value;
+ break;
}
+
+ this.content = this.content || '';
+ this.content = this.content.substring(0, length);
+
+ return this.content.length;
}
setStartOffset(length) {
- // NOP
return 0;
}
- setEndOffset(length) {
- this.length = length;
- return length;
- }
-
containsPoint(point) {
const rect = this.getRect();
return point.x >= rect.left && point.x <= rect.right;
@@ -71,6 +72,6 @@ class TextSourceElement {
}
equals(other) {
- return other.element && other.textRaw() === this.textRaw();
+ return other.element === this.element && other.content === this.content;
}
}
diff --git a/ext/fg/js/source-range.js b/ext/fg/js/source-range.js
index 95177f0b..fa73b0a4 100644
--- a/ext/fg/js/source-range.js
+++ b/ext/fg/js/source-range.js
@@ -18,15 +18,13 @@
class TextSourceRange {
- constructor(range) {
- this.rng = range;
- this.content = '';
+ constructor(range, content='') {
+ this.range = range;
+ this.content = content;
}
clone() {
- const tmp = new TextSourceRange(this.rng.cloneRange());
- tmp.content = this.content;
- return tmp;
+ return new TextSourceRange(this.range.cloneRange(), this.content);
}
text() {
@@ -34,15 +32,15 @@ class TextSourceRange {
}
setEndOffset(length) {
- const state = TextSourceRange.seekForward(this.rng.startContainer, this.rng.startOffset, length);
- this.rng.setEnd(state.node, state.offset);
+ const state = TextSourceRange.seekForward(this.range.startContainer, this.range.startOffset, length);
+ this.range.setEnd(state.node, state.offset);
this.content = state.content;
return length - state.remainder;
}
setStartOffset(length) {
- const state = TextSourceRange.seekBackward(this.rng.startContainer, this.rng.startOffset, length);
- this.rng.setStart(state.node, state.offset);
+ const state = TextSourceRange.seekBackward(this.range.startContainer, this.range.startOffset, length);
+ this.range.setStart(state.node, state.offset);
this.content = state.content;
return length - state.remainder;
}
@@ -53,11 +51,11 @@ class TextSourceRange {
}
getRect() {
- return this.rng.getBoundingClientRect();
+ return this.range.getBoundingClientRect();
}
getPaddedRect() {
- const range = this.rng.cloneRange();
+ const range = this.range.cloneRange();
const startOffset = range.startOffset;
const endOffset = range.endOffset;
const node = range.startContainer;
@@ -71,7 +69,7 @@ class TextSourceRange {
select() {
const selection = window.getSelection();
selection.removeAllRanges();
- selection.addRange(this.rng);
+ selection.addRange(this.range);
}
deselect() {
@@ -80,7 +78,7 @@ class TextSourceRange {
}
equals(other) {
- return other.rng && other.rng.compareBoundaryPoints(Range.START_TO_START, this.rng) === 0;
+ return other.range && other.range.compareBoundaryPoints(Range.START_TO_START, this.range) === 0;
}
static shouldEnter(node) {
--
cgit v1.2.3
From 48693fa5942b8dc908615f73f08ceac8937b8216 Mon Sep 17 00:00:00 2001
From: Alex Yatskov
Date: Mon, 22 May 2017 22:27:09 -0700
Subject: fix search for input controls
---
ext/fg/js/driver.js | 3 +++
ext/fg/js/util.js | 8 --------
2 files changed, 3 insertions(+), 8 deletions(-)
(limited to 'ext/fg')
diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js
index e94a4ac2..98c50a02 100644
--- a/ext/fg/js/driver.js
+++ b/ext/fg/js/driver.js
@@ -144,6 +144,7 @@ window.driver = new class {
const textSource = docRangeFromPoint(point, this.options.scanning.imposter);
if (!textSource || !textSource.containsPoint(point)) {
+ docImposterDestroy();
return;
}
@@ -168,6 +169,7 @@ window.driver = new class {
return bgTermsFind(textSource.text()).then(({definitions, length}) => {
if (definitions.length === 0) {
+ docImposterDestroy();
return false;
} else {
textSource.setEndOffset(length);
@@ -186,6 +188,7 @@ window.driver = new class {
textSource.select();
}
+ docImposterDestroy();
return true;
}
});
diff --git a/ext/fg/js/util.js b/ext/fg/js/util.js
index e5705ffd..88d160cc 100644
--- a/ext/fg/js/util.js
+++ b/ext/fg/js/util.js
@@ -112,12 +112,6 @@ function docImposterDestroy() {
}
}
-function docImposterHide() {
- for (const element of document.getElementsByClassName('yomichan-imposter')) {
- element.style.visibility = 'hidden';
- }
-}
-
function docRangeFromPoint(point, imposter) {
const element = document.elementFromPoint(point.x, point.y);
if (element !== null) {
@@ -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;
}
--
cgit v1.2.3
From c0f74bbc8f6e8dde4f8e254d3f4b260b4209daaa Mon Sep 17 00:00:00 2001
From: Alex Yatskov
Date: Tue, 23 May 2017 22:51:48 -0700
Subject: smarter imposter hiding, version bump
---
ext/fg/js/driver.js | 3 +--
ext/manifest.json | 2 +-
2 files changed, 2 insertions(+), 3 deletions(-)
(limited to 'ext/fg')
diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js
index 98c50a02..e11b5014 100644
--- a/ext/fg/js/driver.js
+++ b/ext/fg/js/driver.js
@@ -160,6 +160,7 @@ window.driver = new class {
}).catch(error => {
this.handleError(error, textSource);
}).then(() => {
+ docImposterDestroy();
this.pendingLookup = false;
});
}
@@ -169,7 +170,6 @@ window.driver = new class {
return bgTermsFind(textSource.text()).then(({definitions, length}) => {
if (definitions.length === 0) {
- docImposterDestroy();
return false;
} else {
textSource.setEndOffset(length);
@@ -188,7 +188,6 @@ window.driver = new class {
textSource.select();
}
- docImposterDestroy();
return true;
}
});
diff --git a/ext/manifest.json b/ext/manifest.json
index eac8c058..8b6a9a02 100644
--- a/ext/manifest.json
+++ b/ext/manifest.json
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Yomichan",
- "version": "1.1.17",
+ "version": "1.1.18",
"description": "Japanese dictionary with Anki integration",
"icons": {"16": "mixed/img/icon16.png", "48": "mixed/img/icon48.png", "128": "mixed/img/icon128.png"},
--
cgit v1.2.3
From 992852d3c0aab94044e4a850f598bed38dbc2579 Mon Sep 17 00:00:00 2001
From: Alex Yatskov
Date: Wed, 24 May 2017 20:42:54 -0700
Subject: make form search be always enabled
---
ext/bg/js/options.js | 2 --
ext/bg/js/util.js | 1 -
ext/bg/options.html | 12 ++++--------
ext/fg/js/driver.js | 2 +-
ext/fg/js/util.js | 4 ++--
5 files changed, 7 insertions(+), 14 deletions(-)
(limited to 'ext/fg')
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index 1bd106d8..8c9e49e1 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -39,7 +39,6 @@ function formRead() {
optionsNew.scanning.requireShift = $('#hold-shift-to-scan').prop('checked');
optionsNew.scanning.middleMouse = $('#middle-mouse-button-scan').prop('checked');
optionsNew.scanning.selectText = $('#select-matched-text').prop('checked');
- optionsNew.scanning.imposter = $('#search-form-text-fields').prop('checked');
optionsNew.scanning.alphanumeric = $('#search-alphanumeric').prop('checked');
optionsNew.scanning.delay = parseInt($('#scan-delay').val(), 10);
optionsNew.scanning.length = parseInt($('#scan-length').val(), 10);
@@ -136,7 +135,6 @@ $(document).ready(() => {
$('#hold-shift-to-scan').prop('checked', options.scanning.requireShift);
$('#middle-mouse-button-scan').prop('checked', options.scanning.middleMouse);
$('#select-matched-text').prop('checked', options.scanning.selectText);
- $('#search-form-text-fields').prop('checked', options.scanning.imposter);
$('#search-alphanumeric').prop('checked', options.scanning.alphanumeric);
$('#scan-delay').val(options.scanning.delay);
$('#scan-length').val(options.scanning.length);
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 6e97b0ea..413fbaca 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -111,7 +111,6 @@ function optionsSetDefaults(options) {
requireShift: true,
middleMouse: true,
selectText: true,
- imposter: true,
alphanumeric: true,
delay: 15,
length: 10
diff --git a/ext/bg/options.html b/ext/bg/options.html
index 4898a3eb..e36e0511 100644
--- a/ext/bg/options.html
+++ b/ext/bg/options.html
@@ -90,10 +90,6 @@
-
-
-
-
@@ -173,15 +169,15 @@
AnkiConnect plugin for Anki.
-
-
-
-
Error:
+
+
+
+
diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js
index e11b5014..bdcc01b3 100644
--- a/ext/fg/js/driver.js
+++ b/ext/fg/js/driver.js
@@ -142,7 +142,7 @@ window.driver = new class {
return;
}
- const textSource = docRangeFromPoint(point, this.options.scanning.imposter);
+ const textSource = docRangeFromPoint(point);
if (!textSource || !textSource.containsPoint(point)) {
docImposterDestroy();
return;
diff --git a/ext/fg/js/util.js b/ext/fg/js/util.js
index 88d160cc..a9e67976 100644
--- a/ext/fg/js/util.js
+++ b/ext/fg/js/util.js
@@ -112,12 +112,12 @@ function docImposterDestroy() {
}
}
-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);
}
}
--
cgit v1.2.3
From 9aeb807d4b40717f0eef50de9b456ddaa08fbadd Mon Sep 17 00:00:00 2001
From: Alex Yatskov
Date: Thu, 25 May 2017 09:09:15 -0700
Subject: fix buggy extent detection
---
ext/fg/js/util.js | 10 ++++++++++
1 file changed, 10 insertions(+)
(limited to 'ext/fg')
diff --git a/ext/fg/js/util.js b/ext/fg/js/util.js
index a9e67976..c6270ce6 100644
--- a/ext/fg/js/util.js
+++ b/ext/fg/js/util.js
@@ -160,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;
@@ -178,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;
--
cgit v1.2.3
From 618a3cb319c247c7196b1b83389d5f43241ab0c6 Mon Sep 17 00:00:00 2001
From: Alex Yatskov
Date: Thu, 25 May 2017 20:56:08 -0700
Subject: support variable modifier keys, fixes #5
---
ext/bg/js/options.js | 6 +++---
ext/bg/js/util.js | 19 +++++++++++++------
ext/bg/options.html | 14 ++++++++++----
ext/fg/js/driver.js | 17 ++++++++++++-----
4 files changed, 38 insertions(+), 18 deletions(-)
(limited to 'ext/fg')
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index 8c9e49e1..c3321012 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -27,7 +27,7 @@ function formRead() {
optionsNew.general.showGuide = $('#show-usage-guide').prop('checked');
optionsNew.general.audioSource = $('#audio-playback-source').val();
- optionsNew.general.audioVolume = $('#audio-playback-volume').val();
+ optionsNew.general.audioVolume = parseFloat($('#audio-playback-volume').val());
optionsNew.general.groupResults = $('#group-terms-results').prop('checked');
optionsNew.general.debugInfo = $('#show-debug-info').prop('checked');
optionsNew.general.showAdvanced = $('#show-advanced-options').prop('checked');
@@ -36,12 +36,12 @@ function formRead() {
optionsNew.general.popupHeight = parseInt($('#popup-height').val(), 10);
optionsNew.general.popupOffset = parseInt($('#popup-offset').val(), 10);
- optionsNew.scanning.requireShift = $('#hold-shift-to-scan').prop('checked');
optionsNew.scanning.middleMouse = $('#middle-mouse-button-scan').prop('checked');
optionsNew.scanning.selectText = $('#select-matched-text').prop('checked');
optionsNew.scanning.alphanumeric = $('#search-alphanumeric').prop('checked');
optionsNew.scanning.delay = parseInt($('#scan-delay').val(), 10);
optionsNew.scanning.length = parseInt($('#scan-length').val(), 10);
+ optionsNew.scanning.modifier = $('#scan-modifier-key').val();
optionsNew.anki.enable = $('#anki-enable').prop('checked');
optionsNew.anki.tags = $('#card-tags').val().split(/[,; ]+/);
@@ -132,12 +132,12 @@ $(document).ready(() => {
$('#popup-height').val(options.general.popupHeight);
$('#popup-offset').val(options.general.popupOffset);
- $('#hold-shift-to-scan').prop('checked', options.scanning.requireShift);
$('#middle-mouse-button-scan').prop('checked', options.scanning.middleMouse);
$('#select-matched-text').prop('checked', options.scanning.selectText);
$('#search-alphanumeric').prop('checked', options.scanning.alphanumeric);
$('#scan-delay').val(options.scanning.delay);
$('#scan-length').val(options.scanning.length);
+ $('#scan-modifier-key').val(options.scanning.modifier);
$('#dict-purge').click(onDictionaryPurge);
$('#dict-importer a').click(onDictionarySetUrl);
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 413fbaca..75833871 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -108,12 +108,12 @@ function optionsSetDefaults(options) {
},
scanning: {
- requireShift: true,
middleMouse: true,
selectText: true,
alphanumeric: true,
delay: 15,
- length: 10
+ length: 10,
+ modifier: 'shift'
},
dictionaries: {},
@@ -149,10 +149,10 @@ function optionsSetDefaults(options) {
function optionsVersion(options) {
const fixups = [
- () => { },
- () => { },
- () => { },
- () => { },
+ () => {},
+ () => {},
+ () => {},
+ () => {},
() => {
if (options.general.audioPlayback) {
options.general.audioSource = 'jpod101';
@@ -162,6 +162,13 @@ function optionsVersion(options) {
},
() => {
options.general.showGuide = false;
+ },
+ () => {
+ if (options.scanning.requireShift) {
+ options.scanning.modifier = 'shift';
+ } else {
+ options.scanning.modifier = 'none';
+ }
}
];
diff --git a/ext/bg/options.html b/ext/bg/options.html
index e36e0511..6a359f5e 100644
--- a/ext/bg/options.html
+++ b/ext/bg/options.html
@@ -82,10 +82,6 @@
-
-
-
-
@@ -103,6 +99,16 @@
+
+
+
+
+
diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js
index bdcc01b3..b0cc4613 100644
--- a/ext/fg/js/driver.js
+++ b/ext/fg/js/driver.js
@@ -70,15 +70,22 @@ window.driver = new class {
return;
}
- if (this.options.scanning.requireShift && !e.shiftKey && !(this.mouseDownMiddle && this.options.scanning.middleMouse)) {
+ const mouseScan = this.mouseDownMiddle && this.options.scanning.middleMouse;
+ const keyScan =
+ this.options.scanning.modifier === 'alt' && e.altKey ||
+ this.options.scanning.modifier === 'ctrl' && e.ctrlKey ||
+ this.options.scanning.modifier === 'shift' && e.shiftKey ||
+ this.options.scanning.modifier === 'none';
+
+ if (!keyScan && !mouseScan) {
return;
}
const searchFunc = () => this.searchAt(this.lastMousePos);
- if (this.options.scanning.requireShift) {
- searchFunc();
- } else {
+ if (this.options.scanning.modifier === 'none') {
this.popupTimerSet(searchFunc);
+ } else {
+ searchFunc();
}
}
@@ -232,7 +239,7 @@ window.driver = new class {
handleError(error, textSource) {
if (window.orphaned) {
- if (textSource && this.options.scanning.requireShift) {
+ if (textSource && this.options.scanning.modifier !== 'none') {
this.popup.showOrphaned(textSource.getRect(), this.options);
}
} else {
--
cgit v1.2.3