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-note-builder.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-note-builder.js')
-rw-r--r-- | ext/bg/js/anki-note-builder.js | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/ext/bg/js/anki-note-builder.js b/ext/bg/js/anki-note-builder.js index f04a6bf7..aa76ecd9 100644 --- a/ext/bg/js/anki-note-builder.js +++ b/ext/bg/js/anki-note-builder.js @@ -44,6 +44,14 @@ class AnkiNoteBuilder { await this._injectMedia(anki, definition, fields, mode, audioDetails, screenshotDetails, clipboardDetails); } + let duplicateScopeDeckName = null; + let duplicateScopeCheckChildren = false; + if (duplicateScope === 'deck-root') { + duplicateScope = 'deck'; + duplicateScopeDeckName = this.getRootDeckName(deck); + duplicateScopeCheckChildren = true; + } + const fieldEntries = Object.entries(fields); const noteFields = {}; const note = { @@ -51,7 +59,13 @@ class AnkiNoteBuilder { tags, deckName: deck, modelName: model, - options: {duplicateScope} + options: { + duplicateScope, + duplicateScopeOptions: { + deckName: duplicateScopeDeckName, + checkChildren: duplicateScopeCheckChildren + } + } }; const data = this._createNoteData(definition, mode, context, resultOutputMode, compactGlossaries); @@ -81,6 +95,11 @@ class AnkiNoteBuilder { return false; } + getRootDeckName(deckName) { + const index = deckName.indexOf('::'); + return index >= 0 ? deckName.substring(0, index) : deckName; + } + // Private _createNoteData(definition, mode, context, resultOutputMode, compactGlossaries) { |