From 518f32a70d3e9eb869d4a19c6fef50b91475a60a Mon Sep 17 00:00:00 2001 From: Thomas Zander Date: Mon, 16 Nov 2009 11:16:47 +0100 Subject: Fix regression in emitting of QTextDocument::undoCommandAdded() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test I wrote was not testing if calling undo/redo had any effect on emitting undoCommandAdded(), added these test cases and fixed the QTextDocumentPrivate::endEditBlock so we now again emit only when an undo command is added, not also on calling undo or redo. Reviewed-by: mae Reviewed-by: Samuel Rødal (cherry picked from commit 7e1f19c3e3036f166a84dbaa916ec1da1cc818c6) --- src/gui/text/qtextdocument_p.cpp | 4 +++- tests/auto/qtextdocument/tst_qtextdocument.cpp | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/gui/text/qtextdocument_p.cpp b/src/gui/text/qtextdocument_p.cpp index 2ad6512..18e1ffc 100644 --- a/src/gui/text/qtextdocument_p.cpp +++ b/src/gui/text/qtextdocument_p.cpp @@ -1114,9 +1114,11 @@ void QTextDocumentPrivate::endEditBlock() return; if (undoEnabled && undoState > 0) { + const bool wasBlocking = !undoStack[undoState - 1].block_end; if (undoStack[undoState - 1].block_part) { undoStack[undoState - 1].block_end = true; - emit document()->undoCommandAdded(); + if (wasBlocking) + emit document()->undoCommandAdded(); } } diff --git a/tests/auto/qtextdocument/tst_qtextdocument.cpp b/tests/auto/qtextdocument/tst_qtextdocument.cpp index 1d54409..11e32b0 100644 --- a/tests/auto/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/qtextdocument/tst_qtextdocument.cpp @@ -2615,6 +2615,17 @@ void tst_QTextDocument::testUndoCommandAdded() cf.setFontItalic(true); cursor.mergeCharFormat(cf); QCOMPARE(spy.count(), 1); + + spy.clear(); + doc->undo(); + QCOMPARE(spy.count(), 0); + doc->undo(); + QCOMPARE(spy.count(), 0); + spy.clear(); + doc->redo(); + QCOMPARE(spy.count(), 0); + doc->redo(); + QCOMPARE(spy.count(), 0); } void tst_QTextDocument::testUndoBlocks() -- cgit v0.12