Add "Use Hotkeys" to settings to enable/disable them

This commit is contained in:
Robbie Antenesse 2019-05-10 13:18:38 -06:00
parent 15bba03e1d
commit 5d38aa4e17
3 changed files with 21 additions and 5 deletions

View File

@ -151,6 +151,11 @@
Pronunciation fields.</small>
</label>
<label>Use Hotkeys
<input id="settingsUseHotkeys" type="checkbox" checked><br />
<small>Check this to enable keyboard combinations to perform different helpful actions.</small>
</label>
<label>Theme
<select disabled>
<option selected value="default">Default</option>

View File

@ -36,9 +36,9 @@ export function hotKeyActions(event) {
}
} break;
}
case 'd': if (event.ctrlKey) {event.preventDefault(); toggleDetailsDisplay()} break;
case 'e': if (event.ctrlKey) {event.preventDefault(); openEditModal()} break;
case 'h': if (event.ctrlKey) {event.preventDefault(); showHelpModal();} break;
case 'd': if (event.ctrlKey) {event.preventDefault(); toggleDetailsDisplay();} break;
case 'e': if (event.ctrlKey) {event.preventDefault(); hideAllModals(); openEditModal();} break;
case 'h': if (event.ctrlKey) {event.preventDefault(); hideAllModals(); showHelpModal();} break;
case 'm': if (event.ctrlKey) {event.preventDefault(); maximizeTextarea();} break;
case 's': {
if (event.ctrlKey) {
@ -52,7 +52,7 @@ export function hotKeyActions(event) {
}
break;
}
case 'S': if (event.ctrlKey) { event.preventDefault(); hideAllModals(); openSettingsModal(); } break;
case 'S': if (event.ctrlKey) {event.preventDefault(); hideAllModals(); openSettingsModal();} break;
case 'x': if (event.ctrlKey) {event.preventDefault(); clearSearchText();} break;
}
}

View File

@ -3,6 +3,7 @@ import { cloneObject } from "../helpers";
import { usePhondueDigraphs } from "./KeyboardFire/phondue/ipaField";
import { renderWords } from "./render";
import { addMessage } from "./utilities";
import { enableHotKeys, disableHotKeys } from "./hotkeys";
export function loadSettings() {
const storedSettings = window.localStorage.getItem(SETTINGS_KEY);
@ -16,17 +17,20 @@ export function saveSettings() {
}
export function openSettingsModal() {
const { useIPAPronunciationField } = window.settings;
const { useIPAPronunciationField, useHotkeys } = window.settings;
document.getElementById('settingsUseIPA').checked = useIPAPronunciationField;
document.getElementById('settingsUseHotkeys').checked = useHotkeys;
document.getElementById('settingsModal').style.display = '';
}
export function saveSettingsModal() {
window.settings.useIPAPronunciationField = document.getElementById('settingsUseIPA').checked;
window.settings.useHotkeys = document.getElementById('settingsUseHotkeys').checked;
saveSettings();
toggleHotkeysEnabled();
toggleIPAPronunciationFields();
}
@ -35,6 +39,13 @@ export function saveAndCloseSettingsModal() {
document.getElementById('settingsModal').style.display = 'none';
}
export function toggleHotkeysEnabled() {
disableHotKeys();
if (window.settings.useHotkeys) {
enableHotKeys();
}
}
export function toggleIPAPronunciationFields() {
const ipaButtons = document.querySelectorAll('.ipa-table-button, .ipa-field-help-button'),
ipaFields = document.querySelectorAll('.ipa-field');