forked from qt-creator/qt-creator
Editor: Avoid setting text cursor when clearing block selection
Task-number: QTCREATORBUG-17475 Change-Id: I0266530c8c2ba10bd14dcb26b946cc51a825600f Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -423,7 +423,13 @@ public:
|
||||
void enableBlockSelection(const QTextCursor &cursor);
|
||||
void enableBlockSelection(int positionBlock, int positionColumn,
|
||||
int anchorBlock, int anchorColumn);
|
||||
void disableBlockSelection(bool keepSelection = true);
|
||||
|
||||
enum BlockSelectionUpdateKind {
|
||||
NoCursorUpdate,
|
||||
CursorUpdateKeepSelection,
|
||||
CursorUpdateClearSelection,
|
||||
};
|
||||
void disableBlockSelection(BlockSelectionUpdateKind kind);
|
||||
void resetCursorFlashTimer();
|
||||
QBasicTimer m_cursorFlashTimer;
|
||||
bool m_cursorVisible;
|
||||
@@ -1469,7 +1475,7 @@ void TextEditorWidget::insertLineAbove()
|
||||
void TextEditorWidget::insertLineBelow()
|
||||
{
|
||||
if (d->m_inBlockSelectionMode)
|
||||
d->disableBlockSelection(false);
|
||||
d->disableBlockSelection(TextEditorWidgetPrivate::NoCursorUpdate);
|
||||
QTextCursor cursor = textCursor();
|
||||
cursor.beginEditBlock();
|
||||
cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::MoveAnchor);
|
||||
@@ -1526,14 +1532,14 @@ void TextEditorWidget::unindent()
|
||||
void TextEditorWidget::undo()
|
||||
{
|
||||
if (d->m_inBlockSelectionMode)
|
||||
d->disableBlockSelection(false);
|
||||
d->disableBlockSelection(TextEditorWidgetPrivate::CursorUpdateClearSelection);
|
||||
QPlainTextEdit::undo();
|
||||
}
|
||||
|
||||
void TextEditorWidget::redo()
|
||||
{
|
||||
if (d->m_inBlockSelectionMode)
|
||||
d->disableBlockSelection(false);
|
||||
d->disableBlockSelection(TextEditorWidgetPrivate::CursorUpdateClearSelection);
|
||||
QPlainTextEdit::redo();
|
||||
}
|
||||
|
||||
@@ -1572,7 +1578,7 @@ void TextEditorWidgetPrivate::moveLineUpDown(bool up)
|
||||
|
||||
if (hasSelection) {
|
||||
if (m_inBlockSelectionMode)
|
||||
disableBlockSelection(true);
|
||||
disableBlockSelection(NoCursorUpdate);
|
||||
move.setPosition(cursor.selectionStart());
|
||||
move.movePosition(QTextCursor::StartOfBlock);
|
||||
move.setPosition(cursor.selectionEnd(), QTextCursor::KeepAnchor);
|
||||
@@ -2114,7 +2120,7 @@ void TextEditorWidget::keyPressEvent(QKeyEvent *e)
|
||||
&& (e == QKeySequence::InsertParagraphSeparator
|
||||
|| (!d->m_lineSeparatorsAllowed && e == QKeySequence::InsertLineSeparator))) {
|
||||
if (d->m_inBlockSelectionMode) {
|
||||
d->disableBlockSelection(false);
|
||||
d->disableBlockSelection(TextEditorWidgetPrivate::CursorUpdateClearSelection);
|
||||
e->accept();
|
||||
return;
|
||||
}
|
||||
@@ -2241,7 +2247,7 @@ void TextEditorWidget::keyPressEvent(QKeyEvent *e)
|
||||
return;
|
||||
} else if (!ro && (e == QKeySequence::MoveToNextPage || e == QKeySequence::MoveToPreviousPage)
|
||||
&& d->m_inBlockSelectionMode) {
|
||||
d->disableBlockSelection(false);
|
||||
d->disableBlockSelection(TextEditorWidgetPrivate::CursorUpdateClearSelection);
|
||||
QPlainTextEdit::keyPressEvent(e);
|
||||
return;
|
||||
} else if (!ro && (e == QKeySequence::SelectNextPage || e == QKeySequence::SelectPreviousPage)
|
||||
@@ -2341,7 +2347,7 @@ void TextEditorWidget::keyPressEvent(QKeyEvent *e)
|
||||
e->accept();
|
||||
return;
|
||||
} else if (d->m_inBlockSelectionMode) { // leave block selection mode
|
||||
d->disableBlockSelection();
|
||||
d->disableBlockSelection(TextEditorWidgetPrivate::NoCursorUpdate);
|
||||
}
|
||||
break;
|
||||
case Qt::Key_Insert:
|
||||
@@ -2528,7 +2534,7 @@ void TextEditorWidget::doSetTextCursor(const QTextCursor &cursor, bool keepBlock
|
||||
// workaround for QTextControl bug
|
||||
bool selectionChange = cursor.hasSelection() || textCursor().hasSelection();
|
||||
if (!keepBlockSelection && d->m_inBlockSelectionMode)
|
||||
d->disableBlockSelection(false);
|
||||
d->disableBlockSelection(TextEditorWidgetPrivate::NoCursorUpdate);
|
||||
QTextCursor c = cursor;
|
||||
c.setVisualNavigation(true);
|
||||
QPlainTextEdit::doSetTextCursor(c);
|
||||
@@ -3502,15 +3508,17 @@ void TextEditorWidgetPrivate::enableBlockSelection(int positionBlock, int positi
|
||||
q->viewport()->update();
|
||||
}
|
||||
|
||||
void TextEditorWidgetPrivate::disableBlockSelection(bool keepSelection)
|
||||
void TextEditorWidgetPrivate::disableBlockSelection(BlockSelectionUpdateKind kind)
|
||||
{
|
||||
m_inBlockSelectionMode = false;
|
||||
m_cursorFlashTimer.stop();
|
||||
if (kind != NoCursorUpdate) {
|
||||
QTextCursor cursor = m_blockSelection.selection(m_document.data());
|
||||
m_blockSelection.clear();
|
||||
if (!keepSelection)
|
||||
if (kind == CursorUpdateClearSelection)
|
||||
cursor.clearSelection();
|
||||
q->setTextCursor(cursor);
|
||||
}
|
||||
m_blockSelection.clear();
|
||||
q->viewport()->update();
|
||||
}
|
||||
|
||||
@@ -4879,7 +4887,7 @@ void TextEditorWidget::mouseMoveEvent(QMouseEvent *e)
|
||||
viewport()->update();
|
||||
}
|
||||
} else if (d->m_inBlockSelectionMode) {
|
||||
d->disableBlockSelection();
|
||||
d->disableBlockSelection(TextEditorWidgetPrivate::CursorUpdateKeepSelection);
|
||||
}
|
||||
}
|
||||
if (viewport()->cursor().shape() == Qt::BlankCursor)
|
||||
@@ -4923,7 +4931,7 @@ void TextEditorWidget::mousePressEvent(QMouseEvent *e)
|
||||
}
|
||||
} else {
|
||||
if (d->m_inBlockSelectionMode)
|
||||
d->disableBlockSelection(false); // just in case, otherwise we might get strange drag and drop
|
||||
d->disableBlockSelection(TextEditorWidgetPrivate::NoCursorUpdate);
|
||||
|
||||
QTextBlock foldedBlock = d->foldedBlockAt(e->pos());
|
||||
if (foldedBlock.isValid()) {
|
||||
@@ -6680,7 +6688,7 @@ void TextEditorWidget::cut()
|
||||
void TextEditorWidget::selectAll()
|
||||
{
|
||||
if (d->m_inBlockSelectionMode)
|
||||
d->disableBlockSelection();
|
||||
d->disableBlockSelection(TextEditorWidgetPrivate::NoCursorUpdate);
|
||||
QPlainTextEdit::selectAll();
|
||||
}
|
||||
|
||||
@@ -7139,7 +7147,8 @@ void BaseTextEditor::setCursorPosition(int pos)
|
||||
|
||||
void TextEditorWidget::setCursorPosition(int pos)
|
||||
{
|
||||
setBlockSelection(false);
|
||||
if (d->m_inBlockSelectionMode)
|
||||
d->disableBlockSelection(TextEditorWidgetPrivate::NoCursorUpdate);
|
||||
QTextCursor tc = textCursor();
|
||||
tc.setPosition(pos);
|
||||
setTextCursor(tc);
|
||||
@@ -7316,7 +7325,7 @@ void TextEditorWidget::setBlockSelection(bool on)
|
||||
if (on)
|
||||
d->enableBlockSelection(textCursor());
|
||||
else
|
||||
d->disableBlockSelection(false);
|
||||
d->disableBlockSelection(TextEditorWidgetPrivate::CursorUpdateClearSelection);
|
||||
}
|
||||
|
||||
void TextEditorWidget::setBlockSelection(int positionBlock, int positionColumn,
|
||||
|
Reference in New Issue
Block a user