diff --git a/common/predictive-text/unit_tests/headless/worker-custom-punctuation.js b/common/predictive-text/unit_tests/headless/worker-custom-punctuation.js index a1bc0b39bb..3407ace41f 100644 --- a/common/predictive-text/unit_tests/headless/worker-custom-punctuation.js +++ b/common/predictive-text/unit_tests/headless/worker-custom-punctuation.js @@ -39,7 +39,6 @@ describe('Custom Punctuation', function () { quotesForKeepSuggestion: { open: "«", close: "»" }, - insertAfterWord: " " } }); @@ -85,9 +84,6 @@ describe('Custom Punctuation', function () { // U+1680 OGHAM SPACE MARK: // it's technically whitespace, but it don't look it! insertAfterWord: " ", - quotesForKeepSuggestion: { - open: "“", close: "”" - }, } }); diff --git a/common/predictive-text/worker/model-compositor.ts b/common/predictive-text/worker/model-compositor.ts index ea33be1c03..60fb8bca5d 100644 --- a/common/predictive-text/worker/model-compositor.ts +++ b/common/predictive-text/worker/model-compositor.ts @@ -49,7 +49,7 @@ class ModelCompositor { let postContext = models.applyTransform(inputTransform, context); let keepOptionText = this.lexicalModel.wordbreak(postContext); let keepOption: Suggestion = null; - let punctuation = this.determinePunctuationFromModel(); + let punctuation = this.determinePunctuationFromModel(this.lexicalModel); for(let alt of transformDistribution) { let transform = alt.sample; @@ -153,8 +153,30 @@ class ModelCompositor { return suggestions; } - private determinePunctuationFromModel() { - return this.lexicalModel.punctuation || DEFAULT_PUNCTUATION; + /** + * Returns the punctuation used for this model, filling out unspecified fields + */ + private determinePunctuationFromModel(model: WorkerInternalModel): LexicalModelPunctuation { + let defaults = DEFAULT_PUNCTUATION; + + // Use the defaults of the model does not provide any punctuation at all. + if (!model.punctuation) + return defaults; + + let specifiedPunctuation = this.lexicalModel.punctuation; + let insertAfterWord = specifiedPunctuation.insertAfterWord; + if (insertAfterWord !== '' && !insertAfterWord) { + insertAfterWord = defaults.insertAfterWord; + } + + let quotesForKeepSuggestion = specifiedPunctuation.quotesForKeepSuggestion; + if (!quotesForKeepSuggestion) { + quotesForKeepSuggestion = defaults.quotesForKeepSuggestion; + } + + return { + insertAfterWord, quotesForKeepSuggestion + } } }