aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-05-25 20:56:08 -0700
committerAlex Yatskov <alex@foosoft.net>2017-05-25 20:56:08 -0700
commit618a3cb319c247c7196b1b83389d5f43241ab0c6 (patch)
treea617adbb35be0645e20e96c62170e89b73d15d48
parent9aeb807d4b40717f0eef50de9b456ddaa08fbadd (diff)
support variable modifier keys, fixes #5
-rw-r--r--ext/bg/js/options.js6
-rw-r--r--ext/bg/js/util.js19
-rw-r--r--ext/bg/options.html14
-rw-r--r--ext/fg/js/driver.js17
4 files changed, 38 insertions, 18 deletions
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
@@ -83,10 +83,6 @@
</div>
<div class="checkbox">
- <label><input type="checkbox" id="hold-shift-to-scan"> Hold <kbd>Shift</kbd> to scan</label>
- </div>
-
- <div class="checkbox">
<label><input type="checkbox" id="select-matched-text"> Select matched text</label>
</div>
@@ -103,6 +99,16 @@
<label for="scan-length">Scan length (in characters)</label>
<input type="number" min="1" id="scan-length" class="form-control">
</div>
+
+ <div class="form-group">
+ <label for="scan-modifier-key">Scan modifier key</label>
+ <select class="form-control" id="scan-modifier-key">
+ <option value="none">None</option>
+ <option value="alt">Alt</option>
+ <option value="ctrl">Ctrl</option>
+ <option value="shift">Shift</option>
+ </select>
+ </div>
</div>
<div>
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 {