]> git.lyx.org Git - features.git/commitdiff
Fix bug http://bugzilla.lyx.org/show_bug.cgi?id=3580
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 24 Jun 2008 09:19:52 +0000 (09:19 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 24 Jun 2008 09:19:52 +0000 (09:19 +0000)
* Paragraph.cpp (isChar): new method; returns true when pointer is on
a character that is not a letter. Note that a footnote inset, for
example is neither a letter nor a character.

* Text.cpp (cursorForwardOneWord, cursorBackwardOneWord): rewrite by
using 3 character categories: letters, characters and others.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25373 a592a061-630c-0410-9148-cb99ea01b6c8

src/Paragraph.cpp
src/Paragraph.h
src/Text.cpp

index 6522bbfe72095bb71172cf7c1109e7b5873fac1e..5eb3a67462416adf0b19bc9d5882acd8e5392eed 100644 (file)
@@ -2268,6 +2268,15 @@ bool Paragraph::isLetter(pos_type pos) const
 }
 
 
+bool Paragraph::isChar(pos_type pos) const
+{
+       if (Inset const * inset = getInset(pos))
+               return inset->isChar();
+       char_type const c = d->text_[pos];
+       return !isLetterChar(c) && !isDigit(c);
+}
+
+
 Language const *
 Paragraph::getParLanguage(BufferParams const & bparams) const
 {
index a75ec791116b27e4b0daeb0905d615eb4f58d464..267fc8de60f6a8cec363a0e0cb8f6277b1932724 100644 (file)
@@ -334,6 +334,8 @@ public:
        /// True if the character/inset at this point can be part of a word.
        /// Note that digits in particular are considered as letters
        bool isLetter(pos_type pos) const;
+       /// True if the element at this point is a character that is not a letter.
+       bool isChar(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 19b3ead091d3002eb767e46ce0d462b013064453..c9bb7e3b563c5e0af33fdfab50455511c0b455ab 100644 (file)
@@ -584,20 +584,27 @@ bool Text::cursorForwardOneWord(Cursor & cur)
 {
        LASSERT(this == cur.text(), /**/);
 
-       Cursor old = cur;
+       pos_type const lastpos = cur.lastpos();
+       pit_type pit = cur.pit();
+       pos_type pos = cur.pos();
+       Paragraph const & par = cur.paragraph();
 
-       if (old.pos() == old.lastpos() && old.pit() != old.lastpit()) {
-               ++old.pit();
-               old.pos() = 0;
-       } else {
-               // Advance through word.
-               while (old.pos() != old.lastpos() && old.paragraph().isLetter(old.pos()))
-                       ++old.pos();
-               // Skip through trailing nonword stuff.
-               while (old.pos() != old.lastpos() && !old.paragraph().isLetter(old.pos()))
-                       ++old.pos();
+       // 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;
+
+       // Skip through trailing punctuation and spaces.
+       while (pos != lastpos && par.isChar(pos))
+               ++pos;
+
+       if (pos == lastpos && pit != cur.lastpit()) {
+               ++pit;
+               pos = 0;
        }
-       return setCursor(cur, old.pit(), old.pos());
+
+       return setCursor(cur, pit, pos);
 }
 
 
@@ -605,20 +612,26 @@ bool Text::cursorBackwardOneWord(Cursor & cur)
 {
        LASSERT(this == cur.text(), /**/);
 
-       Cursor old = cur;
+       pit_type pit = cur.pit();
+       pos_type pos = cur.pos();
+       Paragraph & par = cur.paragraph();
 
-       if (old.pos() == 0 && old.pit() != 0) {
-               --old.pit();
-               old.pos() = old.lastpos();
-       } else {
-               // Skip through initial nonword stuff.
-               while (old.pos() != 0 && !old.paragraph().isLetter(old.pos() - 1))
-                       --old.pos();
-               // Advance through word.
-               while (old.pos() != 0 && old.paragraph().isLetter(old.pos() - 1))
-                       --old.pos();
+       // Skip through puctuation and spaces.
+       while (pos != 0 && par.isChar(pos - 1))
+               --pos;
+
+       // Skip over either a non-char inset or a full word
+       if (pos != 0 && !par.isLetter(pos) && !par.isChar(pos - 1))
+               --pos;
+       else while (pos != 0 && par.isLetter(pos - 1))
+                       --pos;
+
+       if (pos == 0 && pit != 0) {
+               --pit;
+               pos = getPar(cur.pit() - 1).size();
        }
-       return setCursor(cur, old.pit(), old.pos());
+
+       return setCursor(cur, pit, pos);
 }