]> git.lyx.org Git - lyx.git/commitdiff
Fix cursor movement inside insets by Dov Feldstern.
authorAbdelrazak Younes <younes@lyx.org>
Tue, 15 May 2007 17:19:05 +0000 (17:19 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Tue, 15 May 2007 17:19:05 +0000 (17:19 +0000)
* Bidi.[h,cpp]: new helper function reverseDirectionNeeded()

* Cursor::isRTL(): delete unused method

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

src/Bidi.cpp
src/Bidi.h
src/Cursor.cpp
src/Cursor.h
src/Text3.cpp
src/mathed/InsetMathNest.cpp

index f90e007be16458c99ecf3a2acda875aa105c1648..8c3a81b208aae612dc72bc2355dffb76824d1f0d 100644 (file)
@@ -12,6 +12,7 @@
 
 #include "Bidi.h"
 #include "Buffer.h"
+#include "BufferView.h"
 #include "Font.h"
 #include "Row.h"
 #include "LyXRC.h"
@@ -209,4 +210,18 @@ bool Bidi::isBoundary(Buffer const & buf, Paragraph const & par,
 }
 
 
+bool reverseDirectionNeeded(Cursor const & cur) 
+{
+       /*
+        * We determine the directions based on the direction of the
+        * bottom() --- i.e., outermost --- paragraph, because that is
+        * the only way to achieve consistency of the arrow's movements
+        * within a paragraph, and thus avoid situations in which the
+        * cursor gets stuck.
+        */
+       return cur.bottom().paragraph().isRightToLeftPar(
+                       cur.bv().buffer()->params());
+}
+
+
 } // namespace lyx
index a2b49b1fc11e0b1b8922222170e7d026651db748..5c722a9b901bea8e4cb9cbe1becb8ff9fc03d226 100644 (file)
@@ -13,6 +13,7 @@
 #define BIDI_H
 
 #include "support/types.h"
+#include "Cursor.h"
 #include <vector>
 
 
@@ -65,6 +66,8 @@ private:
        pos_type end_;
 };
 
+/// Should interpretation of the arrow keys be reversed?
+bool reverseDirectionNeeded(Cursor const & cur);
 
 } // namespace lyx
 
index fd6bb6e7d8512e6a6dfb46993af2f5660a069e77..7f2213179e75ce49c5d8ee4db928502ff0ee4cce 100644 (file)
@@ -1339,10 +1339,4 @@ void Cursor::fixIfBroken()
 }
 
 
-bool Cursor::isRTL() const
-{
-       return innerParagraph().isRightToLeftPar(bv().buffer()->params());
-}
-
-
 } // namespace lyx
index 9c98fa3d2c6cb2ccd7563607cf8aaaf9c80e154a..87c701c51d22abb16c5543addc70ad4a51aa5872 100644 (file)
@@ -307,8 +307,6 @@ public:
        Encoding const * getEncoding() const;
        /// font at cursor position
        Font getFont() const;
-       ///
-       bool isRTL() const;
 };
 
 
index e53afea82d8b1da713034643691d9b583762738c..37baf50626985622d87755d5b9a688c45a4c0505 100644 (file)
@@ -433,7 +433,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                //lyxerr << BOOST_CURRENT_FUNCTION
                //       << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
                needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
-               if (isRTL(*cur.bv().buffer(), cur.paragraph()))
+               if (reverseDirectionNeeded(cur))
                        needsUpdate |= cursorLeft(cur);
                else
                        needsUpdate |= cursorRight(cur);
@@ -451,7 +451,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_CHAR_BACKWARD_SELECT:
                //lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
                needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
-               if (isRTL(*cur.bv().buffer(), cur.paragraph()))
+               if (reverseDirectionNeeded(cur))
                        needsUpdate |= cursorRight(cur);
                else
                        needsUpdate |= cursorLeft(cur);
@@ -557,7 +557,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_WORD_FORWARD:
        case LFUN_WORD_FORWARD_SELECT:
                needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
-               if (isRTL(*cur.bv().buffer(), cur.paragraph()))
+               if (reverseDirectionNeeded(cur))
                        needsUpdate |= cursorLeftOneWord(cur);
                else
                        needsUpdate |= cursorRightOneWord(cur);
@@ -568,7 +568,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_WORD_BACKWARD:
        case LFUN_WORD_BACKWARD_SELECT:
                needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
-               if (isRTL(*cur.bv().buffer(), cur.paragraph()))
+               if (reverseDirectionNeeded(cur))
                        needsUpdate |= cursorRightOneWord(cur);
                else
                        needsUpdate |= cursorLeftOneWord(cur);
@@ -1434,11 +1434,14 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_FINISHED_LEFT:
                LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
+               if (reverseDirectionNeeded(cur))
+                       ++cur.pos();
                break;
 
        case LFUN_FINISHED_RIGHT:
                LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
-               ++cur.pos();
+               if (!reverseDirectionNeeded(cur))
+                       ++cur.pos();
                break;
 
        case LFUN_FINISHED_UP:
index 8c835a0f7f06d25f8754b62944888a191e0b1f12..43e4f461f2291255b5fe916f679172d7f1fbe31d 100644 (file)
@@ -492,7 +492,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
                cur.autocorrect() = false;
                cur.clearTargetX();
                cur.macroModeClose();
-               if (cur.isRTL() )
+               if (reverseDirectionNeeded(cur))
                        goto goto_char_backwards;
 
 goto_char_forwards:
@@ -515,7 +515,7 @@ goto_char_forwards:
                cur.autocorrect() = false;
                cur.clearTargetX();
                cur.macroModeClose();
-               if (cur.isRTL())
+               if (reverseDirectionNeeded(cur))
                        goto goto_char_forwards;
 
 goto_char_backwards: