internal bool NoveltyFunction(IPredictionSuggestion suggestion) { var fiddleFactor = AppSettings.Instance.Prediction.PredictionNovelty == PredictionNovelty.FromFirstLetter ? 0 : 1; var matchIndex = 0; var matchLim = Math.Min(suggestion.ReplacementLength + fiddleFactor - 1, offeredList.Count); while (matchIndex < matchLim && offeredList[matchIndex] != suggestion.Text) { matchIndex++; } return(matchIndex == matchLim); }
void InsertSuggestion(IPredictionSuggestion suggestion, string insert) { if ((_isAutoSpaceNeeded) && (suggestion.CompleteWord)) { _isAutoSpaceNeeded = false; insert = " " + insert; } _isAutoSpaceAdded = false; Debug.Assert(!_isAutoSpaceNeeded); Debug.Assert(!_isAutoSpaceAdded); if (!suggestion.CompleteWord) { insert = insert.Substring(0, insert.Length - 1); } switch (Settings.Prediction.PredictionSpacingBehavior) { case PredictionSpacingBehavior.Always: insert += " "; break; case PredictionSpacingBehavior.Never: break; case PredictionSpacingBehavior.AddAndRemoveIfUnwanted: insert += " "; _isAutoSpaceAdded = true; break; case PredictionSpacingBehavior.AddIfNeeded: default: Debug.Assert(Settings.Prediction.PredictionSpacingBehavior == PredictionSpacingBehavior.AddIfNeeded); _isAutoSpaceNeeded = suggestion.CompleteWord; break; } var originalText = TextSlice.Text; var replacementText = originalText.Substring(0, suggestion.ReplacementStart) + insert + originalText.Substring(suggestion.ReplacementStart + suggestion.ReplacementLength); var slice = new TextSlice(replacementText, suggestion.ReplacementStart + insert.Length); if (slice != TextSlice) { // Normally selecting a prediction will change the text. _editor.TextSlice = slice; TextSlice = slice; } else { // Sometimes the prediction is just what we typed, but we still want to fire off the prediction engine // which usually runs as a side-effect of the text changing. (This is probably the same as detecting that // _isAutoSpaceNeeded changed as a side-effect of this method.) SetTextHint(slice); } // Release the Shift key if it had been pressed. ShiftToggleState.IsChecked = false; _ambiguousKeys.Clear(); if (!suggestion.CompleteWord) { var entry = new List <string>(); entry.Add(insert); _ambiguousKeys.Add(entry); } RaiseNarrationEvent(insert, NarrationEventType.AcceptSuggestion, insert); }