forked from qt-creator/qt-creator
Utils: sort the cursor before copying or inserting text
The user shouldn't care about the order of the individual cursors inside the MultiTextCursor, so the order of selected texts should always be the same as in the document. Fixes: QTCREATORBUG-26494 Change-Id: I0d5199bda4e48f8482e20018b8f05020e16da3f6 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -125,7 +125,9 @@ bool MultiTextCursor::hasSelection() const
|
||||
QString MultiTextCursor::selectedText() const
|
||||
{
|
||||
QString text;
|
||||
for (const QTextCursor &cursor : m_cursors) {
|
||||
QList<QTextCursor> cursors = m_cursors;
|
||||
Utils::sort(cursors);
|
||||
for (const QTextCursor &cursor : cursors) {
|
||||
const QString &cursorText = cursor.selectedText();
|
||||
if (cursorText.isEmpty())
|
||||
continue;
|
||||
@@ -169,7 +171,9 @@ void MultiTextCursor::insertText(const QString &text, bool selectNewText)
|
||||
lines.pop_back();
|
||||
int index = 0;
|
||||
if (lines.count() == m_cursors.count()) {
|
||||
for (QTextCursor &cursor : m_cursors)
|
||||
QList<QTextCursor> cursors = m_cursors;
|
||||
Utils::sort(cursors);
|
||||
for (QTextCursor &cursor : cursors)
|
||||
insertAndSelect(cursor, lines.at(index++), selectNewText);
|
||||
m_cursors.last().endEditBlock();
|
||||
return;
|
||||
|
Reference in New Issue
Block a user