r24040 by jghali - #14892: Undo doesn't work for search/replace operation

scribus-commit scribus-commit at lists.scribus.net
Sat Sep 26 18:43:39 UTC 2020


Author: jghali
Date: Sat Sep 26 18:43:39 2020
New Revision: 24040

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24040
Log:
#14892: Undo doesn't work for search/replace operation

Modified:
    trunk/Scribus/scribus/ui/search.cpp

Modified: trunk/Scribus/scribus/ui/search.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24040&path=/trunk/Scribus/scribus/ui/search.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/search.cpp	(original)
+++ trunk/Scribus/scribus/ui/search.cpp	Sat Sep 26 18:43:39 2020
@@ -38,6 +38,8 @@
 #include "shadebutton.h"
 #include "styleselect.h"
 #include "ui/storyeditor.h"
+#include "undomanager.h"
+#include "undotransaction.h"
 #include "util.h"
 #include "util_text.h"
 
@@ -728,9 +730,44 @@
 {
 	if (m_itemMode)
 	{
+		UndoTransaction transaction;
+		if (UndoManager::undoEnabled())
+			transaction = UndoManager::instance()->beginTransaction(m_item->getUName(), m_item->getUPixmap());
+
 		if (RText->isChecked())
 		{
+			QString selectedText = m_item->itemText.selectedText();
 			QString repl = RTextVal->text();
+			if (UndoManager::undoEnabled())
+			{
+				UndoObject* undoTarget = m_item->isNoteFrame() ? dynamic_cast<UndoObject*>(m_item->doc()) : dynamic_cast<UndoObject*>(m_item);
+				if (selectedText.length() > 0)
+				{
+					auto is = new ScItemState<CharStyle>(Um::DeleteText, "", Um::IDelete);
+					int selStart =  m_item->itemText.startOfSelection();
+					is->set("DELETE_FRAMETEXT");
+					is->set("ETEA",  QString("delete_frametext"));
+					is->set("TEXT_STR", selectedText);
+					is->set("START", m_item->itemText.startOfSelection());
+					is->setItem(m_item->itemText.charStyle(selStart));
+					if (m_item->isNoteFrame())
+						is->set("noteframeName", m_item->getUName());
+					UndoManager::instance()->action(undoTarget, is);
+				}
+				if (repl.length() > 0)
+				{
+					int selStart = qMin(m_item->itemText.cursorPosition(), m_item->itemText.startOfSelection());
+					auto ss = new SimpleState(Um::InsertText, "", Um::ICreate);
+					ss->set("INSERT_FRAMETEXT");
+					ss->set("ETEA", QString("insert_frametext"));
+					ss->set("TEXT_STR", repl);
+					ss->set("START", selStart);
+					UndoObject * undoTarget = m_item;
+					if (m_item->isNoteFrame())
+						ss->set("noteframeName", m_item->getUName());
+					UndoManager::instance()->action(undoTarget, ss);
+				}
+			}
 			m_item->itemText.replaceSelection(repl);
 		}
 		if (RStyle->isChecked())
@@ -774,6 +811,9 @@
 			}
 		}
 		m_item->itemText.deselectAll();
+
+		if (transaction)
+			transaction.commit();
 	}
 	else if (m_doc->scMW()->CurrStED != nullptr)
 	{
@@ -849,11 +889,18 @@
 	if (m_itemMode)
 		m_doc->DoDrawing = false;
 
+	UndoTransaction undoTransaction;
+	if (m_itemMode && UndoManager::undoEnabled())
+		undoTransaction = UndoManager::instance()->beginTransaction(m_item->getUName(), m_item->getUPixmap());
+
 	do
 	{
 		doReplace();
 	}
 	while (m_found);
+
+	if (undoTransaction)
+		undoTransaction.commit();
 
 	if (m_itemMode)
 	{




More information about the scribus-commit mailing list