diff --git a/src/document/katedocument.h b/src/document/katedocument.h --- a/src/document/katedocument.h +++ b/src/document/katedocument.h @@ -824,7 +824,9 @@ int fromVirtualColumn(int line, int column) const; int fromVirtualColumn(const KTextEditor::Cursor &) const; - void newLine(KTextEditor::ViewPrivate *view); // Changes input + enum NewLineIndent { Indent, NoIndent }; + + void newLine(KTextEditor::ViewPrivate *view, NewLineIndent indent = NewLineIndent::Indent); // Changes input void backspace(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor &); void del(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor &); void transpose(const KTextEditor::Cursor &); diff --git a/src/document/katedocument.cpp b/src/document/katedocument.cpp --- a/src/document/katedocument.cpp +++ b/src/document/katedocument.cpp @@ -3213,7 +3213,8 @@ } } -void KTextEditor::DocumentPrivate::newLine(KTextEditor::ViewPrivate *v) +void KTextEditor::DocumentPrivate::newLine(KTextEditor::ViewPrivate *v, + KTextEditor::DocumentPrivate::NewLineIndent indent) { editStart(); @@ -3247,8 +3248,10 @@ // end edit session here, to have updated HL in userTypedChar! editEnd(); - // second: indent the new line, if needed... - m_indenter->userTypedChar(v, v->cursorPosition(), QLatin1Char('\n')); + // second: if "indent" is true, indent the new line, if needed... + if (indent == KTextEditor::DocumentPrivate::Indent) { + m_indenter->userTypedChar(v, v->cursorPosition(), QLatin1Char('\n')); + } } void KTextEditor::DocumentPrivate::transpose(const KTextEditor::Cursor &cursor) diff --git a/src/view/kateview.h b/src/view/kateview.h --- a/src/view/kateview.h +++ b/src/view/kateview.h @@ -502,6 +502,14 @@ */ void smartNewline(); + /** + * Inserts a new line character at the current cursor position, with + * the newly inserted line having no indentation regardless of indentation + * settings. Useful e.g. for inserting a new, empty, line to separate + * blocks of code inside a function. + */ + void noIndentNewline(); + /** * Insert a tabulator char at current cursor position. */ diff --git a/src/view/kateview.cpp b/src/view/kateview.cpp --- a/src/view/kateview.cpp +++ b/src/view/kateview.cpp @@ -1154,6 +1154,16 @@ connect(a, SIGNAL(triggered(bool)), SLOT(smartNewline())); m_editActions << a; + a = ac->addAction(QStringLiteral("no_indent_newline")); + a->setText(i18n("Insert a non-indented Newline")); + a->setWhatsThis(i18n("Insert a new line without indentation, regardless of indentation settings.")); + scuts.clear(); + scuts << QKeySequence(Qt::CTRL + Qt::Key_Return) + << QKeySequence(Qt::CTRL + Qt::Key_Enter); + ac->setDefaultShortcuts(a, scuts); + connect(a, SIGNAL(triggered(bool)), SLOT(noIndentNewline())); + m_editActions << a; + a = ac->addAction(QStringLiteral("tools_indent")); a->setIcon(QIcon::fromTheme(QStringLiteral("format-indent-more"))); a->setText(i18n("&Indent")); @@ -2865,6 +2875,13 @@ m_viewInternal->updateView(); } +void KTextEditor::ViewPrivate::noIndentNewline() +{ + doc()->newLine(this, KTextEditor::DocumentPrivate::NoIndent); + m_viewInternal->iconBorder()->updateForCursorLineChange(); + m_viewInternal->updateView(); +} + void KTextEditor::ViewPrivate::backspace() { doc()->backspace(this, cursorPosition());