]> git.lyx.org Git - lyx.git/blobdiff - src/Text.cpp
Typo.
[lyx.git] / src / Text.cpp
index 033cbe8aa9044219c0d1bc0f7cdf4ae7dde4b431..1bde616c3183a1d2bacaec2a2fb8c7541e3acc5b 100644 (file)
@@ -589,19 +589,38 @@ bool Text::cursorForwardOneWord(Cursor & cur)
        pos_type pos = cur.pos();
        Paragraph const & par = cur.paragraph();
 
-       // Skip over either a non-char inset or a full word
-       if (pos != lastpos && !par.isLetter(pos) && !par.isChar(pos))
-               ++pos;
-       else while (pos != lastpos && par.isLetter(pos))
-                       ++pos;
+       // Paragraph boundary is a word boundary
+       if (pos == lastpos) {
+               if (pit != cur.lastpit())
+                       return setCursor(cur, pit + 1, 0);
+               else
+                       return false;
+       }
 
-       // Skip through trailing punctuation and spaces.
-       while (pos != lastpos && par.isChar(pos))
-               ++pos;
+       if (lyxrc.mac_like_word_movement) {
+               // Skip through trailing punctuation and spaces.
+               while (pos != lastpos && par.isChar(pos))
+                        ++pos;
 
-       if (pos == lastpos && pit != cur.lastpit()) {
-               ++pit;
-               pos = 0;
+               // Skip over either a non-char inset or a full word
+               if (pos != lastpos && !par.isLetter(pos))
+                       ++pos;
+               else while (pos != lastpos && par.isLetter(pos))
+                            ++pos;
+       } else {
+               LASSERT(pos < lastpos, /**/); // see above
+               if (par.isLetter(pos))
+                       while (pos != lastpos && par.isLetter(pos))
+                               ++pos;
+               else if (par.isChar(pos))
+                       while (pos != lastpos && par.isChar(pos))
+                               ++pos;
+               else if (!par.isSpace(pos)) // non-char inset
+                       ++pos;
+
+               // Skip over white space
+               while (pos != lastpos && par.isSpace(pos))
+                            ++pos;             
        }
 
        return setCursor(cur, pit, pos);
@@ -616,19 +635,33 @@ bool Text::cursorBackwardOneWord(Cursor & cur)
        pos_type pos = cur.pos();
        Paragraph & par = cur.paragraph();
 
-       // Skip through puctuation and spaces.
-       while (pos != 0 && par.isChar(pos - 1))
-               --pos;
+       // Paragraph boundary is a word boundary
+       if (pos == 0 && pit != 0)
+               return setCursor(cur, pit - 1, getPar(pit - 1).size());
 
-       // Skip over either a non-char inset or a full word
-       if (pos != 0 && !par.isLetter(pos - 1) && !par.isChar(pos - 1))
-               --pos;
-       else while (pos != 0 && par.isLetter(pos - 1))
+       if (lyxrc.mac_like_word_movement) {
+               // Skip through puctuation and spaces.
+               while (pos != 0 && par.isChar(pos - 1))
                        --pos;
 
-       if (pos == 0 && pit != 0) {
-               --pit;
-               pos = getPar(cur.pit() - 1).size();
+               // Skip over either a non-char inset or a full word
+               if (pos != 0 && !par.isLetter(pos - 1) && !par.isChar(pos - 1))
+                       --pos;
+               else while (pos != 0 && par.isLetter(pos - 1))
+                            --pos;
+       } else {
+               // Skip over white space
+               while (pos != 0 && par.isSpace(pos - 1))
+                            --pos;
+
+               if (pos != 0 && par.isLetter(pos - 1))
+                       while (pos != 0 && par.isLetter(pos - 1))
+                               --pos;
+               else if (pos != 0 && par.isChar(pos - 1))
+                       while (pos != 0 && par.isChar(pos - 1))
+                               --pos;
+               else if (pos != 0 && !par.isSpace(pos - 1)) // non-char inset
+                       --pos;
        }
 
        return setCursor(cur, pit, pos);