summaryrefslogtreecommitdiff
path: root/src/plugins/texteditor
diff options
context:
space:
mode:
authorIvan Donchevskii <ivan.donchevskii@qt.io>2019-01-28 07:54:05 +0100
committerIvan Donchevskii <ivan.donchevskii@qt.io>2019-01-31 10:25:05 +0000
commit80fb0178fdd9ee82acfb22aa512c7514868e89d1 (patch)
tree7cb0a4670571ccb4183ad9b8ce6bf939a99172cc /src/plugins/texteditor
parent9d046826f87c1971f4104ca5fc86ef58250168c5 (diff)
downloadqt-creator-80fb0178fdd9ee82acfb22aa512c7514868e89d1.tar.gz
ClangFormat: Introduce check to format code instead of indenting
Ctrl+I with the new check will reformat the selected code or the current line instead. Change-Id: Ia5a72c4a09621034d0dfe463f669fe1ca36b0b5f Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io> Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Diffstat (limited to 'src/plugins/texteditor')
-rw-r--r--src/plugins/texteditor/indenter.h18
-rw-r--r--src/plugins/texteditor/textdocument.cpp4
-rw-r--r--src/plugins/texteditor/textdocument.h2
-rw-r--r--src/plugins/texteditor/texteditor.cpp12
-rw-r--r--src/plugins/texteditor/textindenter.cpp6
-rw-r--r--src/plugins/texteditor/textindenter.h1
6 files changed, 19 insertions, 24 deletions
diff --git a/src/plugins/texteditor/indenter.h b/src/plugins/texteditor/indenter.h
index 5b4b97fbfa..a9fb5de7cd 100644
--- a/src/plugins/texteditor/indenter.h
+++ b/src/plugins/texteditor/indenter.h
@@ -81,6 +81,21 @@ public:
return -1;
}
+ virtual void formatOrIndent(const QTextCursor &cursor,
+ const TabSettings &tabSettings,
+ int /*cursorPositionInEditor*/ = -1)
+ {
+ indent(cursor, QChar::Null, tabSettings);
+ }
+
+ // By default just calls indent with default settings.
+ virtual Replacements format(const QTextCursor &cursor,
+ const TabSettings &tabSettings)
+ {
+ indent(cursor, QChar::Null, tabSettings);
+ return Replacements();
+ }
+
// Expects a list of blocks in order of occurrence in the document.
virtual IndentationForBlock indentationForBlocks(const QVector<QTextBlock> &blocks,
const TabSettings & /*tabSettings*/)
@@ -99,9 +114,6 @@ public:
const TabSettings &tabSettings)
= 0;
- // By default just calls indent with default settings.
- virtual Replacements format(const QTextCursor &cursor, const TabSettings &tabSettings) = 0;
-
// Reindent at cursor. Selection will be adjusted according to the indentation
// change of the first block.
virtual void reindent(const QTextCursor &cursor, const TabSettings &tabSettings) = 0;
diff --git a/src/plugins/texteditor/textdocument.cpp b/src/plugins/texteditor/textdocument.cpp
index 352c609143..d96b463cd4 100644
--- a/src/plugins/texteditor/textdocument.cpp
+++ b/src/plugins/texteditor/textdocument.cpp
@@ -422,9 +422,9 @@ void TextDocument::autoReindent(const QTextCursor &cursor)
d->m_indenter->reindent(cursor, tabSettings());
}
-void TextDocument::autoFormat(const QTextCursor &cursor)
+void TextDocument::autoFormatOrIndent(const QTextCursor &cursor)
{
- d->m_indenter->format(cursor, tabSettings());
+ d->m_indenter->formatOrIndent(cursor, tabSettings());
}
QTextCursor TextDocument::indent(const QTextCursor &cursor, bool blockSelection, int column,
diff --git a/src/plugins/texteditor/textdocument.h b/src/plugins/texteditor/textdocument.h
index eaa102ec74..f71922f2d2 100644
--- a/src/plugins/texteditor/textdocument.h
+++ b/src/plugins/texteditor/textdocument.h
@@ -89,7 +89,7 @@ public:
Indenter *indenter() const;
void autoIndent(const QTextCursor &cursor, QChar typedChar = QChar::Null);
void autoReindent(const QTextCursor &cursor);
- void autoFormat(const QTextCursor &cursor);
+ void autoFormatOrIndent(const QTextCursor &cursor);
QTextCursor indent(const QTextCursor &cursor, bool blockSelection = false, int column = 0,
int *offset = nullptr);
QTextCursor unindent(const QTextCursor &cursor, bool blockSelection = false, int column = 0,
diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp
index 872c139b69..7907259306 100644
--- a/src/plugins/texteditor/texteditor.cpp
+++ b/src/plugins/texteditor/texteditor.cpp
@@ -7135,21 +7135,11 @@ void TextEditorWidget::setIfdefedOutBlocks(const QList<BlockRange> &blocks)
documentLayout->requestUpdate();
}
-static bool applyFormattingInsteadOfIndentation()
-{
- constexpr const char option[] = "QTC_FORMAT_INSTEAD_OF_INDENT";
- return qEnvironmentVariableIsSet(option);
-}
-
void TextEditorWidget::format()
{
- static bool formattingInsteadOfIndentation = applyFormattingInsteadOfIndentation();
QTextCursor cursor = textCursor();
cursor.beginEditBlock();
- if (formattingInsteadOfIndentation)
- d->m_document->autoFormat(cursor);
- else
- d->m_document->autoIndent(cursor);
+ d->m_document->autoFormatOrIndent(cursor);
cursor.endEditBlock();
}
diff --git a/src/plugins/texteditor/textindenter.cpp b/src/plugins/texteditor/textindenter.cpp
index bca7b1ae18..53801fabfa 100644
--- a/src/plugins/texteditor/textindenter.cpp
+++ b/src/plugins/texteditor/textindenter.cpp
@@ -102,12 +102,6 @@ void TextIndenter::reindent(const QTextCursor &cursor, const TabSettings &tabSet
}
}
-Replacements TextIndenter::format(const QTextCursor &cursor, const TabSettings &tabSettings)
-{
- indent(cursor, QChar::Null, tabSettings);
- return Replacements();
-}
-
Utils::optional<TabSettings> TextIndenter::tabSettings() const
{
return Utils::optional<TabSettings>();
diff --git a/src/plugins/texteditor/textindenter.h b/src/plugins/texteditor/textindenter.h
index 8a87b9214d..51be65f409 100644
--- a/src/plugins/texteditor/textindenter.h
+++ b/src/plugins/texteditor/textindenter.h
@@ -54,7 +54,6 @@ public:
const QChar &typedChar,
const TabSettings &tabSettings) override;
- Replacements format(const QTextCursor &cursor, const TabSettings &tabSettings) override;
void reindent(const QTextCursor &cursor, const TabSettings &tabSettings) override;
Utils::optional<TabSettings> tabSettings() const override;