From e2370578275fde45b010c1adad4b713a4ba39e02 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Thu, 22 Nov 2012 11:40:06 +0100 Subject: [PATCH] Make insertLineAbove behaviour consistent when at top of document. Currently, pressing Ctrl+Shift+Enter to insert a line above the current line does not work consistently when the current line is the first in the document. For example, if the cursor (|) is not on the first line: 1. #include 2.|#include becomes 1. #include 2.| 3. #include after Ctrl+Shift+Enter. When the cursor is on the first line, however: 1.|#include 2. #include becomes 1. #include 2.| 3. #include after Ctrl+Shift+Enter. This patch corrects the above result: 1. | 2. #include 3. #include This is also in line with Eclipse's behaviour, for example. Change-Id: I542050b6090ed0cfdf613bf67bbd2651eb99ec9d Reviewed-by: David Schulz --- src/plugins/texteditor/basetexteditor.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index e876c6fc3ca..faa74f49124 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -1015,9 +1015,11 @@ void BaseTextEditorWidget::insertLineAbove() { QTextCursor cursor = textCursor(); cursor.beginEditBlock(); - cursor.movePosition(QTextCursor::PreviousBlock, QTextCursor::MoveAnchor); - cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::MoveAnchor); + // If the cursor is at the beginning of the document, + // it should still insert a line above the current line. + cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor); cursor.insertBlock(); + cursor.movePosition(QTextCursor::PreviousBlock, QTextCursor::MoveAnchor); indent(document(), cursor, QChar::Null); cursor.endEditBlock(); setTextCursor(cursor);