mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-10 20:04:46 +00:00
visual mode for bidi cursor movement --- in math
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22930 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
11a6b3c4c7
commit
8f47f5d396
@ -1027,6 +1027,8 @@ void InsetMathHull::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|||||||
|
|
||||||
case LFUN_FINISHED_BACKWARD:
|
case LFUN_FINISHED_BACKWARD:
|
||||||
case LFUN_FINISHED_FORWARD:
|
case LFUN_FINISHED_FORWARD:
|
||||||
|
case LFUN_FINISHED_RIGHT:
|
||||||
|
case LFUN_FINISHED_LEFT:
|
||||||
//lyxerr << "action: " << cmd.action << endl;
|
//lyxerr << "action: " << cmd.action << endl;
|
||||||
InsetMathGrid::doDispatch(cur, cmd);
|
InsetMathGrid::doDispatch(cur, cmd);
|
||||||
notifyCursorLeaves(cur);
|
notifyCursorLeaves(cur);
|
||||||
@ -1166,6 +1168,8 @@ bool InsetMathHull::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|||||||
switch (cmd.action) {
|
switch (cmd.action) {
|
||||||
case LFUN_FINISHED_BACKWARD:
|
case LFUN_FINISHED_BACKWARD:
|
||||||
case LFUN_FINISHED_FORWARD:
|
case LFUN_FINISHED_FORWARD:
|
||||||
|
case LFUN_FINISHED_RIGHT:
|
||||||
|
case LFUN_FINISHED_LEFT:
|
||||||
case LFUN_UP:
|
case LFUN_UP:
|
||||||
case LFUN_DOWN:
|
case LFUN_DOWN:
|
||||||
case LFUN_NEW_LINE:
|
case LFUN_NEW_LINE:
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
#include "FuncRequest.h"
|
#include "FuncRequest.h"
|
||||||
#include "FuncStatus.h"
|
#include "FuncStatus.h"
|
||||||
#include "LyXFunc.h"
|
#include "LyXFunc.h"
|
||||||
|
#include "LyXRC.h"
|
||||||
#include "support/gettext.h"
|
#include "support/gettext.h"
|
||||||
#include "Text.h"
|
#include "Text.h"
|
||||||
#include "OutputParams.h"
|
#include "OutputParams.h"
|
||||||
@ -490,77 +491,79 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|||||||
lfunMouseRelease(cur, cmd);
|
lfunMouseRelease(cur, cmd);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case LFUN_FINISHED_LEFT: // in math, left is backwards
|
||||||
case LFUN_FINISHED_BACKWARD:
|
case LFUN_FINISHED_BACKWARD:
|
||||||
cur.bv().cursor() = cur;
|
cur.bv().cursor() = cur;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case LFUN_FINISHED_RIGHT: // in math, right is forward
|
||||||
case LFUN_FINISHED_FORWARD:
|
case LFUN_FINISHED_FORWARD:
|
||||||
++cur.pos();
|
++cur.pos();
|
||||||
cur.bv().cursor() = cur;
|
cur.bv().cursor() = cur;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case LFUN_CHAR_RIGHT:
|
||||||
|
case LFUN_CHAR_LEFT:
|
||||||
|
case LFUN_CHAR_BACKWARD:
|
||||||
case LFUN_CHAR_FORWARD:
|
case LFUN_CHAR_FORWARD:
|
||||||
cur.updateFlags(Update::Decoration | Update::FitCursor);
|
cur.updateFlags(Update::Decoration | Update::FitCursor);
|
||||||
case LFUN_CHAR_FORWARD_SELECT:
|
|
||||||
cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
|
|
||||||
cur.autocorrect() = false;
|
|
||||||
cur.clearTargetX();
|
|
||||||
cur.macroModeClose();
|
|
||||||
if (cur.pos() != cur.lastpos() && cur.openable(cur.nextAtom())) {
|
|
||||||
cur.pushBackward(*cur.nextAtom().nucleus());
|
|
||||||
cur.inset().idxFirst(cur);
|
|
||||||
} else if (cur.posForward() || idxForward(cur)
|
|
||||||
|| cur.popForward() || cur.selection())
|
|
||||||
;
|
|
||||||
else {
|
|
||||||
cmd = FuncRequest(LFUN_FINISHED_FORWARD);
|
|
||||||
cur.undispatched();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LFUN_CHAR_BACKWARD:
|
|
||||||
cur.updateFlags(Update::Decoration | Update::FitCursor);
|
|
||||||
case LFUN_CHAR_BACKWARD_SELECT:
|
|
||||||
cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
|
|
||||||
cur.autocorrect() = false;
|
|
||||||
cur.clearTargetX();
|
|
||||||
cur.macroModeClose();
|
|
||||||
if (cur.pos() != 0 && cur.openable(cur.prevAtom())) {
|
|
||||||
cur.posBackward();
|
|
||||||
cur.push(*cur.nextAtom().nucleus());
|
|
||||||
cur.inset().idxLast(cur);
|
|
||||||
} else if (cur.posBackward() || idxBackward(cur)
|
|
||||||
|| cur.popBackward() || cur.selection())
|
|
||||||
;
|
|
||||||
else {
|
|
||||||
cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
|
|
||||||
cur.undispatched();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LFUN_CHAR_RIGHT:
|
|
||||||
case LFUN_CHAR_RIGHT_SELECT:
|
case LFUN_CHAR_RIGHT_SELECT:
|
||||||
//FIXME: for visual cursor, really move right
|
|
||||||
if (reverseDirectionNeeded(cur))
|
|
||||||
cmd.action = cmd.action == LFUN_CHAR_RIGHT_SELECT ?
|
|
||||||
LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD;
|
|
||||||
else
|
|
||||||
cmd.action = cmd.action == LFUN_CHAR_RIGHT_SELECT ?
|
|
||||||
LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD;
|
|
||||||
doDispatch(cur, cmd);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LFUN_CHAR_LEFT:
|
|
||||||
case LFUN_CHAR_LEFT_SELECT:
|
case LFUN_CHAR_LEFT_SELECT:
|
||||||
//FIXME: for visual cursor, really move left
|
case LFUN_CHAR_BACKWARD_SELECT:
|
||||||
if (reverseDirectionNeeded(cur))
|
case LFUN_CHAR_FORWARD_SELECT: {
|
||||||
cmd.action = cmd.action == LFUN_CHAR_LEFT_SELECT ?
|
// are we in a selection?
|
||||||
LFUN_CHAR_FORWARD_SELECT : LFUN_CHAR_FORWARD;
|
bool select = (cmd.action == LFUN_CHAR_RIGHT_SELECT
|
||||||
else
|
|| cmd.action == LFUN_CHAR_LEFT_SELECT
|
||||||
cmd.action = cmd.action == LFUN_CHAR_LEFT_SELECT ?
|
|| cmd.action == LFUN_CHAR_BACKWARD_SELECT
|
||||||
LFUN_CHAR_BACKWARD_SELECT : LFUN_CHAR_BACKWARD;
|
|| cmd.action == LFUN_CHAR_FORWARD_SELECT);
|
||||||
doDispatch(cur, cmd);
|
// are we moving forward or backwards?
|
||||||
|
// If the command was RIGHT or LEFT, then whether we're moving forward
|
||||||
|
// or backwards depends on the cursor movement mode (logical or visual):
|
||||||
|
// * in visual mode, since math is always LTR, right -> forward,
|
||||||
|
// left -> backwards
|
||||||
|
// * in logical mode, the mapping is determined by the
|
||||||
|
// reverseDirectionNeeded() function
|
||||||
|
|
||||||
|
bool forward;
|
||||||
|
kb_action finish_lfun;
|
||||||
|
|
||||||
|
if (cmd.action == LFUN_CHAR_FORWARD
|
||||||
|
|| cmd.action == LFUN_CHAR_FORWARD_SELECT) {
|
||||||
|
forward = true;
|
||||||
|
finish_lfun = LFUN_FINISHED_FORWARD;
|
||||||
|
}
|
||||||
|
else if (cmd.action == LFUN_CHAR_BACKWARD
|
||||||
|
|| cmd.action == LFUN_CHAR_BACKWARD_SELECT) {
|
||||||
|
forward = false;
|
||||||
|
finish_lfun = LFUN_FINISHED_BACKWARD;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
bool right = (cmd.action == LFUN_CHAR_RIGHT_SELECT
|
||||||
|
|| cmd.action == LFUN_CHAR_RIGHT);
|
||||||
|
if (lyxrc.visual_cursor || !reverseDirectionNeeded(cur))
|
||||||
|
forward = right;
|
||||||
|
else
|
||||||
|
forward = !right;
|
||||||
|
|
||||||
|
if (right)
|
||||||
|
finish_lfun = LFUN_FINISHED_RIGHT;
|
||||||
|
else
|
||||||
|
finish_lfun = LFUN_FINISHED_LEFT;
|
||||||
|
}
|
||||||
|
// Now that we know exactly what we want to do, let's do it!
|
||||||
|
cur.selHandle(select);
|
||||||
|
cur.autocorrect() = false;
|
||||||
|
cur.clearTargetX();
|
||||||
|
cur.macroModeClose();
|
||||||
|
// try moving forward or backwards as necessary...
|
||||||
|
if (!(forward ? cursorMathForward(cur) : cursorMathBackward(cur))) {
|
||||||
|
// ... and if movement failed, then finish forward or backwards
|
||||||
|
// as necessary
|
||||||
|
cmd = FuncRequest(finish_lfun);
|
||||||
|
cur.undispatched();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case LFUN_DOWN:
|
case LFUN_DOWN:
|
||||||
case LFUN_UP:
|
case LFUN_UP:
|
||||||
@ -1584,4 +1587,41 @@ bool InsetMathNest::script(Cursor & cur, bool up,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool InsetMathNest::cursorMathForward(Cursor & cur)
|
||||||
|
{
|
||||||
|
if (cur.pos() != cur.lastpos() && cur.openable(cur.nextAtom())) {
|
||||||
|
cur.pushBackward(*cur.nextAtom().nucleus());
|
||||||
|
cur.inset().idxFirst(cur);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (cur.posForward() || idxForward(cur) || cur.selection())
|
||||||
|
return true;
|
||||||
|
// try to pop forwards --- but don't pop out of math! leave that to
|
||||||
|
// the FINISH lfuns
|
||||||
|
int s = cur.depth() - 2;
|
||||||
|
if (s >= 0 && cur[s].inset().asInsetMath())
|
||||||
|
return cur.popForward();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool InsetMathNest::cursorMathBackward(Cursor & cur)
|
||||||
|
{
|
||||||
|
if (cur.pos() != 0 && cur.openable(cur.prevAtom())) {
|
||||||
|
cur.posBackward();
|
||||||
|
cur.push(*cur.nextAtom().nucleus());
|
||||||
|
cur.inset().idxLast(cur);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (cur.posBackward() || idxBackward(cur) || cur.selection())
|
||||||
|
return true;
|
||||||
|
// try to pop backwards --- but don't pop out of math! leave that to
|
||||||
|
// the FINISH lfuns
|
||||||
|
int s = cur.depth() - 2;
|
||||||
|
if (s >= 0 && cur[s].inset().asInsetMath())
|
||||||
|
return cur.popBackward();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
@ -153,6 +153,10 @@ private:
|
|||||||
/// Find a macro to fold or unfold, starting at searchCur and searchCur.nextInset() pointing to a macro
|
/// Find a macro to fold or unfold, starting at searchCur and searchCur.nextInset() pointing to a macro
|
||||||
/// afterwards if found
|
/// afterwards if found
|
||||||
bool findMacroToFoldUnfold(Cursor & searchCur, bool fold) const;
|
bool findMacroToFoldUnfold(Cursor & searchCur, bool fold) const;
|
||||||
|
/// move cursor forward
|
||||||
|
bool cursorMathForward(Cursor & cur);
|
||||||
|
/// move cursor backwards
|
||||||
|
bool cursorMathBackward(Cursor & cur);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// we store the cells in a vector
|
/// we store the cells in a vector
|
||||||
|
Loading…
Reference in New Issue
Block a user