From bd34df230da21154536cdc7c2886206bb53d2a78 Mon Sep 17 00:00:00 2001 From: Pekka Vuorela Date: Thu, 6 Oct 2011 15:10:24 +0300 Subject: QTextEdit - Fix selectionChange emission bug QTextEdit did not emit selectionChange signal if selection availability did not change, but the start or end of the selection did. This was causing unit test to fail. Change-Id: Iea0cb0bae767bc8d2dd36141362f9a084af97266 Reviewed-on: http://codereview.qt-project.org/6426 Sanity-Review: Qt Sanity Bot Reviewed-by: Joona Petrell Reviewed-by: Lars Knoll --- src/widgets/widgets/qwidgettextcontrol.cpp | 23 +++++++++++++++++------ src/widgets/widgets/qwidgettextcontrol_p_p.h | 3 ++- 2 files changed, 19 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index 346499c26f..68dad9fe7a 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -119,7 +119,8 @@ QWidgetTextControlPrivate::QWidgetTextControlPrivate() #ifndef QT_NO_DRAGANDDROP mousePressed(false), mightStartDrag(false), #endif - lastSelectionState(false), ignoreAutomaticScrollbarAdjustement(false), + lastSelectionPosition(0), lastSelectionAnchor(0), + ignoreAutomaticScrollbarAdjustement(false), overwriteMode(false), acceptRichText(true), preeditCursor(0), hideCursor(false), @@ -577,15 +578,25 @@ void QWidgetTextControlPrivate::selectionChanged(bool forceEmitSelectionChanged if (forceEmitSelectionChanged) emit q->selectionChanged(); - bool current = cursor.hasSelection(); - if (current == lastSelectionState) + if (cursor.position() == lastSelectionPosition + && cursor.anchor() == lastSelectionAnchor) return; - lastSelectionState = current; - emit q->copyAvailable(current); - if (!forceEmitSelectionChanged) + bool selectionStateChange = (cursor.hasSelection() + != (lastSelectionPosition != lastSelectionAnchor)); + if (selectionStateChange) + emit q->copyAvailable(cursor.hasSelection()); + + if (!forceEmitSelectionChanged + && (selectionStateChange + || (cursor.hasSelection() + && (cursor.position() != lastSelectionPosition + || cursor.anchor() != lastSelectionAnchor)))) emit q->selectionChanged(); + emit q->microFocusChanged(); + lastSelectionPosition = cursor.position(); + lastSelectionAnchor = cursor.anchor(); } void QWidgetTextControlPrivate::_q_updateCurrentCharFormatAndSelection() diff --git a/src/widgets/widgets/qwidgettextcontrol_p_p.h b/src/widgets/widgets/qwidgettextcontrol_p_p.h index 8943bb70cf..0f163d7e04 100644 --- a/src/widgets/widgets/qwidgettextcontrol_p_p.h +++ b/src/widgets/widgets/qwidgettextcontrol_p_p.h @@ -193,7 +193,8 @@ public: QPoint dragStartPos; QPointer contextWidget; - bool lastSelectionState; + int lastSelectionPosition; + int lastSelectionAnchor; bool ignoreAutomaticScrollbarAdjustement; -- cgit v1.2.3