Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed words with ".".

  • Loading branch information...
commit 4cc11b0835893fc50b71d510878bdfbbb37bbd89 1 parent cb178d7
Noah Richards authored
View
3  .gitignore
@@ -4,3 +4,6 @@ obj*/
*.suo
*.user
*~
+TestResults/
+*.testsettings
+*.vsmdi
View
21 SpellChecker.Implementation/Spelling/SpellingTagger.cs
@@ -381,6 +381,9 @@ IEnumerable<MisspellingTag> GetMisspellingsInSpans(NormalizedSnapshotSpanCollect
{
string textToParse = span.Snapshot.GetText(span.Start + word.Start, word.Length);
+ if (!ProbablyARealWord(textToParse))
+ continue;
+
// Now pass these off to WPF.
textBox.Text = textToParse;
@@ -430,6 +433,11 @@ static internal bool ProbablyARealWord(string word)
if (word.Any(c => c == '_' || char.IsDigit(c)))
return false;
+ // Check for a . in the middle of the word
+ int firstDot = word.IndexOf('.');
+ if (firstDot >= 0 && firstDot < word.Length - 1 && word.Skip(firstDot + 1).Any(c => !IsWordBreakCharacter(c)))
+ return false;
+
// CamelCase/UPPER
char firstLetter = word.FirstOrDefault(c => char.IsLetter(c));
if (firstLetter != 0)
@@ -447,16 +455,16 @@ static internal IEnumerable<Microsoft.VisualStudio.Text.Span> GetWordsInText(str
if (string.IsNullOrWhiteSpace(text))
yield break;
- // We need to break this up for WPF, because it is *incredibly* slow at checking the spelling
+ // We need to break this up for WPF, because it is *incredibly* slow at checking the spelling
for (int i = 0; i < text.Length; i++)
{
- if (char.IsWhiteSpace(text[i]))
+ if (IsWordBreakCharacter(text[i]))
continue;
int end = i;
for (; end < text.Length; end++)
{
- if (char.IsWhiteSpace(text[end]))
+ if (IsWordBreakCharacter(text[end]))
break;
}
@@ -465,6 +473,13 @@ static internal IEnumerable<Microsoft.VisualStudio.Text.Span> GetWordsInText(str
}
}
+ // Word break characters. Specifically, exclude _.'
+ const string wordBreakChars = ",/<>?;:\"[]\\{}|-=+~!@#$%^&*() \t";
+ static bool IsWordBreakCharacter(char c)
+ {
+ return wordBreakChars.Contains(c) || char.IsWhiteSpace(c);
+ }
+
void OnForegroundThread(Action action, DispatcherPriority priority = DispatcherPriority.ApplicationIdle)
{
_dispatcher.Invoke(action, priority);
View
12 Test/WordLogicTests.cs
@@ -23,7 +23,7 @@ void CheckWords(string sentence, List<string> expected)
public void GetWordsTest()
{
CheckWords("This! Is an amazing1 sentence, I think; but_some of ThEse words Should be ignore.d I think.",
- new List<string>() { "This!", "Is", "an", "amazing1", "sentence,", "I", "think;", "but_some", "of", "ThEse", "words", "Should", "be", "ignore.d", "I", "think." });
+ new List<string>() { "This", "Is", "an", "amazing1", "sentence", "I", "think", "but_some", "of", "ThEse", "words", "Should", "be", "ignore.d", "I", "think." });
}
[TestMethod]
@@ -70,6 +70,16 @@ public void SkipAllUppercaseWords()
AWord(word);
}
+ [TestMethod]
+ public void SkipWordsWithDotInTheMiddle()
+ {
+ foreach (string word in Words("foo.exe", "wordlogictests.cs", "include.h"))
+ NotAWord(word);
+
+ foreach (string word in Words("this."))
+ AWord(word);
+ }
+
#region Helpers
void NotAWord(string word)
{
Please sign in to comment.
Something went wrong with that request. Please try again.