diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp
index a2d766effc0ba48bf7d21abe4d6ee9738f316503..448ab814864baeaa522d1b0926053b997d739716 100644
--- a/src/plugins/cppeditor/cppeditor.cpp
+++ b/src/plugins/cppeditor/cppeditor.cpp
@@ -1512,14 +1512,9 @@ bool CPPEditor::isInComment(const QTextCursor &cursor) const
     return false;
 }
 
-void CPPEditor::indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar)
+static CppTools::QtStyleCodeFormatter setupCodeFormatter(const TextEditor::TabSettings &ts)
 {
-    Q_UNUSED(doc)
-    Q_UNUSED(typedChar)
-
-    const TabSettings &ts = tabSettings();
     CppTools::QtStyleCodeFormatter codeFormatter;
-
     codeFormatter.setIndentSize(ts.m_indentSize);
     codeFormatter.setTabSize(ts.m_tabSize);
     if (ts.m_indentBraces && ts.m_doubleIndentBlocks) { // gnu style
@@ -1538,12 +1533,46 @@ void CPPEditor::indentBlock(QTextDocument *doc, QTextBlock block, QChar typedCha
         codeFormatter.setIndentDeclarationBraces(false);
         codeFormatter.setIndentDeclarationMembers(true);
     }
+    return codeFormatter;
+}
+
+void CPPEditor::indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar)
+{
+    Q_UNUSED(doc)
+    Q_UNUSED(typedChar)
+
+    const TabSettings &ts = tabSettings();
+    CppTools::QtStyleCodeFormatter codeFormatter = setupCodeFormatter(ts);
 
     codeFormatter.updateStateUntil(block);
     const int depth = codeFormatter.indentFor(block);
     ts.indentLine(block, depth);
 }
 
+void CPPEditor::indent(QTextDocument *doc, const QTextCursor &cursor, QChar typedChar)
+{
+    Q_UNUSED(doc)
+    Q_UNUSED(typedChar)
+
+    maybeClearSomeExtraSelections(cursor);
+    if (cursor.hasSelection()) {
+        QTextBlock block = doc->findBlock(cursor.selectionStart());
+        const QTextBlock end = doc->findBlock(cursor.selectionEnd()).next();
+
+        const TabSettings &ts = tabSettings();
+        CppTools::QtStyleCodeFormatter codeFormatter = setupCodeFormatter(ts);
+        codeFormatter.updateStateUntil(block);
+
+        do {
+            ts.indentLine(block, codeFormatter.indentFor(block));
+            codeFormatter.updateLineStateChange(block);
+            block = block.next();
+        } while (block.isValid() && block != end);
+    } else {
+        indentBlock(doc, cursor.block(), typedChar);
+    }
+}
+
 bool CPPEditor::event(QEvent *e)
 {
     switch (e->type()) {
diff --git a/src/plugins/cppeditor/cppeditor.h b/src/plugins/cppeditor/cppeditor.h
index a6b991b81ce2adcb5e6d91ad4a9a1f637a1995bc..488bcfd9e275f61b429f230e03c415967844a375 100644
--- a/src/plugins/cppeditor/cppeditor.h
+++ b/src/plugins/cppeditor/cppeditor.h
@@ -237,6 +237,7 @@ private:
     bool sortedMethodOverview() const;
     CPlusPlus::Symbol *findDefinition(CPlusPlus::Symbol *symbol, const CPlusPlus::Snapshot &snapshot);
     virtual void indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar);
+    virtual void indent(QTextDocument *doc, const QTextCursor &cursor, QChar typedChar);
 
     TextEditor::ITextEditor *openCppEditorAt(const QString &fileName, int line,
                                              int column = 0);
diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h
index a2b8c72b2683861e77edef2ddb17c81668472816..087d67e642f3373e6bfeecd505af51f9083add8a 100644
--- a/src/plugins/texteditor/basetexteditor.h
+++ b/src/plugins/texteditor/basetexteditor.h
@@ -476,6 +476,8 @@ protected:
      */
     virtual bool openLink(const Link &link);
 
+    void maybeClearSomeExtraSelections(const QTextCursor &cursor);
+
 protected slots:
     virtual void slotUpdateExtraAreaWidth();
     virtual void slotModificationChanged(bool);
@@ -500,8 +502,6 @@ private:
     void updateHighlights();
     void updateCurrentLineHighlight();
 
-    void maybeClearSomeExtraSelections(const QTextCursor &cursor);
-
     void drawFoldingMarker(QPainter *painter, const QPalette &pal,
                            const QRect &rect,
                            bool expanded,