commit 008a0825e8d67b9c0a3d31b906f04cd7b8fd18a8
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Tue Jun 29 12:43:59 2021 +0200
Always remove selection after cursor up/down
When the cursor cannot move on cursor up/down, at least the selection
should be cleared (when not selecting).
To detect this, the method Cursor::upDownInText has been modified to
return true when cursor is at top/bottom of inset, but there is some
room above/below.
Moreover, introduce the functions LFUN_FINISHED_UP/DOWN, which is
dispatched at upper cursor level as long as no local movement is
possible. This allows to handle differently the original char moving
action and its consequences.
Fixes part of bug #12310.
---
src/Cursor.cpp | 2 +-
src/Cursor.h | 5 +++--
src/FuncCode.h | 2 ++
src/LyXAction.cpp | 16 ++++++++++++++++
src/Text3.cpp | 42 +++++++++++++++++++++++++++++++-----------
5 files changed, 53 insertions(+), 14 deletions(-)
diff --git a/src/Cursor.cpp b/src/Cursor.cpp
index ad46e8c..d2190e7 100644
--- a/src/Cursor.cpp
+++ b/src/Cursor.cpp
@@ -2216,7 +2216,7 @@ bool Cursor::upDownInText(bool up, bool & updateNeeded)
if (updateNeeded)
forceBufferUpdate();
}
- return false;
+ return valid_destination;
}
// with and without selection are handled differently
diff --git a/src/Cursor.h b/src/Cursor.h
index f549047..4ef5bc9 100644
--- a/src/Cursor.h
+++ b/src/Cursor.h
@@ -496,8 +496,9 @@ public:
/// return true if fullscreen update is needed
bool down();
/// move up/down in a text inset, called for LFUN_UP/DOWN,
- /// return true if successful, updateNeeded set to true if fullscreen
- /// update is needed, otherwise it's not touched
+ /// return true if the cursor has moved or can move, updateNeeded
+ /// set to true if fullscreen update is needed, otherwise it's not
+ /// touched
bool upDownInText(bool up, bool & updateNeeded);
/// move up/down in math or any non text inset, call for LFUN_UP/DOWN
/// return true if successful
diff --git a/src/FuncCode.h b/src/FuncCode.h
index 391232b..20231eb 100644
--- a/src/FuncCode.h
+++ b/src/FuncCode.h
@@ -500,6 +500,8 @@ enum FuncCode
LFUN_SPELLING_ADD_LOCAL, // jspitzm 20210306
// 390
LFUN_SPELLING_REMOVE_LOCAL, // jspitzm 20210307
+ LFUN_FINISHED_DOWN, // lasgouttes 20210629
+ LFUN_FINISHED_UP, // lasgouttes 20210629
LFUN_LASTACTION // end of the table
};
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 8933e3d..254060e 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -1669,6 +1669,22 @@ void LyXAction::init()
{ LFUN_FINISHED_RIGHT, "", ReadOnly, Hidden },
/*!
+ * \var lyx::FuncCode lyx::LFUN_FINISHED_UP
+ * \li Action: Moves the cursor out of the current slice, going up.
+ * \li Notion: See also #LFUN_FINISHED_DOWN.
+ * \endvar
+ */
+ { LFUN_FINISHED_UP, "", ReadOnly, Hidden },
+
+/*!
+ * \var lyx::FuncCode lyx::LFUN_FINISHED_DOWN
+ * \li Action: Moves the cursor out of the current slice, going down.
+ * \li Notion: See also #LFUN_FINISHED_DOWN.
+ * \endvar
+ */
+ { LFUN_FINISHED_DOWN, "", ReadOnly, Hidden },
+
+/*!
* \var lyx::FuncCode lyx::LFUN_FLEX_INSERT
* \li Action: Inserts CharStyle, Custom inset or XML short element.
* \li Notion: Look into the Customization manual for more information about
diff --git a/src/Text3.cpp b/src/Text3.cpp
index ffc5d75..fcccdd3 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -892,14 +892,12 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_UP:
case LFUN_DOWN: {
// stop/start the selection
- bool select = cmd.action() == LFUN_DOWN_SELECT ||
- cmd.action() == LFUN_UP_SELECT;
-
+ bool const select = cmd.action() == LFUN_DOWN_SELECT
+ || cmd.action() == LFUN_UP_SELECT;
// move cursor up/down
- bool up = cmd.action() == LFUN_UP_SELECT || cmd.action() ==
LFUN_UP;
- bool const atFirstOrLastRow = cur.atFirstOrLastRow(up);
+ bool const up = cmd.action() == LFUN_UP_SELECT || cmd.action()
== LFUN_UP;
- if (!atFirstOrLastRow) {
+ if (!cur.atFirstOrLastRow(up)) {
needsUpdate |= cur.selHandle(select);
cur.upDownInText(up, needsUpdate);
needsUpdate |= cur.beforeDispatchCursor().inMathed();
@@ -915,13 +913,35 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
cur.forceBufferUpdate();
break;
}
+ needsUpdate |= cur.selHandle(select);
+ bool const can_move = cur.upDownInText(up, needsUpdate);
+ // if the cursor can be moved up or down at an upper
level,
+ // delegate the dispatch to next level. Otherwise, we
are
+ // done.
+ if (can_move) {
+ cmd = FuncRequest(up ? LFUN_FINISHED_UP :
LFUN_FINISHED_DOWN);
+ cur.undispatched();
+ }
+ }
- // if the cursor cannot be moved up or down do not
remove
- // the selection right now, but wait for the next
dispatch.
- if (select)
- needsUpdate |= cur.selHandle(select);
+ break;
+ }
+
+ case LFUN_FINISHED_UP:
+ case LFUN_FINISHED_DOWN: {
+ // move cursor up/down
+ bool const up = cmd.action() == LFUN_FINISHED_UP;
+
+ if (!cur.atFirstOrLastRow(up)) {
cur.upDownInText(up, needsUpdate);
- cur.undispatched();
+ needsUpdate |= cur.beforeDispatchCursor().inMathed();
+ } else {
+ bool const can_move = cur.upDownInText(up, needsUpdate);
+ // if the cursor can be moved up or down and we are not
+ // moving cusor at top level, wait for the next
dispatch.
+ // Otherwise, we are done.
+ if (can_move)
+ cur.undispatched();
}
break;
--
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs