diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-11-26 22:53:58 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-26 22:53:58 -0500 |
commit | 8449322e1c7b083e1096b8168abf162730880f89 (patch) | |
tree | 9b7a92dc3a98dfdd8e2a533198521b6a161889a4 /ext/mixed/js | |
parent | 3f7c76dbc787e443c6afb13f1a44520885159c1b (diff) |
Fix kanji note creation (#1069)
* Fix kanji note creation
* Move try/catch for consistency
* Move audio normalization
Diffstat (limited to 'ext/mixed/js')
-rw-r--r-- | ext/mixed/js/api.js | 4 | ||||
-rw-r--r-- | ext/mixed/js/display.js | 21 |
2 files changed, 15 insertions, 10 deletions
diff --git a/ext/mixed/js/api.js b/ext/mixed/js/api.js index 947f1cd8..c840adca 100644 --- a/ext/mixed/js/api.js +++ b/ext/mixed/js/api.js @@ -81,8 +81,8 @@ const api = (() => { return this._invoke('getAnkiNoteInfo', {notes, duplicateScope}); } - injectAnkiNoteMedia(expression, reading, timestamp, audioDetails, screenshotDetails, clipboardDetails) { - return this._invoke('injectAnkiNoteMedia', {expression, reading, timestamp, audioDetails, screenshotDetails, clipboardDetails}); + injectAnkiNoteMedia(timestamp, definitionDetails, audioDetails, screenshotDetails, clipboardDetails) { + return this._invoke('injectAnkiNoteMedia', {timestamp, definitionDetails, audioDetails, screenshotDetails, clipboardDetails}); } noteView(noteId) { diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 085a3237..f3aead44 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -1471,7 +1471,7 @@ class Display extends EventDispatcher { const timestamp = Date.now(); const ownerFrameId = this._ownerFrameId; const {fields} = modeOptions; - const {expression, reading} = this._getDefinitionPrimaryExpressionAndReading(definition); + const definitionDetails = this._getDefinitionDetailsForNote(definition); const audioDetails = (mode !== 'kanji' && this._ankiNoteBuilder.containsMarker(fields, 'audio') ? {sources, customSourceUrl} : null); const screenshotDetails = (this._ankiNoteBuilder.containsMarker(fields, 'screenshot') ? {ownerFrameId, format, quality} : null); const clipboardDetails = { @@ -1479,9 +1479,8 @@ class Display extends EventDispatcher { text: this._ankiNoteBuilder.containsMarker(fields, 'clipboard-text') }; const {screenshotFileName, clipboardImageFileName, clipboardText, audioFileName} = await api.injectAnkiNoteMedia( - expression, - reading, timestamp, + definitionDetails, audioDetails, screenshotDetails, clipboardDetails @@ -1507,11 +1506,13 @@ class Display extends EventDispatcher { }); } - async _getAudioInfo(source, expression, reading, details) { - return await api.getDefinitionAudioInfo(source, expression, reading, details); - } + _getDefinitionDetailsForNote(definition) { + const {type} = definition; + if (type === 'kanji') { + const {character} = definition; + return {type, character}; + } - _getDefinitionPrimaryExpressionAndReading(definition) { const termDetailsList = definition.expressions; let bestIndex = -1; for (let i = 0, ii = termDetailsList.length; i < ii; ++i) { @@ -1524,7 +1525,11 @@ class Display extends EventDispatcher { } } const {expression, reading} = termDetailsList[Math.max(0, bestIndex)]; - return {expression, reading}; + return {type, expression, reading}; + } + + async _getAudioInfo(source, expression, reading, details) { + return await api.getDefinitionAudioInfo(source, expression, reading, details); } _areSame(set, array) { |