Commit a180345b authored by mae's avatar mae

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.
parent 341d8d56
......@@ -714,7 +714,10 @@ void BaseTextEditor::moveLineUpDown(bool up)
{
QTextCursor cursor = textCursor();
QTextCursor move = cursor;
move.beginEditBlock();
if (d->m_moveLineUndoHack)
move.joinPreviousEditBlock();
else
move.beginEditBlock();
bool hasSelection = cursor.hasSelection();
......@@ -722,7 +725,7 @@ void BaseTextEditor::moveLineUpDown(bool up)
move.setPosition(cursor.selectionStart());
move.movePosition(QTextCursor::StartOfBlock);
move.setPosition(cursor.selectionEnd(), QTextCursor::KeepAnchor);
move.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
move.movePosition(move.atBlockStart() ? QTextCursor::Left: QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
} else {
move.movePosition(QTextCursor::StartOfBlock);
move.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
......@@ -760,6 +763,7 @@ void BaseTextEditor::moveLineUpDown(bool up)
move.endEditBlock();
setTextCursor(move);
d->m_moveLineUndoHack = true;
}
void BaseTextEditor::cleanWhitespace()
......@@ -769,6 +773,7 @@ void BaseTextEditor::cleanWhitespace()
void BaseTextEditor::keyPressEvent(QKeyEvent *e)
{
d->m_moveLineUndoHack = false;
d->clearVisibleCollapsedBlock();
QKeyEvent *original_e = e;
......@@ -1305,7 +1310,8 @@ BaseTextEditorPrivate::BaseTextEditorPrivate()
m_actionHack(0),
m_inBlockSelectionMode(false),
m_lastEventWasBlockSelectionEvent(false),
m_blockSelectionExtraX(0)
m_blockSelectionExtraX(0),
m_moveLineUndoHack(false)
{
}
......
......@@ -225,6 +225,7 @@ public:
void clearBlockSelection();
QString copyBlockSelection();
void removeBlockSelection(const QString &text = QString());
bool m_moveLineUndoHack;
QTextCursor m_findScope;
QTextCursor m_selectBlockAnchor;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment