Move some functions out of Bidi.*

The functions reverseDirectionNeeded() and reverseDirectionNeeded() do
not rely on the Bidi class. The first one is changed into a Cursor
method, and the second one is replaced with explicit code.
This commit is contained in:
Jean-Marc Lasgouttes 2015-07-16 11:55:45 +02:00
parent f51d7fdd2a
commit 96692bdbb0
7 changed files with 22 additions and 35 deletions

View File

@ -215,23 +215,4 @@ bool Bidi::isBoundary(Buffer const & buf, Paragraph const & par,
return rtl != rtl2; return rtl != rtl2;
} }
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().isRTL(cur.bv().buffer().params());
}
bool isWithinRtlParagraph(Cursor const & cur)
{
return cur.innerParagraph().isRTL(cur.bv().buffer().params());
}
} // namespace lyx } // namespace lyx

View File

@ -75,12 +75,6 @@ private:
pos_type end_; pos_type end_;
}; };
/// Should interpretation of the arrow keys be reversed?
bool reverseDirectionNeeded(Cursor const & cur);
/// Is current paragraph in RTL mode?
bool isWithinRtlParagraph(Cursor const & cur);
} // namespace lyx } // namespace lyx
#endif // BIDI_H #endif // BIDI_H

View File

@ -1156,6 +1156,19 @@ void Cursor::posVisToRowExtremity(bool left)
} }
bool Cursor::reverseDirectionNeeded() const
{
/*
* 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 bottom().paragraph().isRTL(bv().buffer().params());
}
CursorSlice Cursor::normalAnchor() const CursorSlice Cursor::normalAnchor() const
{ {
if (!selection()) if (!selection())
@ -1843,7 +1856,7 @@ bool Cursor::upDownInMath(bool up)
// handling when the cursor is at the end of line: Use the new // handling when the cursor is at the end of line: Use the new
// x-target only if the old one was before the end of line // x-target only if the old one was before the end of line
// or the old one was after the beginning of the line // or the old one was after the beginning of the line
bool inRTL = isWithinRtlParagraph(*this); bool inRTL = innerParagraph().isRTL(bv().buffer().params());
bool left; bool left;
bool right; bool right;
if (inRTL) { if (inRTL) {
@ -1985,7 +1998,7 @@ bool Cursor::upDownInText(bool up, bool & updateNeeded)
// end of line: Use the new x-target only if the old // end of line: Use the new x-target only if the old
// one was before the end of line or the old one was // one was before the end of line or the old one was
// after the beginning of the line // after the beginning of the line
bool inRTL = isWithinRtlParagraph(*this); bool inRTL = innerParagraph().isRTL(bv().buffer().params());
bool left; bool left;
bool right; bool right;
if (inRTL) { if (inRTL) {

View File

@ -268,6 +268,8 @@ public:
bool posVisToNewRow(bool movingLeft); bool posVisToNewRow(bool movingLeft);
/// move to right or left extremity of the current row /// move to right or left extremity of the current row
void posVisToRowExtremity(bool left); void posVisToRowExtremity(bool left);
/// Should interpretation of the arrow keys be reversed?
bool reverseDirectionNeeded() const;
/// insert an inset /// insert an inset
void insert(Inset *); void insert(Inset *);

View File

@ -22,7 +22,6 @@
#include "Text.h" #include "Text.h"
#include "Bidi.h"
#include "Buffer.h" #include "Buffer.h"
#include "buffer_funcs.h" #include "buffer_funcs.h"
#include "BufferList.h" #include "BufferList.h"

View File

@ -17,7 +17,6 @@
#include "Text.h" #include "Text.h"
#include "Bidi.h"
#include "BranchList.h" #include "BranchList.h"
#include "FloatList.h" #include "FloatList.h"
#include "FuncStatus.h" #include "FuncStatus.h"
@ -710,7 +709,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
cmd = FuncRequest(LFUN_FINISHED_LEFT); cmd = FuncRequest(LFUN_FINISHED_LEFT);
} }
} else { } else {
if (reverseDirectionNeeded(cur)) { if (cur.reverseDirectionNeeded()) {
cmd.setAction(cmd.action() == LFUN_CHAR_LEFT_SELECT ? cmd.setAction(cmd.action() == LFUN_CHAR_LEFT_SELECT ?
LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD); LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD);
} else { } else {
@ -734,7 +733,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
cmd = FuncRequest(LFUN_FINISHED_RIGHT); cmd = FuncRequest(LFUN_FINISHED_RIGHT);
} }
} else { } else {
if (reverseDirectionNeeded(cur)) { if (cur.reverseDirectionNeeded()) {
cmd.setAction(cmd.action() == LFUN_CHAR_RIGHT_SELECT ? cmd.setAction(cmd.action() == LFUN_CHAR_RIGHT_SELECT ?
LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD); LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD);
} else { } else {
@ -846,7 +845,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
cmd = FuncRequest(LFUN_FINISHED_RIGHT); cmd = FuncRequest(LFUN_FINISHED_RIGHT);
} }
} else { } else {
if (reverseDirectionNeeded(cur)) { if (cur.reverseDirectionNeeded()) {
cmd.setAction(cmd.action() == LFUN_WORD_RIGHT_SELECT ? cmd.setAction(cmd.action() == LFUN_WORD_RIGHT_SELECT ?
LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD); LFUN_WORD_BACKWARD_SELECT : LFUN_WORD_BACKWARD);
} else { } else {
@ -898,7 +897,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
cmd = FuncRequest(LFUN_FINISHED_LEFT); cmd = FuncRequest(LFUN_FINISHED_LEFT);
} }
} else { } else {
if (reverseDirectionNeeded(cur)) { if (cur.reverseDirectionNeeded()) {
cmd.setAction(cmd.action() == LFUN_WORD_LEFT_SELECT ? cmd.setAction(cmd.action() == LFUN_WORD_LEFT_SELECT ?
LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD); LFUN_WORD_FORWARD_SELECT : LFUN_WORD_FORWARD);
} else { } else {

View File

@ -38,7 +38,6 @@
#include "MathStream.h" #include "MathStream.h"
#include "MathSupport.h" #include "MathSupport.h"
#include "Bidi.h"
#include "Buffer.h" #include "Buffer.h"
#include "BufferParams.h" #include "BufferParams.h"
#include "BufferView.h" #include "BufferView.h"
@ -670,7 +669,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
else { else {
bool right = (act == LFUN_CHAR_RIGHT_SELECT bool right = (act == LFUN_CHAR_RIGHT_SELECT
|| act == LFUN_CHAR_RIGHT); || act == LFUN_CHAR_RIGHT);
if (lyxrc.visual_cursor || !reverseDirectionNeeded(cur)) if (lyxrc.visual_cursor || !cur.reverseDirectionNeeded())
forward = right; forward = right;
else else
forward = !right; forward = !right;