From a180345b169e9efea9ee2a9b106bca0914581275 Mon Sep 17 00:00:00 2001 From: mae <qt-info@nokia.com> Date: Thu, 23 Apr 2009 19:24:57 +0200 Subject: [PATCH] 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. --- src/plugins/texteditor/basetexteditor.cpp | 12 +++++++++--- src/plugins/texteditor/basetexteditor_p.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 081d343764a..7dcfcf5679c 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -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) { } diff --git a/src/plugins/texteditor/basetexteditor_p.h b/src/plugins/texteditor/basetexteditor_p.h index 9bff3da0f41..844d3777689 100644 --- a/src/plugins/texteditor/basetexteditor_p.h +++ b/src/plugins/texteditor/basetexteditor_p.h @@ -225,6 +225,7 @@ public: void clearBlockSelection(); QString copyBlockSelection(); void removeBlockSelection(const QString &text = QString()); + bool m_moveLineUndoHack; QTextCursor m_findScope; QTextCursor m_selectBlockAnchor; -- GitLab