diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index 7c1b72423437db7f9ede7d18bb387ad106c7eb7b..6a7b725e59267559f82baa4772a154f77bb5e40d 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -882,17 +882,17 @@ void BaseTextEditor::joinLines()
     QTextCursor move = textCursor();
     move.beginEditBlock();
 
-    move.movePosition(QTextCursor::Down);
+    move.movePosition(QTextCursor::NextBlock);
     move.movePosition(QTextCursor::StartOfBlock);
     move.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
     QString cutLine = move.selectedText();
 
-    // collapse trailing whitespaces to one or insert whitespace
+    // Collapse leading whitespaces to one or insert whitespace
     cutLine.replace(QRegExp("^\\s*"), " ");
     move.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
     move.removeSelectedText();
 
-    move.movePosition(QTextCursor::Up);
+    move.movePosition(QTextCursor::PreviousBlock);
     move.movePosition(QTextCursor::EndOfBlock);
 
     move.insertText(cutLine);