[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lyx-devel
Subject:    Re: [PATCH] LFUN_DOWN: if cursor is on last line, move to end
From:       Stephan Witt <st.witt () gmx ! net>
Date:       2013-06-26 9:49:59
Message-ID: A3AF0FE6-C629-4969-AD3E-56B248C21FB7 () gmx ! net
[Download RAW message or body]

Am 26.06.2013 um 10:41 schrieb Jean-Marc Lasgouttes <lasgouttes@lyx.org>:

> Le 26/06/2013 10:07, Stephan Witt a écrit :
>> How does this look?
>> 
>> bool Cursor::atFirstOrLastRowOfDocument(bool up)
>> {
>>    Cursor dummy = *this;
>>    bool result = dummy.atFirstOrLastRow(up);
>>    while (result && dummy.depth() > 1) {
>>       dummy.pop();
>>       result = dummy.atFirstOrLastRow(up);
>>    }
>>    return result;
>> }
> 
> Yes, I prefer this version.
> 
> JMarc

That's the final patch then.

Stephan


["0004-LFUN_DOWN-if-cursor-is-on-last-line-move-to-end.patch" (0004-LFUN_DOWN-if-cursor-is-on-last-line-move-to-end.patch)]

diff --git a/src/Cursor.cpp b/src/Cursor.cpp
index 3ad16f4..415aedb 100644
--- a/src/Cursor.cpp
+++ b/src/Cursor.cpp
@@ -1945,6 +1945,18 @@ bool Cursor::upDownInMath(bool up)
 }
 
 
+bool Cursor::atFirstOrLastRowOfDocument(bool up)
+{
+	Cursor current = *this;
+	bool result = current.atFirstOrLastRow(up);
+	while (result && current.depth() > 1) {
+		current.pop();
+		result = current.atFirstOrLastRow(up);
+	}
+	return result;
+}
+
+
 bool Cursor::atFirstOrLastRow(bool up)
 {
 	TextMetrics const & tm = bv_->textMetrics(text());
@@ -2027,13 +2039,7 @@ bool Cursor::upDownInText(bool up, bool & updateNeeded)
 		// Is there a place for the cursor to go ? If yes, we
 		// can execute the DEPM, otherwise we should keep the
 		// paragraph to host the cursor.
-		Cursor dummy = *this;
-		bool valid_destination = false;
-		for(; dummy.depth(); dummy.pop())
-			if (!dummy.atFirstOrLastRow(up)) {
-				valid_destination = true;
-				break;
-			}
+		bool const valid_destination = !atFirstOrLastRowOfDocument(up);
 
 		// will a next dispatch follow and if there is a new 
 		// dispatch will it move the cursor out ?
@@ -2042,7 +2048,7 @@ bool Cursor::upDownInText(bool up, bool & updateNeeded)
 			// you e.g. move out of an inset. And to give the 
 			// DEPM the possibility of doing something we must
 			// provide it with two different cursors. (Lgb, vfr)
-			dummy = *this;
+			Cursor dummy = *this;
 			dummy.pos() = dummy.pos() == 0 ? dummy.lastpos() : 0;
 			dummy.pit() = dummy.pit() == 0 ? dummy.lastpit() : 0;
 
diff --git a/src/Cursor.h b/src/Cursor.h
index 006919b..49922c6 100644
--- a/src/Cursor.h
+++ b/src/Cursor.h
@@ -419,8 +419,10 @@ public:
 	/// move the cursor up by sending an internal LFUN_DOWN,
 	/// return true if fullscreen update is needed
 	bool down();
-	/// whether the cursor is either at the first or last row
+	/// whether the cursor is either at the first or last row of inset
 	bool atFirstOrLastRow(bool up);
+	/// whether the cursor is either at the first or last row of document
+	bool atFirstOrLastRowOfDocument(bool up);
 	/// 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
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 2fa5ccf..0c8903f 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -637,13 +637,17 @@ void LyXAction::init()
 /*!
  * \var lyx::FuncCode lyx::LFUN_DOWN
  * \li Action: Moves the cursor one line in downward direction.
+               With mac_like_cursor_movement the cursor is moved to
+               the end of the line if on the last line already.
  * \li Syntax: down
  * \endvar
  */
 		{ LFUN_DOWN, "down", ReadOnly | NoUpdate, Edit },
 /*!
  * \var lyx::FuncCode lyx::LFUN_UP
- * \li Action: Moves the cursor one line in upward direction.
+ * \li Action: Moves the cursor one line in upward direction. 
+               With mac_like_cursor_movement the cursor is moved to
+               the beginning of the line if on the first line already.
  * \li Syntax: up
  * \endvar
  */
@@ -651,7 +655,8 @@ void LyXAction::init()
 /*!
  * \var lyx::FuncCode lyx::LFUN_DOWN_SELECT
  * \li Action: Moves the cursor one line in downward direction adding the current
-               position to the selection.
+               position to the selection. With mac_like_cursor_movement the cursor
+               is moved to the end of the last line if on the last line already.
  * \li Syntax: down-select
  * \endvar
  */
@@ -659,7 +664,8 @@ void LyXAction::init()
 /*!
  * \var lyx::FuncCode lyx::LFUN_UP_SELECT
  * \li Action: Moves the cursor one line in upward direction adding the current
-               position to the selection.
+               position to the selection. With mac_like_cursor_movement the cursor
+               is moved to the beginning of the first line if on the first line already.
  * \li Syntax: up-select
  * \endvar
  */
diff --git a/src/Text3.cpp b/src/Text3.cpp
index 7045362..ed5537d 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -739,8 +739,16 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 		// move cursor up/down
 		bool up = cmd.action() == LFUN_UP_SELECT || cmd.action() == LFUN_UP;
 		bool const atFirstOrLastRow = cur.atFirstOrLastRow(up);
-
-		if (!atFirstOrLastRow) {
+		bool const atFirstOrLastRowOfDoc = atFirstOrLastRow && cur.atFirstOrLastRowOfDocument(up);
+
+		if (lyxrc.mac_like_cursor_movement && atFirstOrLastRowOfDoc) {
+			cmd.setAction(
+				select && up ? LFUN_BUFFER_BEGIN_SELECT :
+				select ? LFUN_BUFFER_END_SELECT :
+				up ? LFUN_BUFFER_BEGIN :
+				LFUN_BUFFER_END) ;
+			dispatch(cur, cmd);
+		} else if (!atFirstOrLastRow) {
 			needsUpdate |= cur.selHandle(select);	
 			cur.selHandle(select);
 			cur.upDownInText(up, needsUpdate);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic