Bug 633210 - Single hyphens are marked as spelling mistakes; r=smaug a=beltzner
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 10 Feb 2011 12:07:31 -0500
changeset 62304 05e6ab25d30415dd7ab87423053abbb58126dc14
parent 62303 8272387621cf8f562bc4feb97443f757ab4bc98c
child 62305 3eaad34067e4003449252176acfb893b613c5e33
push idunknown
push userunknown
push dateunknown
reviewerssmaug, beltzner
bugs633210
milestone2.0b12pre
Bug 633210 - Single hyphens are marked as spelling mistakes; r=smaug a=beltzner
extensions/spellcheck/src/mozInlineSpellWordUtil.cpp
layout/reftests/editor/reftest.list
layout/reftests/editor/spellcheck-hyphen-multiple-invalid-ref.html
layout/reftests/editor/spellcheck-hyphen-multiple-invalid.html
layout/reftests/editor/spellcheck-hyphen-multiple-valid-ref.html
layout/reftests/editor/spellcheck-hyphen-multiple-valid.html
--- a/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp
+++ b/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp
@@ -910,19 +910,29 @@ WordSplitState::ClassifyCharacter(PRInt3
   }
 
   // all other punctuation
   if (charCategory == nsIUGenCategory::kSeparator ||
       charCategory == nsIUGenCategory::kOther ||
       charCategory == nsIUGenCategory::kPunctuation ||
       charCategory == nsIUGenCategory::kSymbol) {
     // Don't break on hyphens, as hunspell handles them on its own.
-    if (mDOMWordText[aIndex] != '-') {
-      return CHAR_CLASS_SEPARATOR;
+    if (aIndex > 0 &&
+        mDOMWordText[aIndex] == '-' &&
+        mDOMWordText[aIndex - 1] != '-' &&
+        ClassifyCharacter(aIndex - 1, false) == CHAR_CLASS_WORD) {
+      // A hyphen is only meaningful as a separator inside a word
+      // if the previous and next characters are a word character.
+      if (aIndex == PRInt32(mDOMWordText.Length()) - 1)
+        return CHAR_CLASS_SEPARATOR;
+      if (mDOMWordText[aIndex + 1] != '.' &&
+          ClassifyCharacter(aIndex + 1, false) == CHAR_CLASS_WORD)
+        return CHAR_CLASS_WORD;
     }
+    return CHAR_CLASS_SEPARATOR;
   }
 
   // any other character counts as a word
   return CHAR_CLASS_WORD;
 }
 
 
 // WordSplitState::Advance
--- a/layout/reftests/editor/reftest.list
+++ b/layout/reftests/editor/reftest.list
@@ -48,9 +48,11 @@ needs-focus == caret_after_reframe.html 
 == nobogusnode-1.html nobogusnode-ref.html
 == nobogusnode-2.html nobogusnode-ref.html
 == spellcheck-hyphen-valid.html spellcheck-hyphen-valid-ref.html
 != spellcheck-hyphen-invalid.html spellcheck-hyphen-invalid-ref.html
 == spellcheck-slash-valid.html spellcheck-slash-valid-ref.html
 == spellcheck-period-valid.html spellcheck-period-valid-ref.html
 == spellcheck-space-valid.html spellcheck-space-valid-ref.html
 == spellcheck-comma-valid.html spellcheck-comma-valid-ref.html
+== spellcheck-hyphen-multiple-valid.html spellcheck-hyphen-multiple-valid-ref.html
+!= spellcheck-hyphen-multiple-invalid.html spellcheck-hyphen-multiple-invalid-ref.html
 == unneeded_scroll.html unneeded_scroll-ref.html
new file mode 100644
--- /dev/null
+++ b/layout/reftests/editor/spellcheck-hyphen-multiple-invalid-ref.html
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<html>
+  <body>
+    <textarea style="width: 400px; height: 200px;" autofocus spellcheck="false">-hlloe hlloe- --hlloe --hlloe ---hlloe hlloe--- ---hlloe----</textarea>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/editor/spellcheck-hyphen-multiple-invalid.html
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<html>
+  <body>
+    <textarea style="width: 400px; height: 200px;" autofocus>-hlloe hlloe- --hlloe --hlloe ---hlloe hlloe--- ---hlloe----</textarea>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/editor/spellcheck-hyphen-multiple-valid-ref.html
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<html>
+  <body>
+    <textarea style="width: 400px; height: 200px;" autofocus spellcheck="false">- -- --- -hello hello- --hello --hello ---hello hello--- ---hello----</textarea>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/editor/spellcheck-hyphen-multiple-valid.html
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<html>
+  <body>
+    <textarea style="width: 400px; height: 200px;" autofocus>- -- --- -hello hello- --hello --hello ---hello hello--- ---hello----</textarea>
+  </body>
+</html>