diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-10-31 19:03:45 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-31 19:03:45 -0400 |
commit | 215ef627f13744f4041e4537ab163f71312215e5 (patch) | |
tree | 90e9200647d55fb76963b2c60c4e106f53af5ac0 /ext/bg/js/anki.js | |
parent | 94620f4f224ffec20b774dd75143ce5023c60b83 (diff) |
Duplicate scope options (#955)
* Add deck-root duplicate scope option
* Implement support for deck-root scope
Diffstat (limited to 'ext/bg/js/anki.js')
-rw-r--r-- | ext/bg/js/anki.js | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/ext/bg/js/anki.js b/ext/bg/js/anki.js index 182b4ded..84d81d49 100644 --- a/ext/bg/js/anki.js +++ b/ext/bg/js/anki.js @@ -92,13 +92,26 @@ class AnkiConnect { if (!this._enabled) { return []; } await this._checkVersion(); const actions = notes.map((note) => { - let query = (duplicateScope === 'deck' ? `"deck:${this._escapeQuery(note.deckName)}" ` : ''); + let query = ''; + switch (duplicateScope) { + case 'deck': + query = `"deck:${this._escapeQuery(note.deckName)}" `; + break; + case 'deck-root': + query = `"deck:${this._escapeQuery(this.getRootDeckName(note.deckName))}" `; + break; + } query += this._fieldsToQuery(note.fields); return {action: 'findNotes', params: {query}}; }); return await this._invoke('multi', {actions}); } + getRootDeckName(deckName) { + const index = deckName.indexOf('::'); + return index >= 0 ? deckName.substring(0, index) : deckName; + } + // Private async _checkVersion() { |