diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 18547bb8794..bcb02ca444a 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -882,6 +882,29 @@ void BaseTextEditor::joinLines() setTextCursor(cursor); } +void BaseTextEditor::insertLineAbove() +{ + QTextCursor cursor = textCursor(); + cursor.beginEditBlock(); + cursor.movePosition(QTextCursor::PreviousBlock, QTextCursor::MoveAnchor); + cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::MoveAnchor); + cursor.insertBlock(); + indent(document(), cursor, QChar::Null); + cursor.endEditBlock(); + setTextCursor(cursor); +} + +void BaseTextEditor::insertLineBelow() +{ + QTextCursor cursor = textCursor(); + cursor.beginEditBlock(); + cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::MoveAnchor); + cursor.insertBlock(); + indent(document(), cursor, QChar::Null); + cursor.endEditBlock(); + setTextCursor(cursor); +} + void BaseTextEditor::moveLineUp() { moveLineUpDown(true); diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h index 67ef63858d6..af067e777e4 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -242,6 +242,9 @@ public slots: void joinLines(); + void insertLineAbove(); + void insertLineBelow(); + void cleanWhitespace(); signals: diff --git a/src/plugins/texteditor/texteditoractionhandler.cpp b/src/plugins/texteditor/texteditoractionhandler.cpp index d08912fe9d7..19e9438f5ec 100644 --- a/src/plugins/texteditor/texteditoractionhandler.cpp +++ b/src/plugins/texteditor/texteditoractionhandler.cpp @@ -292,6 +292,16 @@ void TextEditorActionHandler::createActions() command = am->registerAction(m_joinLinesAction, Constants::JOIN_LINES, m_contextId); command->setDefaultKeySequence(QKeySequence(tr("Ctrl+J"))); connect(m_joinLinesAction, SIGNAL(triggered()), this, SLOT(joinLines())); + + m_insertLineAboveAction = new QAction(tr("Insert Line Above Current Line"), this); + command = am->registerAction(m_insertLineAboveAction, Constants::INSERT_LINE_ABOVE, m_contextId); + command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+Return"))); + connect(m_insertLineAboveAction, SIGNAL(triggered()), this, SLOT(insertLineAbove())); + + m_insertLineBelowAction = new QAction(tr("Insert Line Below Current Line"), this); + command = am->registerAction(m_insertLineBelowAction, Constants::INSERT_LINE_BELOW, m_contextId); + command->setDefaultKeySequence(QKeySequence(tr("Shift+Return"))); + connect(m_insertLineBelowAction, SIGNAL(triggered()), this, SLOT(insertLineBelow())); } bool TextEditorActionHandler::supportsAction(const QString & /*id */) const @@ -454,6 +464,8 @@ FUNCTION(moveLineDown) FUNCTION(copyLineUp) FUNCTION(copyLineDown) FUNCTION(joinLines) +FUNCTION(insertLineAbove) +FUNCTION(insertLineBelow) void TextEditorActionHandler::updateCurrentEditor(Core::IEditor *editor) { diff --git a/src/plugins/texteditor/texteditoractionhandler.h b/src/plugins/texteditor/texteditoractionhandler.h index 2b8b7a039c0..c747bc30fdb 100644 --- a/src/plugins/texteditor/texteditoractionhandler.h +++ b/src/plugins/texteditor/texteditoractionhandler.h @@ -116,6 +116,8 @@ private slots: void copyLineUp(); void copyLineDown(); void joinLines(); + void insertLineAbove(); + void insertLineBelow(); void updateCurrentEditor(Core::IEditor *editor); private: @@ -153,6 +155,8 @@ private: QAction *m_copyLineUpAction; QAction *m_copyLineDownAction; QAction *m_joinLinesAction; + QAction *m_insertLineAboveAction; + QAction *m_insertLineBelowAction; uint m_optionalActions; QPointer m_currentEditor; diff --git a/src/plugins/texteditor/texteditorconstants.h b/src/plugins/texteditor/texteditorconstants.h index 7fc41a9f888..2a27a67296d 100644 --- a/src/plugins/texteditor/texteditorconstants.h +++ b/src/plugins/texteditor/texteditorconstants.h @@ -61,6 +61,8 @@ const char * const MOVE_LINE_DOWN = "TextEditor.MoveLineDown"; const char * const COPY_LINE_UP = "TextEditor.CopyLineUp"; const char * const COPY_LINE_DOWN = "TextEditor.CopyLineDown"; const char * const JOIN_LINES = "TextEditor.JoinLines"; +const char * const INSERT_LINE_ABOVE = "TextEditor.InsertLineAboveCurrentLine"; +const char * const INSERT_LINE_BELOW = "TextEditor.InsertLineBelowCurrentLine"; const char * const CUT_LINE = "TextEditor.CutLine"; const char * const DELETE_LINE = "TextEditor.DeleteLine"; const char * const DELETE_WORD = "TextEditor.DeleteWord";