mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-07 08:07:43 +00:00
Allow for the partial specification of punctuation, with more robust defaults selector thing.
This commit is contained in:
parent
5e2528a78c
commit
b20541ea8b
2 changed files with 25 additions and 7 deletions
|
|
@ -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: "”"
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue