r23313 by jghali - #15900: Story Editor jumps to top every time a style is changed

scribus-commit scribus-commit at lists.scribus.net
Sun Nov 3 00:16:13 UTC 2019


Author: jghali
Date: Sun Nov  3 00:16:13 2019
New Revision: 23313

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23313
Log:
#15900: Story Editor jumps to top every time a style is changed

Modified:
    trunk/Scribus/scribus/ui/storyeditor.cpp
    trunk/Scribus/scribus/ui/storyeditor.h

Modified: trunk/Scribus/scribus/ui/storyeditor.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23313&path=/trunk/Scribus/scribus/ui/storyeditor.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/storyeditor.cpp	(original)
+++ trunk/Scribus/scribus/ui/storyeditor.cpp	Sun Nov  3 00:16:13 2019
@@ -506,13 +506,13 @@
 	QTextCursor tc(textCursor());
 	if (tc.hasSelection())
 	{
-		QPair<int, int> selPair = qMakePair(tc.selectionStart(), tc.selectionEnd());
-		SelStack.push(selPair);
+		auto selTuple = std::make_tuple(tc.selectionStart(), tc.selectionEnd(), verticalScrollBar()->value());
+		SelStack.push(selTuple);
 	}
 	else
 	{
-		QPair<int, int> selPair = qMakePair(tc.position(), -1);
-		SelStack.push(selPair);
+		auto selTuple = std::make_tuple(tc.position(), -1, verticalScrollBar()->value());
+		SelStack.push(selTuple);
 	}
 	QTextEdit::focusOutEvent(e);
 }
@@ -522,11 +522,13 @@
 	if (SelStack.count() > 0)
 	{
 		QTextCursor tc(textCursor());
-		QPair<int, int> selPair = SelStack.pop();
-		tc.setPosition(qMin(selPair.first, StyledText.length()));
-		if (selPair.second >= 0)
-			tc.setPosition(selPair.second, QTextCursor::KeepAnchor);
+		int selFirst, selSecond, selThird;
+		std::tie(selFirst, selSecond, selThird) = SelStack.pop();
+		tc.setPosition(qMin(selFirst, StyledText.length()));
+		if (selSecond >= 0)
+			tc.setPosition(selSecond, QTextCursor::KeepAnchor);
 		setTextCursor(tc);
+		verticalScrollBar()->setValue(selThird);
 	}
 	QTextEdit::focusInEvent(e);
 }
@@ -710,7 +712,7 @@
 		SelCharStart = currItem->itemText.cursorPosition();
 	SelCharStart -= currItem->itemText.startOfParagraph(newSelParaStart);
 	if (SelStack.count())
-		SelStack.top().second = -1;
+		std::get<1>(SelStack.top()) = -1;
 	//qDebug() << "SE::loadItemText: cursor";
 //	setCursorPosition(SelParaStart, SelCharStart);
 	emit setProps(newSelParaStart, SelCharStart);
@@ -911,11 +913,12 @@
 	if (SelStack.count())
 	{
 		QTextCursor tc(textCursor());
-		QPair<int, int> selPair = SelStack.pop();
-		if (selPair.second >= 0)
-		{
-			tc.setPosition(selPair.first);
-			tc.setPosition(selPair.second, QTextCursor::KeepAnchor);
+		int selFirst, selSecond, selThird;
+		std::tie(selFirst, selSecond, selThird) = SelStack.pop();
+		if (selSecond >= 0)
+		{
+			tc.setPosition(selFirst);
+			tc.setPosition(selSecond, QTextCursor::KeepAnchor);
 			setTextCursor(tc);
 		}
 	}
@@ -935,11 +938,12 @@
 	if (SelStack.count())
 	{
 		QTextCursor tc(textCursor());
-		QPair<int, int> selPair = SelStack.pop();
-		if (selPair.second >= 0)
-		{
-			tc.setPosition(selPair.first);
-			tc.setPosition(selPair.second, QTextCursor::KeepAnchor);
+		int selFirst, selSecond, selThird;
+		std::tie(selFirst, selSecond, selThird) = SelStack.pop();
+		if (selSecond >= 0)
+		{
+			tc.setPosition(selFirst);
+			tc.setPosition(selSecond, QTextCursor::KeepAnchor);
 			setTextCursor(tc);
 		}
 	}
@@ -3038,7 +3042,7 @@
 			QTextCursor tCursor = Editor->textCursor();
 			tCursor.setPosition(pos);
 			Editor->setTextCursor(tCursor);
-			Editor->SelStack.push(qMakePair(pos, -1));
+			Editor->SelStack.push(std::make_tuple(pos, -1, Editor->verticalScrollBar()->value()));
 		}
 	}
 	qApp->processEvents();

Modified: trunk/Scribus/scribus/ui/storyeditor.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23313&path=/trunk/Scribus/scribus/ui/storyeditor.h
==============================================================================
--- trunk/Scribus/scribus/ui/storyeditor.h	(original)
+++ trunk/Scribus/scribus/ui/storyeditor.h	Sun Nov  3 00:16:13 2019
@@ -23,6 +23,8 @@
 
 #ifndef STORYEDITOR_H
 #define STORYEDITOR_H
+
+#include <tuple>
 
 #include <QTextEdit>
 #include <QAction>
@@ -163,7 +165,7 @@
 	QString CurrFont;
 	QString unicodeInputString;
 
-	QStack< QPair<int, int> > SelStack;
+	QStack< std::tuple<int, int, int> > SelStack;
 
 	int SelCharStart;
 	int SelCharEnd;




More information about the scribus-commit mailing list