[LyX/master] Fix replace all in selection with change tracking

Juergen Spitzmueller spitz at lyx.org
Tue Feb 16 08:39:04 UTC 2021


commit 119e8c08d47a4fb50a77995ed837283c163d1685
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Tue Feb 16 09:42:17 2021 +0100

    Fix replace all in selection with change tracking
---
 src/lyxfind.cpp |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp
index 6caa7fa..50c3381 100644
--- a/src/lyxfind.cpp
+++ b/src/lyxfind.cpp
@@ -391,25 +391,30 @@ int replaceAll(BufferView * bv,
 		pos_type const pos = cur.pos();
 		Font const font = cur.paragraph().getFontSettings(buf.params(), pos);
 		cur.recordUndo();
-		int struck = ssize -
+		int ct_deleted_text = ssize -
 			cur.paragraph().eraseChars(pos, pos + match_len,
 						   buf.params().track_changes);
 		cur.paragraph().insert(pos, replacestr, font,
 				       Change(buf.params().track_changes
 					      ? Change::INSERTED
 					      : Change::UNCHANGED));
-		for (int i = 0; i < rsize + struck; ++i)
-			cur.forwardChar();
+		for (int i = 0; i < rsize + ct_deleted_text
+		     && cur.pos() < cur.lastpos(); ++i)
+			cur.forwardPos();
 		if (onlysel && cur.pit() == endcur.pit() && cur.idx() == endcur.idx()) {
 			// Adjust end of selection for replace-all in selection
 			if (rsize > ssize) {
 				int const offset = rsize - ssize;
-				for (int i = 0; i < offset + struck; ++i)
+				for (int i = 0; i < offset + ct_deleted_text
+				     && endcur.pos() < endcur.lastpos(); ++i)
 					endcur.forwardPos();
 			} else {
 				int const offset = ssize - rsize;
-				for (int i = 0; i < offset + struck; ++i)
+				for (int i = 0; i < offset && endcur.pos() > 0; ++i)
 					endcur.backwardPos();
+				for (int i = 0; i < ct_deleted_text
+				     && endcur.pos() < endcur.lastpos(); ++i)
+					endcur.forwardPos();
 			}
 		}
 		++num;


More information about the lyx-cvs mailing list