diff options
author | David Schulz <david.schulz@theqtcompany.com> | 2015-04-21 12:36:11 +0200 |
---|---|---|
committer | David Schulz <david.schulz@theqtcompany.com> | 2015-05-21 07:29:55 +0000 |
commit | 7ce495876448b2438e796f2fd00a499a386ded49 (patch) | |
tree | 4af6756bf71611c673d075c93a77c7a842ac7402 | |
parent | 5fd3fa917dd9c43d49d30658dbb8276829b90326 (diff) | |
download | qt-creator-7ce495876448b2438e796f2fd00a499a386ded49.tar.gz |
Editor: Correctly unset block selection when setting a new text cursor.
Change-Id: I7d155140c55ed145cede217f3cc97064161a5a07
Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
-rw-r--r-- | src/plugins/texteditor/texteditor.cpp | 24 | ||||
-rw-r--r-- | src/plugins/texteditor/texteditor.h | 6 |
2 files changed, 14 insertions, 16 deletions
diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 8474030dc2..5c0fcbf795 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -2146,7 +2146,7 @@ void TextEditorWidget::keyPressEvent(QKeyEvent *e) && d->m_inBlockSelectionMode) { QPlainTextEdit::keyPressEvent(e); d->m_blockSelection.positionBlock = QPlainTextEdit::textCursor().blockNumber(); - setTextCursor(d->m_blockSelection.selection(d->m_document.data()), true); + doSetTextCursor(d->m_blockSelection.selection(d->m_document.data()), true); viewport()->update(); e->accept(); return; @@ -2229,7 +2229,7 @@ void TextEditorWidget::keyPressEvent(QKeyEvent *e) break; } d->resetCursorFlashTimer(); - setTextCursor(d->m_blockSelection.selection(d->m_document.data()), true); + doSetTextCursor(d->m_blockSelection.selection(d->m_document.data()), true); viewport()->update(); e->accept(); return; @@ -2417,7 +2417,7 @@ void TextEditorWidgetPrivate::universalHelper() // give it proper scrutiny before pushing it onto others. } -void TextEditorWidget::setTextCursor(const QTextCursor &cursor, bool keepBlockSelection) +void TextEditorWidget::doSetTextCursor(const QTextCursor &cursor, bool keepBlockSelection) { // workaround for QTextControl bug bool selectionChange = cursor.hasSelection() || textCursor().hasSelection(); @@ -2425,14 +2425,14 @@ void TextEditorWidget::setTextCursor(const QTextCursor &cursor, bool keepBlockSe d->disableBlockSelection(false); QTextCursor c = cursor; c.setVisualNavigation(true); - QPlainTextEdit::setTextCursor(c); + QPlainTextEdit::doSetTextCursor(c); if (selectionChange) d->slotSelectionChanged(); } -void TextEditorWidget::setTextCursor(const QTextCursor &cursor) +void TextEditorWidget::doSetTextCursor(const QTextCursor &cursor) { - setTextCursor(cursor, false); + doSetTextCursor(cursor, false); } void TextEditorWidget::gotoLine(int line, int column, bool centerLine) @@ -3303,7 +3303,7 @@ void TextEditorWidgetPrivate::insertIntoBlockSelection(const QString &text) column += textLength; m_blockSelection.fromPostition(positionBlock, column, anchorBlock, column); - q->setTextCursor(m_blockSelection.selection(m_document.data()), true); + q->doSetTextCursor(m_blockSelection.selection(m_document.data()), true); } void TextEditorWidgetPrivate::removeBlockSelection() @@ -3345,7 +3345,7 @@ void TextEditorWidgetPrivate::removeBlockSelection() cursor.endEditBlock(); m_blockSelection.fromPostition(positionBlock, firstColumn, anchorBlock, firstColumn); cursor = m_blockSelection.selection(m_document.data()); - q->setTextCursor(cursor, m_blockSelection.hasSelection()); + q->doSetTextCursor(cursor, m_blockSelection.hasSelection()); } void TextEditorWidgetPrivate::enableBlockSelection(const QTextCursor &cursor) @@ -3370,7 +3370,7 @@ void TextEditorWidgetPrivate::enableBlockSelection(int positionBlock, int positi m_blockSelection.fromPostition(positionBlock, anchorColumn, anchorBlock, positionColumn); resetCursorFlashTimer(); m_inBlockSelectionMode = true; - q->setTextCursor(m_blockSelection.selection(m_document.data()), true); + q->doSetTextCursor(m_blockSelection.selection(m_document.data()), true); q->viewport()->update(); } @@ -4771,7 +4771,7 @@ void TextEditorWidget::mouseMoveEvent(QMouseEvent *e) d->m_blockSelection.positionBlock = cursor.blockNumber(); d->m_blockSelection.positionColumn = column; - setTextCursor(d->m_blockSelection.selection(d->m_document.data()), true); + doSetTextCursor(d->m_blockSelection.selection(d->m_document.data()), true); viewport()->update(); } } else if (d->m_inBlockSelectionMode) { @@ -4812,7 +4812,7 @@ void TextEditorWidget::mousePressEvent(QMouseEvent *e) d->m_blockSelection.positionBlock = block; d->m_blockSelection.positionColumn = column; - setTextCursor(d->m_blockSelection.selection(d->m_document.data()), true); + doSetTextCursor(d->m_blockSelection.selection(d->m_document.data()), true); viewport()->update(); } else { d->enableBlockSelection(block, column, block, column); @@ -5802,7 +5802,7 @@ void TextEditorWidget::copyLine() copy(); if (!prevCursor.hasSelection()) prevCursor.movePosition(QTextCursor::StartOfBlock); - setTextCursor(prevCursor, d->m_inBlockSelectionMode); + doSetTextCursor(prevCursor, d->m_inBlockSelectionMode); } void TextEditorWidget::deleteLine() diff --git a/src/plugins/texteditor/texteditor.h b/src/plugins/texteditor/texteditor.h index 8fa094d14c..9df1fab3a4 100644 --- a/src/plugins/texteditor/texteditor.h +++ b/src/plugins/texteditor/texteditor.h @@ -284,9 +284,6 @@ public: void setReadOnly(bool b); - void setTextCursor(const QTextCursor &cursor, bool keepBlockSelection); - void setTextCursor(const QTextCursor &cursor); - void insertCodeSnippet(const QTextCursor &cursor, const QString &snippet); void setBlockSelection(bool on); @@ -605,7 +602,8 @@ protected: QPointF offset, const QRect &clip); int visibleFoldedBlockNumber() const; - + void doSetTextCursor(const QTextCursor &cursor) override; + void doSetTextCursor(const QTextCursor &cursor, bool keepBlockSelection); signals: void markRequested(TextEditor::TextEditorWidget *widget, |