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:
mae
2009-04-23 19:24:57 +02:00
parent 341d8d5622
commit a180345b16
2 changed files with 10 additions and 3 deletions

View File

@@ -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)
{
}

View File

@@ -225,6 +225,7 @@ public:
void clearBlockSelection();
QString copyBlockSelection();
void removeBlockSelection(const QString &text = QString());
bool m_moveLineUndoHack;
QTextCursor m_findScope;
QTextCursor m_selectBlockAnchor;