The last changes regarding isWordSeparator and hard hyphens have a drawback...
Now the single dash enclosed by white space is treated as a single word and the
spell check marks it red - I'd rate this as a regression.

The attached patch should fix that. Ok to apply?

Stephan

Index: src/Paragraph.h
===================================================================
--- src/Paragraph.h     (Revision 38273)
+++ src/Paragraph.h     (Arbeitskopie)
@@ -420,6 +420,8 @@
        bool isChar(pos_type pos) const;
        /// True if the element at this point is a space
        bool isSpace(pos_type pos) const;
+       /// True if the element at this point is a hard hyphen
+       bool isHardHyphen(pos_type pos) const;
 
        /// returns true if at least one line break or line separator has been 
deleted
        /// at the beginning of the paragraph (either physically or logically)
Index: src/Paragraph.cpp
===================================================================
--- src/Paragraph.cpp   (Revision 38273)
+++ src/Paragraph.cpp   (Arbeitskopie)
@@ -2851,21 +2851,37 @@
                return !inset->isLetter();
        if (pos == size())
                return true;
-       char_type const c = d->text_[pos];
        // if we have a hard hyphen (no en- or emdash),
        // we pass this to the spell checker
-       if (c == '-') {
-               int j = pos + 1;
-               if ((j == size() || d->text_[j] != '-')
-                   && (pos == 0 || d->text_[pos - 1] != '-'))
-                       return false;
-       }
+       if (isHardHyphen(pos))
+               return false;
+       char_type const c = d->text_[pos];
        // We want to pass the ' and escape chars to the spellchecker
        static docstring const quote = from_utf8(lyxrc.spellchecker_esc_chars + 
'\'');
        return (!isLetterChar(c) && !isDigitASCII(c) && !contains(quote, c));
 }
 
 
+bool Paragraph::isHardHyphen(pos_type pos) const
+{
+       pos_type const psize = size();
+       if (pos < psize) {
+               char_type const c = d->text_[pos];
+               if (c == '-') {
+                       int j = pos + 1;
+                       int k = pos > 0 ? pos - 1 : 0;
+                       if ((pos == 0 || isSpace(k))
+                               && (j == psize || isSpace(j)))
+                               return false;
+                       if ((j == psize || d->text_[j] != '-')
+                               && (pos == 0 || d->text_[k] != '-'))
+                               return true;
+               }
+       }
+       return false;
+}
+
+
 bool Paragraph::isSameSpellRange(pos_type pos1, pos_type pos2) const
 {
        return pos1 == pos2

Reply via email to