summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/widgets/qlinecontrol.cpp7
-rw-r--r--tests/auto/qlineedit/tst_qlineedit.cpp38
2 files changed, 44 insertions, 1 deletions
diff --git a/src/gui/widgets/qlinecontrol.cpp b/src/gui/widgets/qlinecontrol.cpp
index 300a2ea..334a925 100644
--- a/src/gui/widgets/qlinecontrol.cpp
+++ b/src/gui/widgets/qlinecontrol.cpp
@@ -138,7 +138,12 @@ void QLineControl::copy(QClipboard::Mode mode) const
*/
void QLineControl::paste()
{
- insert(QApplication::clipboard()->text(QClipboard::Clipboard));
+ QString clip = QApplication::clipboard()->text(QClipboard::Clipboard);
+ if (!clip.isEmpty() || hasSelectedText()) {
+ separate(); //make it a separate undo/redo command
+ insert(clip);
+ separate();
+ }
}
#endif // !QT_NO_CLIPBOARD
diff --git a/tests/auto/qlineedit/tst_qlineedit.cpp b/tests/auto/qlineedit/tst_qlineedit.cpp
index b4dfbba..dd5bb29 100644
--- a/tests/auto/qlineedit/tst_qlineedit.cpp
+++ b/tests/auto/qlineedit/tst_qlineedit.cpp
@@ -51,6 +51,10 @@
#include "qcompleter.h"
#include "qstandarditemmodel.h"
+#ifndef QT_NO_CLIPBOARD
+#include "qclipboard.h"
+#endif
+
#ifdef Q_WS_MAC
#include <Carbon/Carbon.h> // For the random function.
#include <cstdlib> // For the random function.
@@ -157,6 +161,10 @@ private slots:
void undo_keypressevents_data();
void undo_keypressevents();
+#ifndef QT_NO_CLIPBOARD
+ void QTBUG5786_undoPaste();
+#endif
+
void clear();
void text_data();
@@ -1406,6 +1414,36 @@ void tst_QLineEdit::undo_keypressevents()
QVERIFY(testWidget->text().isEmpty());
}
+#ifndef QT_NO_CLIPBOARD
+void tst_QLineEdit::QTBUG5786_undoPaste()
+{
+ QString initial("initial");
+ QString string("test");
+ QString additional("add");
+ QApplication::clipboard()->setText(string);
+ QLineEdit edit(initial);
+ QCOMPARE(edit.text(), initial);
+ edit.paste();
+ QCOMPARE(edit.text(), initial + string);
+ edit.paste();
+ QCOMPARE(edit.text(), initial + string + string);
+ edit.insert(additional);
+ QCOMPARE(edit.text(), initial + string + string + additional);
+ edit.undo();
+ QCOMPARE(edit.text(), initial + string + string);
+ edit.undo();
+ QCOMPARE(edit.text(), initial + string);
+ edit.undo();
+ QCOMPARE(edit.text(), initial);
+ edit.selectAll();
+ QApplication::clipboard()->setText(QString());
+ edit.paste();
+ QVERIFY(edit.text().isEmpty());
+
+}
+#endif
+
+
void tst_QLineEdit::clear()
{
// checking that clear of empty/nullstring doesn't add to undo history