forked from qt-creator/qt-creator
make move line up/down only move the selected line if the end of the selection
is at the beginning of the next block. Join the undo commands for subsequent moves.
This commit is contained in:
@@ -714,6 +714,9 @@ void BaseTextEditor::moveLineUpDown(bool up)
|
|||||||
{
|
{
|
||||||
QTextCursor cursor = textCursor();
|
QTextCursor cursor = textCursor();
|
||||||
QTextCursor move = cursor;
|
QTextCursor move = cursor;
|
||||||
|
if (d->m_moveLineUndoHack)
|
||||||
|
move.joinPreviousEditBlock();
|
||||||
|
else
|
||||||
move.beginEditBlock();
|
move.beginEditBlock();
|
||||||
|
|
||||||
bool hasSelection = cursor.hasSelection();
|
bool hasSelection = cursor.hasSelection();
|
||||||
@@ -722,7 +725,7 @@ void BaseTextEditor::moveLineUpDown(bool up)
|
|||||||
move.setPosition(cursor.selectionStart());
|
move.setPosition(cursor.selectionStart());
|
||||||
move.movePosition(QTextCursor::StartOfBlock);
|
move.movePosition(QTextCursor::StartOfBlock);
|
||||||
move.setPosition(cursor.selectionEnd(), QTextCursor::KeepAnchor);
|
move.setPosition(cursor.selectionEnd(), QTextCursor::KeepAnchor);
|
||||||
move.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
|
move.movePosition(move.atBlockStart() ? QTextCursor::Left: QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
|
||||||
} else {
|
} else {
|
||||||
move.movePosition(QTextCursor::StartOfBlock);
|
move.movePosition(QTextCursor::StartOfBlock);
|
||||||
move.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
|
move.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
|
||||||
@@ -760,6 +763,7 @@ void BaseTextEditor::moveLineUpDown(bool up)
|
|||||||
move.endEditBlock();
|
move.endEditBlock();
|
||||||
|
|
||||||
setTextCursor(move);
|
setTextCursor(move);
|
||||||
|
d->m_moveLineUndoHack = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseTextEditor::cleanWhitespace()
|
void BaseTextEditor::cleanWhitespace()
|
||||||
@@ -769,6 +773,7 @@ void BaseTextEditor::cleanWhitespace()
|
|||||||
|
|
||||||
void BaseTextEditor::keyPressEvent(QKeyEvent *e)
|
void BaseTextEditor::keyPressEvent(QKeyEvent *e)
|
||||||
{
|
{
|
||||||
|
d->m_moveLineUndoHack = false;
|
||||||
d->clearVisibleCollapsedBlock();
|
d->clearVisibleCollapsedBlock();
|
||||||
|
|
||||||
QKeyEvent *original_e = e;
|
QKeyEvent *original_e = e;
|
||||||
@@ -1305,7 +1310,8 @@ BaseTextEditorPrivate::BaseTextEditorPrivate()
|
|||||||
m_actionHack(0),
|
m_actionHack(0),
|
||||||
m_inBlockSelectionMode(false),
|
m_inBlockSelectionMode(false),
|
||||||
m_lastEventWasBlockSelectionEvent(false),
|
m_lastEventWasBlockSelectionEvent(false),
|
||||||
m_blockSelectionExtraX(0)
|
m_blockSelectionExtraX(0),
|
||||||
|
m_moveLineUndoHack(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -225,6 +225,7 @@ public:
|
|||||||
void clearBlockSelection();
|
void clearBlockSelection();
|
||||||
QString copyBlockSelection();
|
QString copyBlockSelection();
|
||||||
void removeBlockSelection(const QString &text = QString());
|
void removeBlockSelection(const QString &text = QString());
|
||||||
|
bool m_moveLineUndoHack;
|
||||||
|
|
||||||
QTextCursor m_findScope;
|
QTextCursor m_findScope;
|
||||||
QTextCursor m_selectBlockAnchor;
|
QTextCursor m_selectBlockAnchor;
|
||||||
|
Reference in New Issue
Block a user