/// <summary> /// Returns the TextRange covering a misspelled word at a specified /// position. /// </summary> /// <param name="position"> /// Position of text to query. /// </param> /// <remarks> /// The position and its LogicalDirection specify a character to query. /// If the specificed character is not part of a misspelled word then /// this method will return null. /// </remarks> public TextRange GetSpellingErrorRange(TextPointer position) { ValidationHelper.VerifyPosition(this.TextContainer, position); SpellingError spellingError = this.TextEditor.GetSpellingErrorAtPosition(position, position.LogicalDirection); return((spellingError == null) ? null : new TextRange(spellingError.Start, spellingError.End)); }
/// <summary>Returns a <see cref="T:System.Windows.Documents.TextRange" /> object covering any misspelled word at a specified position in the contents of the <see cref="T:System.Windows.Controls.RichTextBox" />.</summary> /// <param name="position">A <see cref="T:System.Windows.Documents.TextPointer" /> that specifies a position and logical direction that resolves to a character to examine for a spelling error. Use the <see cref="P:System.Windows.Documents.TextPointer.LogicalDirection" /> property of this <see cref="T:System.Windows.Documents.TextPointer" /> to specify the direction of the character to examine.</param> /// <returns>A <see cref="T:System.Windows.Documents.TextRange" /> object covering any misspelled word that includes the character specified by <paramref name="position" />, or <see langword="null" /> if no spelling error exists at the specified character.</returns> // Token: 0x060054BB RID: 21691 RVA: 0x0017740C File Offset: 0x0017560C public TextRange GetSpellingErrorRange(TextPointer position) { ValidationHelper.VerifyPosition(base.TextContainer, position); SpellingError spellingErrorAtPosition = base.TextEditor.GetSpellingErrorAtPosition(position, position.LogicalDirection); if (spellingErrorAtPosition != null) { return(new TextRange(spellingErrorAtPosition.Start, spellingErrorAtPosition.End)); } return(null); }
public void UpdateSuggestions() { int caretPos = inputUser.CaretIndex; listBox.Items.Clear(); if (!String.IsNullOrEmpty(inputUser.Text)) { error = inputUser.GetSpellingError(0); if (error != null) { var corrections = from sug in error.Suggestions orderby LevenshteinDistance.Compute(inputUser.Text, sug) select sug; int loc = 0; var limited_corrections = corrections.TakeWhile(str => { if (loc >= 4) return false; loc++; return true; }); foreach (string suggession in limited_corrections) { listBox.Items.Add(suggession); } } } }
internal IList GetSuggestionsForError(SpellingError error) { ITextPointer contextStart; ITextPointer contextEnd; ITextPointer contentStart; ITextPointer contentEnd; TextMap textMap; ArrayList suggestions; suggestions = new ArrayList(1); // // IMPORTANT!! // // This logic here must match ScanRange, or else we might not // calculate the exact same error. Keep the two methods in [....]! // XmlLanguage language; CultureInfo culture = GetCurrentCultureAndLanguage(error.Start, out language); if (culture == null || !CanSpellCheck(culture)) { // Return an empty list. } else { ExpandToWordBreakAndContext(error.Start, LogicalDirection.Backward, language, out contentStart, out contextStart); ExpandToWordBreakAndContext(error.End, LogicalDirection.Forward, language, out contentEnd, out contextEnd); textMap = new TextMap(contextStart, contextEnd, contentStart, contentEnd); SetCulture(culture); _spellerInterop.SetContextOption("IsSpellChecking", true); _spellerInterop.SetContextOption("IsSpellVerifyOnly", false); _spellerInterop.EnumTextSegments(textMap.Text, textMap.TextLength, null, new SpellerInterop.EnumTextSegmentsCallback(ScanErrorTextSegment), new TextMapCallbackData(textMap, suggestions)); } return suggestions; }
// Returns an object holding state about an error at the specified // position, or null if no error is present. // // If forceEvaluation is set true, the speller will analyze any dirty region // covered by the position. Otherwise dirty regions will be treated as // non-errors. internal SpellingError GetError(ITextPointer position, LogicalDirection direction, bool forceEvaluation) { ITextPointer start; ITextPointer end; SpellingError error; // Evaluate any pending dirty region. if (forceEvaluation && EnsureInitialized() && _statusTable.IsRunType(position.CreateStaticPointer(), direction, SpellerStatusTable.RunType.Dirty)) { ScanPosition(position, direction); } // Get the error result. if (_statusTable != null && _statusTable.GetError(position.CreateStaticPointer(), direction, out start, out end)) { error = new SpellingError(this, start, end); } else { error = null; } return error; }
// Returns true when one or both ends of the error lies at the inner edge of non-mergeable inline // such as Hyperlink. In this case, a TextRange will normalize its ends outside // the scope of the inline, and the corrected text will not be covered by it. // // We work around the common case, when the error is contained within a single // Run. In more complex cases we'll fail and fall back to using a TextRange. private static bool IsErrorAtNonMergeableInlineEdge(SpellingError spellingError, out ITextPointer textStart, out ITextPointer textEnd) { bool result = false; textStart = spellingError.Start.CreatePointer(LogicalDirection.Backward); while (textStart.CompareTo(spellingError.End) < 0 && textStart.GetPointerContext(LogicalDirection.Forward) != TextPointerContext.Text) { textStart.MoveToNextContextPosition(LogicalDirection.Forward); } textEnd = spellingError.End.CreatePointer(); while (textEnd.CompareTo(spellingError.Start) > 0 && textEnd.GetPointerContext(LogicalDirection.Backward) != TextPointerContext.Text) { textEnd.MoveToNextContextPosition(LogicalDirection.Backward); } if (textStart.GetPointerContext(LogicalDirection.Forward) != TextPointerContext.Text || textStart.CompareTo(spellingError.End) == 0) { return false; } Invariant.Assert(textEnd.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.Text && textEnd.CompareTo(spellingError.Start) != 0); if (TextPointerBase.IsAtNonMergeableInlineStart(textStart) || TextPointerBase.IsAtNonMergeableInlineEnd(textEnd)) { if (typeof(Run).IsAssignableFrom(textStart.ParentType) && textStart.HasEqualScope(textEnd)) { result = true; } } return result; }