#include "Bidi.h"
#include "Buffer.h"
+#include "BufferView.h"
#include "Font.h"
#include "Row.h"
#include "LyXRC.h"
}
+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
//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);
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);
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);
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);
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: