Hi Mario,
Le 28/05/2016 10:36, Mario D a écrit :
...
Consider
\frac{1}{2} + \left(1+1\right) = 2.5
^ ^ ^ ^ ^
A B C D E
Wherever I am, if I hit ctrl+right I am driven to E.
What I would like is that if I am in A I land in B and if I am in C I go
to D
...
What I have not been able to understand is which function I should bind
to ctrl+right so that this combination drives me from A to B or from C
to D instead of from everywhere to E
I agree ctrl+arrows could do better. The attached patch implements your
suggestion.
Pro: I find this behaviour more useful. It could be made better by
skipping strings of characters that constitute "words", but I am not
sure how to define this notion properly in mathed. (Jean-Marc speaks of
using the rel/bin/op categories to find a criterion, let's think about it.)
Con: it is a bit unintuitive that ctrl+arrow behaves differently from
ctrl+shift+arrows. But I believe that the current behaviour of
ctrl+shift+arrows is fine and should be kept.
Incidentally, I also do not like very much the fact that if in A then
shift+right selects all the A-B portion of the formula: in my view, this
should be the behavior of
ctrl+shift+right, whereas shift+right should select only the very next
character (that is, the numerator if I am in A).
Selections in LyX correspond to meaningful objects, not portions of
LaTeX code such as \frac{1} in your example. So what you propose for
shift+right does not make sense to LyX.
As for ctrl+shift+arrows, I find them useful to select entire insets
quickly.
Guillaume
>From 96d2db292628d3ab588a24574f9e27e8e076484c Mon Sep 17 00:00:00 2001
From: Guillaume Munch <[email protected]>
Date: Fri, 27 May 2016 21:00:54 +0100
Subject: [PATCH] Make ctrl+arrow behave like shift+arrow in math
Define ctrl+up,down for consistency
---
src/mathed/InsetMathGrid.cpp | 4 ----
src/mathed/InsetMathNest.cpp | 54 ++++++++++++++++++++++++--------------------
src/mathed/InsetMathNest.h | 4 ++--
3 files changed, 32 insertions(+), 30 deletions(-)
diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp
index b505886..d9cc469 100644
--- a/src/mathed/InsetMathGrid.cpp
+++ b/src/mathed/InsetMathGrid.cpp
@@ -1665,8 +1665,6 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
}
case LFUN_LINE_BEGIN:
- case LFUN_WORD_BACKWARD:
- case LFUN_WORD_LEFT:
cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
// fall through
case LFUN_LINE_BEGIN_SELECT:
@@ -1690,8 +1688,6 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
}
break;
- case LFUN_WORD_FORWARD:
- case LFUN_WORD_RIGHT:
case LFUN_LINE_END:
cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
// fall through
diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp
index 7357b5f..dde674e 100644
--- a/src/mathed/InsetMathNest.cpp
+++ b/src/mathed/InsetMathNest.cpp
@@ -638,6 +638,10 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_CHAR_LEFT:
case LFUN_CHAR_BACKWARD:
case LFUN_CHAR_FORWARD:
+ case LFUN_WORD_RIGHT:
+ case LFUN_WORD_LEFT:
+ case LFUN_WORD_BACKWARD:
+ case LFUN_WORD_FORWARD:
cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
// fall through
case LFUN_CHAR_RIGHT_SELECT:
@@ -649,6 +653,9 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
|| act == LFUN_CHAR_LEFT_SELECT
|| act == LFUN_CHAR_BACKWARD_SELECT
|| act == LFUN_CHAR_FORWARD_SELECT);
+ // enter insets of possible?
+ bool enter = (act != LFUN_WORD_BACKWARD) && (act != LFUN_WORD_LEFT)
+ && (act != LFUN_WORD_FORWARD) && (act != LFUN_WORD_RIGHT);
// 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):
@@ -661,18 +668,21 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
FuncCode finish_lfun;
if (act == LFUN_CHAR_FORWARD
- || act == LFUN_CHAR_FORWARD_SELECT) {
+ || act == LFUN_CHAR_FORWARD_SELECT
+ || act == LFUN_WORD_FORWARD) {
forward = true;
finish_lfun = LFUN_FINISHED_FORWARD;
}
else if (act == LFUN_CHAR_BACKWARD
- || act == LFUN_CHAR_BACKWARD_SELECT) {
+ || act == LFUN_CHAR_BACKWARD_SELECT
+ || act == LFUN_WORD_BACKWARD) {
forward = false;
finish_lfun = LFUN_FINISHED_BACKWARD;
}
else {
bool right = (act == LFUN_CHAR_RIGHT_SELECT
- || act == LFUN_CHAR_RIGHT);
+ || act == LFUN_CHAR_RIGHT
+ || act == LFUN_WORD_RIGHT);
if (lyxrc.visual_cursor || !cur.reverseDirectionNeeded())
forward = right;
else
@@ -688,7 +698,8 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
cur.clearTargetX();
cur.macroModeClose();
// try moving forward or backwards as necessary...
- if (!(forward ? cursorMathForward(cur) : cursorMathBackward(cur))) {
+ if (!(forward ? cursorMathForward(cur, enter)
+ : cursorMathBackward(cur, enter))) {
// ... and if movement failed, then finish forward or backwards
// as necessary
cmd = FuncRequest(finish_lfun);
@@ -699,10 +710,14 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_DOWN:
case LFUN_UP:
+ case LFUN_PARAGRAPH_UP:
+ case LFUN_PARAGRAPH_DOWN:
cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
// fall through
case LFUN_DOWN_SELECT:
- case LFUN_UP_SELECT: {
+ case LFUN_UP_SELECT:
+ case LFUN_PARAGRAPH_UP_SELECT:
+ case LFUN_PARAGRAPH_DOWN_SELECT: {
// close active macro
if (cur.inMacroMode()) {
cur.macroModeClose();
@@ -710,8 +725,10 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
}
// stop/start the selection
- bool select = act == LFUN_DOWN_SELECT ||
- act == LFUN_UP_SELECT;
+ bool select = act == LFUN_DOWN_SELECT
+ || act == LFUN_UP_SELECT
+ || act == LFUN_PARAGRAPH_DOWN_SELECT
+ || act == LFUN_PARAGRAPH_UP_SELECT;
cur.selHandle(select);
// handle autocorrect:
@@ -721,7 +738,8 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
}
// go up/down
- bool up = act == LFUN_UP || act == LFUN_UP_SELECT;
+ bool up = act == LFUN_UP || act == LFUN_UP_SELECT
+ || act == LFUN_PARAGRAPH_UP || act == LFUN_PARAGRAPH_UP_SELECT;
bool successful = cur.upDownInMath(up);
if (successful)
break;
@@ -755,17 +773,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
cur.bv().cursor() = cur;
break;
- case LFUN_PARAGRAPH_UP:
- case LFUN_PARAGRAPH_DOWN:
- cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
- // fall through
- case LFUN_PARAGRAPH_UP_SELECT:
- case LFUN_PARAGRAPH_DOWN_SELECT:
- break;
-
case LFUN_LINE_BEGIN:
- case LFUN_WORD_BACKWARD:
- case LFUN_WORD_LEFT:
cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
// fall through
case LFUN_LINE_BEGIN_SELECT:
@@ -789,8 +797,6 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
}
break;
- case LFUN_WORD_FORWARD:
- case LFUN_WORD_RIGHT:
case LFUN_LINE_END:
cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
// fall through
@@ -2075,9 +2081,9 @@ void InsetMathNest::completionPosAndDim(Cursor const & cur, int & x, int & y,
}
-bool InsetMathNest::cursorMathForward(Cursor & cur)
+bool InsetMathNest::cursorMathForward(Cursor & cur, bool enter)
{
- if (cur.pos() != cur.lastpos() && cur.openable(cur.nextAtom())) {
+ if (enter && cur.pos() != cur.lastpos() && cur.openable(cur.nextAtom())) {
cur.pushBackward(*cur.nextAtom().nucleus());
cur.inset().idxFirst(cur);
return true;
@@ -2093,9 +2099,9 @@ bool InsetMathNest::cursorMathForward(Cursor & cur)
}
-bool InsetMathNest::cursorMathBackward(Cursor & cur)
+bool InsetMathNest::cursorMathBackward(Cursor & cur, bool enter)
{
- if (cur.pos() != 0 && cur.openable(cur.prevAtom())) {
+ if (enter && cur.pos() != 0 && cur.openable(cur.prevAtom())) {
cur.posBackward();
cur.push(*cur.nextAtom().nucleus());
cur.inset().idxLast(cur);
diff --git a/src/mathed/InsetMathNest.h b/src/mathed/InsetMathNest.h
index b9cc1f6..8d383d0 100644
--- a/src/mathed/InsetMathNest.h
+++ b/src/mathed/InsetMathNest.h
@@ -190,9 +190,9 @@ private:
/// afterwards if found
bool findMacroToFoldUnfold(Cursor & searchCur, bool fold) const;
/// move cursor forward
- bool cursorMathForward(Cursor & cur);
+ bool cursorMathForward(Cursor & cur, bool enter = true);
/// move cursor backwards
- bool cursorMathBackward(Cursor & cur);
+ bool cursorMathBackward(Cursor & cur, bool enter = true);
protected:
/// we store the cells in a vector
--
2.7.4