Skip to content

Commit

Permalink
add profile switching keyboard shortcuts (#832)
Browse files Browse the repository at this point in the history
* add profile switching

* add duplicate behavior dropdown (#853)

* duplicate behavior dropdown

* allow duplicate for existing users

* Update docs/anki-integration.md

Co-authored-by: James Maa <jmaa@berkeley.edu>
Signed-off-by: StefanVukovic99 <stefanvukovic44@gmail.com>

* Update docs/anki-integration.md

Co-authored-by: James Maa <jmaa@berkeley.edu>
Signed-off-by: StefanVukovic99 <stefanvukovic44@gmail.com>

* Update docs/anki-integration.md

Co-authored-by: James Maa <jmaa@berkeley.edu>
Signed-off-by: StefanVukovic99 <stefanvukovic44@gmail.com>

* remove suggestion comment

---------

Signed-off-by: StefanVukovic99 <stefanvukovic44@gmail.com>
Co-authored-by: James Maa <jmaa@berkeley.edu>

---------

Signed-off-by: StefanVukovic99 <stefanvukovic44@gmail.com>
Co-authored-by: James Maa <jmaa@berkeley.edu>
  • Loading branch information
StefanVukovic99 and jamesmaa committed Apr 22, 2024
1 parent c6d93a9 commit f0196aa
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 6 deletions.
8 changes: 5 additions & 3 deletions ext/data/schemas/options-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1154,8 +1154,8 @@
}
},
"default": [
{"action": "close", "argument": "", "key": "Escape", "modifiers": [], "scopes": ["popup"], "enabled": true},
{"action": "focusSearchBox", "argument": "", "key": "Escape", "modifiers": [], "scopes": ["search"], "enabled": true},
{"action": "close", "argument": "", "key": "Escape", "modifiers": [], "scopes": ["popup"], "enabled": true},
{"action": "focusSearchBox", "argument": "", "key": "Escape", "modifiers": [], "scopes": ["search"], "enabled": true},
{"action": "previousEntry", "argument": "3", "key": "PageUp", "modifiers": ["alt"], "scopes": ["popup", "search"], "enabled": true},
{"action": "nextEntry", "argument": "3", "key": "PageDown", "modifiers": ["alt"], "scopes": ["popup", "search"], "enabled": true},
{"action": "lastEntry", "argument": "", "key": "End", "modifiers": ["alt"], "scopes": ["popup", "search"], "enabled": true},
Expand All @@ -1164,12 +1164,14 @@
{"action": "nextEntry", "argument": "1", "key": "ArrowDown", "modifiers": ["alt"], "scopes": ["popup", "search"], "enabled": true},
{"action": "historyBackward", "argument": "", "key": "KeyB", "modifiers": ["alt"], "scopes": ["popup", "search"], "enabled": true},
{"action": "historyForward", "argument": "", "key": "KeyF", "modifiers": ["alt"], "scopes": ["popup", "search"], "enabled": true},
{"action": "profilePrevious", "argument": "", "key": "Minus", "modifiers": ["alt"], "scopes": ["popup", "search"], "enabled": true},
{"action": "profileNext", "argument": "", "key": "Equal", "modifiers": ["alt"], "scopes": ["popup", "search"], "enabled": true},
{"action": "addNoteKanji", "argument": "", "key": "KeyK", "modifiers": ["alt"], "scopes": ["popup", "search"], "enabled": true},
{"action": "addNoteTermKanji", "argument": "", "key": "KeyE", "modifiers": ["alt"], "scopes": ["popup", "search"], "enabled": true},
{"action": "addNoteTermKana", "argument": "", "key": "KeyR", "modifiers": ["alt"], "scopes": ["popup", "search"], "enabled": true},
{"action": "playAudio", "argument": "", "key": "KeyP", "modifiers": ["alt"], "scopes": ["popup", "search"], "enabled": true},
{"action": "viewNotes", "argument": "", "key": "KeyV", "modifiers": ["alt"], "scopes": ["popup", "search"], "enabled": true},
{"action": "copyHostSelection", "argument": "", "key": "KeyC", "modifiers": ["ctrl"], "scopes": ["popup"], "enabled": true}
{"action": "copyHostSelection", "argument": "", "key": "KeyC", "modifiers": ["ctrl"], "scopes": ["popup"], "enabled": true}
]
}
}
Expand Down
17 changes: 16 additions & 1 deletion ext/js/data/options-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,8 @@ export class OptionsUtil {
this._updateVersion28,
this._updateVersion29,
this._updateVersion30,
this._updateVersion31
this._updateVersion31,
this._updateVersion32
];
/* eslint-enable @typescript-eslint/unbound-method */
if (typeof targetVersion === 'number' && targetVersion < result.length) {
Expand Down Expand Up @@ -1244,6 +1245,20 @@ export class OptionsUtil {
}
}

/**
* - Added profilePrevious and profileNext to hotkeys.
* @type {import('options-util').UpdateFunction}
*/
async _updateVersion32(options) {
for (const profile of options.profiles) {
profile.options.inputs.hotkeys.push(
{action: 'profilePrevious', key: 'Minus', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
{action: 'profileNext', key: 'Equal', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true}
);
}
}


/**
* @param {string} url
* @returns {Promise<chrome.tabs.Tab>}
Expand Down
22 changes: 22 additions & 0 deletions ext/js/display/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ export class Display extends EventDispatcher {
['firstEntry', () => { this._focusEntry(0, 0, true); }],
['historyBackward', () => { this._sourceTermView(); }],
['historyForward', () => { this._nextTermView(); }],
['profilePrevious', async () => { await this._setProfile(-1); }],
['profileNext', async () => { await this._setProfile(1); }],
['copyHostSelection', () => this._copyHostSelection()],
['nextEntryDifferentDictionary', () => { this._focusEntryWithDifferentDictionary(1, true); }],
['previousEntryDifferentDictionary', () => { this._focusEntryWithDifferentDictionary(-1, true); }]
Expand Down Expand Up @@ -1996,6 +1998,26 @@ export class Display extends EventDispatcher {
this._focusEntry(this._index + count * sign, 0, true);
}

/**
* @param {number} direction
*/
async _setProfile(direction) {
const optionsFull = await this.application.api.optionsGetFull();

const profileCount = optionsFull.profiles.length;
const newProfile = (optionsFull.profileCurrent + direction + profileCount) % profileCount;

/** @type {import('settings-modifications').ScopedModificationSet} */
const modification = {
action: 'set',
path: 'profileCurrent',
value: newProfile,
scope: 'global',
optionsContext: null
};
await this.application.api.modifySettings([modification], 'search');
}

/** */
_closeAllPopupMenus() {
for (const popupMenu of PopupMenu.openMenus) {
Expand Down
2 changes: 2 additions & 0 deletions ext/js/pages/settings/keyboard-shortcuts-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export class KeyboardShortcutController {
['previousEntryDifferentDictionary', {scopes: new Set(['popup', 'search'])}],
['historyBackward', {scopes: new Set(['popup', 'search'])}],
['historyForward', {scopes: new Set(['popup', 'search'])}],
['profilePrevious', {scopes: new Set(['popup', 'search'])}],
['profileNext', {scopes: new Set(['popup', 'search'])}],
['addNoteKanji', {scopes: new Set(['popup', 'search'])}],
['addNoteTermKanji', {scopes: new Set(['popup', 'search'])}],
['addNoteTermKana', {scopes: new Set(['popup', 'search'])}],
Expand Down
2 changes: 2 additions & 0 deletions ext/templates-settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@
<option value="previousEntryDifferentDictionary">Go to previous dictionary</option>
<option value="historyBackward">Navigate backward in history</option>
<option value="historyForward">Navigate forward in history</option>
<option value="profilePrevious">Switch to previous profile</option>
<option value="profileNext">Switch to next profile</option>
<option value="addNoteKanji">Add kanji note</option>
<option value="addNoteTermKanji">Add term note</option>
<option value="addNoteTermKana">Add term note (reading)</option>
Expand Down
6 changes: 4 additions & 2 deletions test/options-util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,9 @@ function createProfileOptionsUpdatedTestData1() {
{action: 'addNoteTermKana', argument: '', key: 'KeyR', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
{action: 'playAudio', argument: '', key: 'KeyP', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
{action: 'viewNotes', argument: '', key: 'KeyV', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
{action: 'copyHostSelection', argument: '', key: 'KeyC', modifiers: ['ctrl'], scopes: ['popup'], enabled: true}
{action: 'copyHostSelection', argument: '', key: 'KeyC', modifiers: ['ctrl'], scopes: ['popup'], enabled: true},
{action: 'profilePrevious', argument: '', key: 'Minus', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true},
{action: 'profileNext', argument: '', key: 'Equal', modifiers: ['alt'], scopes: ['popup', 'search'], enabled: true}
]
/* eslint-enable @stylistic/no-multi-spaces */
},
Expand Down Expand Up @@ -603,7 +605,7 @@ function createOptionsUpdatedTestData1() {
}
],
profileCurrent: 0,
version: 31,
version: 32,
global: {
database: {
prefixWildcardsSupported: false
Expand Down

0 comments on commit f0196aa

Please sign in to comment.