support variable modifier keys, fixes #5

This commit is contained in:
Alex Yatskov 2017-05-25 20:56:08 -07:00
parent 9aeb807d4b
commit 618a3cb319
4 changed files with 38 additions and 18 deletions

View File

@ -27,7 +27,7 @@ function formRead() {
optionsNew.general.showGuide = $('#show-usage-guide').prop('checked'); optionsNew.general.showGuide = $('#show-usage-guide').prop('checked');
optionsNew.general.audioSource = $('#audio-playback-source').val(); 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.groupResults = $('#group-terms-results').prop('checked');
optionsNew.general.debugInfo = $('#show-debug-info').prop('checked'); optionsNew.general.debugInfo = $('#show-debug-info').prop('checked');
optionsNew.general.showAdvanced = $('#show-advanced-options').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.popupHeight = parseInt($('#popup-height').val(), 10);
optionsNew.general.popupOffset = parseInt($('#popup-offset').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.middleMouse = $('#middle-mouse-button-scan').prop('checked');
optionsNew.scanning.selectText = $('#select-matched-text').prop('checked'); optionsNew.scanning.selectText = $('#select-matched-text').prop('checked');
optionsNew.scanning.alphanumeric = $('#search-alphanumeric').prop('checked'); optionsNew.scanning.alphanumeric = $('#search-alphanumeric').prop('checked');
optionsNew.scanning.delay = parseInt($('#scan-delay').val(), 10); optionsNew.scanning.delay = parseInt($('#scan-delay').val(), 10);
optionsNew.scanning.length = parseInt($('#scan-length').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.enable = $('#anki-enable').prop('checked');
optionsNew.anki.tags = $('#card-tags').val().split(/[,; ]+/); optionsNew.anki.tags = $('#card-tags').val().split(/[,; ]+/);
@ -132,12 +132,12 @@ $(document).ready(() => {
$('#popup-height').val(options.general.popupHeight); $('#popup-height').val(options.general.popupHeight);
$('#popup-offset').val(options.general.popupOffset); $('#popup-offset').val(options.general.popupOffset);
$('#hold-shift-to-scan').prop('checked', options.scanning.requireShift);
$('#middle-mouse-button-scan').prop('checked', options.scanning.middleMouse); $('#middle-mouse-button-scan').prop('checked', options.scanning.middleMouse);
$('#select-matched-text').prop('checked', options.scanning.selectText); $('#select-matched-text').prop('checked', options.scanning.selectText);
$('#search-alphanumeric').prop('checked', options.scanning.alphanumeric); $('#search-alphanumeric').prop('checked', options.scanning.alphanumeric);
$('#scan-delay').val(options.scanning.delay); $('#scan-delay').val(options.scanning.delay);
$('#scan-length').val(options.scanning.length); $('#scan-length').val(options.scanning.length);
$('#scan-modifier-key').val(options.scanning.modifier);
$('#dict-purge').click(onDictionaryPurge); $('#dict-purge').click(onDictionaryPurge);
$('#dict-importer a').click(onDictionarySetUrl); $('#dict-importer a').click(onDictionarySetUrl);

View File

@ -108,12 +108,12 @@ function optionsSetDefaults(options) {
}, },
scanning: { scanning: {
requireShift: true,
middleMouse: true, middleMouse: true,
selectText: true, selectText: true,
alphanumeric: true, alphanumeric: true,
delay: 15, delay: 15,
length: 10 length: 10,
modifier: 'shift'
}, },
dictionaries: {}, dictionaries: {},
@ -149,10 +149,10 @@ function optionsSetDefaults(options) {
function optionsVersion(options) { function optionsVersion(options) {
const fixups = [ const fixups = [
() => { }, () => {},
() => { }, () => {},
() => { }, () => {},
() => { }, () => {},
() => { () => {
if (options.general.audioPlayback) { if (options.general.audioPlayback) {
options.general.audioSource = 'jpod101'; options.general.audioSource = 'jpod101';
@ -162,6 +162,13 @@ function optionsVersion(options) {
}, },
() => { () => {
options.general.showGuide = false; options.general.showGuide = false;
},
() => {
if (options.scanning.requireShift) {
options.scanning.modifier = 'shift';
} else {
options.scanning.modifier = 'none';
}
} }
]; ];

View File

@ -82,10 +82,6 @@
<label><input type="checkbox" id="middle-mouse-button-scan"> Middle mouse button scans</label> <label><input type="checkbox" id="middle-mouse-button-scan"> Middle mouse button scans</label>
</div> </div>
<div class="checkbox">
<label><input type="checkbox" id="hold-shift-to-scan"> Hold <kbd>Shift</kbd> to scan</label>
</div>
<div class="checkbox"> <div class="checkbox">
<label><input type="checkbox" id="select-matched-text"> Select matched text</label> <label><input type="checkbox" id="select-matched-text"> Select matched text</label>
</div> </div>
@ -103,6 +99,16 @@
<label for="scan-length">Scan length (in characters)</label> <label for="scan-length">Scan length (in characters)</label>
<input type="number" min="1" id="scan-length" class="form-control"> <input type="number" min="1" id="scan-length" class="form-control">
</div> </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>
<div> <div>

View File

@ -70,15 +70,22 @@ window.driver = new class {
return; 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; return;
} }
const searchFunc = () => this.searchAt(this.lastMousePos); const searchFunc = () => this.searchAt(this.lastMousePos);
if (this.options.scanning.requireShift) { if (this.options.scanning.modifier === 'none') {
searchFunc();
} else {
this.popupTimerSet(searchFunc); this.popupTimerSet(searchFunc);
} else {
searchFunc();
} }
} }
@ -232,7 +239,7 @@ window.driver = new class {
handleError(error, textSource) { handleError(error, textSource) {
if (window.orphaned) { if (window.orphaned) {
if (textSource && this.options.scanning.requireShift) { if (textSource && this.options.scanning.modifier !== 'none') {
this.popup.showOrphaned(textSource.getRect(), this.options); this.popup.showOrphaned(textSource.getRect(), this.options);
} }
} else { } else {