From 175527299f08a82dc90b37b4c4c6713e5dd3af50 Mon Sep 17 00:00:00 2001 From: Leon Matthes Date: Thu, 5 Dec 2024 14:30:11 +0100 Subject: [PATCH] refactor!: Remove TextDocument::removeIndent Calling `indent` with negative values has exactly the same effect, so remove this duplicate function. `remove` is also not a great name for what the function did, as it didn't remove the entire indentation but rather "reduced" it. --- docs/API/knut/textdocument.md | 21 ++++----------------- src/core/textdocument.cpp | 34 +++++----------------------------- src/core/textdocument.h | 2 -- tests/tst_textdocument.cpp | 6 +++--- 4 files changed, 12 insertions(+), 51 deletions(-) diff --git a/docs/API/knut/textdocument.md b/docs/API/knut/textdocument.md index e7818ad4..131d0f89 100644 --- a/docs/API/knut/textdocument.md +++ b/docs/API/knut/textdocument.md @@ -76,8 +76,6 @@ Inherited properties: [Document properties](../knut/document.md#properties) ||**[positionAt](#positionAt)**(int line, int col)| ||**[redo](#redo)**(int count)| ||**[remove](#remove)**(int length)| -||**[removeIndent](#removeIndent)**(int count)| -||**[removeIndentAtLine](#removeIndentAtLine)**(int count, int line)| ||**[replace](#replace)**(int length, string text)| ||**[replace](#replace)**([RangeMark](../knut/rangemark.md) range, string text)| ||**[replace](#replace)**(int from, int to, string text)| @@ -316,7 +314,9 @@ Returns true if the editor has a selection. Indents the current line `count` times. If there's a selection, indent all lines in the selection. -See also: [`removeIndent`](#removeIndent), [`setIndentation`](#setIndentation). +The `count` can be negative to reduce the existing indentation. + +See also: [`setIndentation`](#setIndentation). #### **indentLine**(int count, int line) @@ -392,19 +392,6 @@ Redo `count` times the last actions. Remove `length` character from the current position. -#### **removeIndent**(int count) - -Reduce the indenation of the current line `count` times. If there's a selection, reduce indentation for all lines in -the selection. - -See also: [`indent`](#indent), [`setIndentation`](#setIndentation). - -#### **removeIndentAtLine**(int count, int line) - -Reduce the indentation of the `line` by `count` times. - -See also: [`removeIndent`](#removeIndent) - #### **replace**(int length, string text) Replaces `length` characters from the current position with the string `text`. @@ -546,7 +533,7 @@ Selects the text from the cursor position to the `mark`. Sets the absolute indentation of the current line to `indent` indentations. If there's a selection, sets the indentation of all lines in the selection. -For relative indentation, see [`indent`](#indent) and [`removeIndent`](#removeIndent). +For relative indentation, see [`indent`](#indent) and [`indentLine`](#indentLine). #### **setIndentationAtLine**(int indent, int line) diff --git a/src/core/textdocument.cpp b/src/core/textdocument.cpp index eff0439d..f4768cb3 100644 --- a/src/core/textdocument.cpp +++ b/src/core/textdocument.cpp @@ -194,7 +194,7 @@ bool TextDocument::eventFilter(QObject *watched, QEvent *event) else if (keyEvent == QKeySequence::MoveToPreviousPage) return false; else if ((keyEvent->key() == Qt::Key_Backtab)) - removeIndent(); + indent(-1); else if (keyEvent->key() == Qt::Key_Tab) indent(); else if (keyEvent == QKeySequence::Undo) @@ -1611,7 +1611,9 @@ void indentTextInTextEdit(QPlainTextEdit *textEdit, int tabCount, bool relative) * \qmlmethod TextDocument::indent(int count) * Indents the current line `count` times. If there's a selection, indent all lines in the selection. * - * See also: [`removeIndent`](#removeIndent), [`setIndentation`](#setIndentation). + * The `count` can be negative to reduce the existing indentation. + * + * See also: [`setIndentation`](#setIndentation). */ void TextDocument::indent(int count) { @@ -1632,38 +1634,12 @@ void TextDocument::indentLine(int count, int line) indentBlocksInTextEdit(m_document, line - 1, line - 1, count, true); } -/*! - * \qmlmethod TextDocument::removeIndent(int count) - * Reduce the indenation of the current line `count` times. If there's a selection, reduce indentation for all lines in - * the selection. - * - * See also: [`indent`](#indent), [`setIndentation`](#setIndentation). - */ -void TextDocument::removeIndent(int count) -{ - LOG_AND_MERGE(count); - indentTextInTextEdit(m_document, -count); -} - -/*! - * \qmlmethod TextDocument::removeIndentAtLine(int count, int line) - * Reduce the indentation of the `line` by `count` times. - * - * See also: [`removeIndent`](#removeIndent) - */ -void TextDocument::removeIndentAtLine(int count, int line) -{ - LOG(LOG_ARG("count", count), LOG_ARG("line", line)); - - indentBlocksInTextEdit(m_document, line - 1, line - 1, -count, true); -} - /*! * \qmlmethod TextDocument::setIndentation(int indent) * Sets the absolute indentation of the current line to `indent` indentations. * If there's a selection, sets the indentation of all lines in the selection. * - * For relative indentation, see [`indent`](#indent) and [`removeIndent`](#removeIndent). + * For relative indentation, see [`indent`](#indent) and [`indentLine`](#indentLine). */ void TextDocument::setIndentation(int indent) { diff --git a/src/core/textdocument.h b/src/core/textdocument.h index 9ef9aa2b..a0043582 100644 --- a/src/core/textdocument.h +++ b/src/core/textdocument.h @@ -190,8 +190,6 @@ public slots: // Indentation void indent(int count = 1); void indentLine(int count, int line); - void removeIndent(int count = 1); - void removeIndentAtLine(int count, int line); void setIndentation(int indent); void setIndentationAtLine(int indent, int line); int indentationAtPosition(int pos) const; diff --git a/tests/tst_textdocument.cpp b/tests/tst_textdocument.cpp index 2dca29f2..de566c1a 100644 --- a/tests/tst_textdocument.cpp +++ b/tests/tst_textdocument.cpp @@ -384,7 +384,7 @@ private slots: // When we remove 2 levels of indentation, that will result in 2 columns left (aka. 8 spaces). document.gotoLine(7, 4); COMPARE_CURRENT_INDENT(" \t\t\t\t", 4) - document.removeIndent(2); + document.indent(-2); COMPARE_CURRENT_INDENT(spaces(8), 2) document.gotoLine(10); @@ -393,14 +393,14 @@ private slots: document.gotoLine(16); document.selectNextLine(); - document.removeIndent(); + document.indent(-1); document.gotoLine(19); document.selectNextLine(); document.setIndentation(1); document.indentLine(2, 25); - document.removeIndentAtLine(1, 26); + document.indentLine(-1, 26); document.setIndentationAtLine(1, 28); document.save();