From: Abdelrazak Younes Date: Tue, 15 May 2007 17:19:05 +0000 (+0000) Subject: Fix cursor movement inside insets by Dov Feldstern. X-Git-Tag: 1.6.10~9754 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=55a26d72d446be48188b26fa494d5fe2b24437f4;p=lyx.git Fix cursor movement inside insets by Dov Feldstern. * 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 --- diff --git a/src/Bidi.cpp b/src/Bidi.cpp index f90e007be1..8c3a81b208 100644 --- a/src/Bidi.cpp +++ b/src/Bidi.cpp @@ -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 diff --git a/src/Bidi.h b/src/Bidi.h index a2b49b1fc1..5c722a9b90 100644 --- a/src/Bidi.h +++ b/src/Bidi.h @@ -13,6 +13,7 @@ #define BIDI_H #include "support/types.h" +#include "Cursor.h" #include @@ -65,6 +66,8 @@ private: pos_type end_; }; +/// Should interpretation of the arrow keys be reversed? +bool reverseDirectionNeeded(Cursor const & cur); } // namespace lyx diff --git a/src/Cursor.cpp b/src/Cursor.cpp index fd6bb6e7d8..7f2213179e 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -1339,10 +1339,4 @@ void Cursor::fixIfBroken() } -bool Cursor::isRTL() const -{ - return innerParagraph().isRightToLeftPar(bv().buffer()->params()); -} - - } // namespace lyx diff --git a/src/Cursor.h b/src/Cursor.h index 9c98fa3d2c..87c701c51d 100644 --- a/src/Cursor.h +++ b/src/Cursor.h @@ -307,8 +307,6 @@ public: Encoding const * getEncoding() const; /// font at cursor position Font getFont() const; - /// - bool isRTL() const; }; diff --git a/src/Text3.cpp b/src/Text3.cpp index e53afea82d..37baf50626 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -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: diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index 8c835a0f7f..43e4f461f2 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -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: