Editor: fix selecting multiple block selections with mouse

Change-Id: I5b46adbf38358d1396ee7120558648b1375e4047
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2022-04-14 14:53:20 +02:00
parent 63702b52e2
commit 3f9c1d5d2b
3 changed files with 8 additions and 1 deletions

View File

@@ -50,6 +50,12 @@ void MultiTextCursor::addCursor(const QTextCursor &cursor)
mergeCursors(); mergeCursors();
} }
void MultiTextCursor::addCursors(const QList<QTextCursor> &cursors)
{
m_cursors.append(cursors);
mergeCursors();
}
void MultiTextCursor::setCursors(const QList<QTextCursor> &cursors) void MultiTextCursor::setCursors(const QList<QTextCursor> &cursors)
{ {
m_cursors = cursors; m_cursors = cursors;

View File

@@ -57,6 +57,7 @@ public:
/// the \param cursor that is appended by added by \brief addCursor /// the \param cursor that is appended by added by \brief addCursor
/// will be interpreted as the new main cursor /// will be interpreted as the new main cursor
void addCursor(const QTextCursor &cursor); void addCursor(const QTextCursor &cursor);
void addCursors(const QList<QTextCursor> &cursors);
/// convenience function that removes the old main cursor and appends /// convenience function that removes the old main cursor and appends
/// \param cursor as the new main cursor /// \param cursor as the new main cursor
void replaceMainCursor(const QTextCursor &cursor); void replaceMainCursor(const QTextCursor &cursor);

View File

@@ -5335,7 +5335,7 @@ void TextEditorWidget::mouseMoveEvent(QMouseEvent *e)
anchorCursor.blockNumber(), anchorCursor.blockNumber(),
anchorColumn}; anchorColumn};
cursor.setCursors(d->generateCursorsForBlockSelection(blockSelection)); cursor.addCursors(d->generateCursorsForBlockSelection(blockSelection));
if (!cursor.isNull()) if (!cursor.isNull())
setMultiTextCursor(cursor); setMultiTextCursor(cursor);
} else { } else {