forked from qt-creator/qt-creator
ClangFormat: Add cursor position to the indenter interface
Sometimes it's imnportant where the cursor currently is to properly format the code without affecting the current line. Change-Id: I8b1fb11d2303adb5f960c7cb80a0ed2e6e45010f Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io> Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
@@ -93,7 +93,8 @@ static bool isElectricInLine(const QChar ch, const QString &text)
|
||||
|
||||
void CppQtStyleIndenter::indentBlock(const QTextBlock &block,
|
||||
const QChar &typedChar,
|
||||
const TextEditor::TabSettings &tabSettings)
|
||||
const TextEditor::TabSettings &tabSettings,
|
||||
int /*cursorPositionInEditor*/)
|
||||
{
|
||||
QtStyleCodeFormatter codeFormatter(tabSettings, codeStyleSettings());
|
||||
|
||||
@@ -121,7 +122,8 @@ void CppQtStyleIndenter::indentBlock(const QTextBlock &block,
|
||||
|
||||
void CppQtStyleIndenter::indent(const QTextCursor &cursor,
|
||||
const QChar &typedChar,
|
||||
const TextEditor::TabSettings &tabSettings)
|
||||
const TextEditor::TabSettings &tabSettings,
|
||||
int /*cursorPositionInEditor*/)
|
||||
{
|
||||
if (cursor.hasSelection()) {
|
||||
QTextBlock block = m_doc->findBlock(cursor.selectionStart());
|
||||
@@ -160,7 +162,8 @@ void CppQtStyleIndenter::invalidateCache()
|
||||
}
|
||||
|
||||
int CppQtStyleIndenter::indentFor(const QTextBlock &block,
|
||||
const TextEditor::TabSettings &tabSettings)
|
||||
const TextEditor::TabSettings &tabSettings,
|
||||
int /*cursorPositionInEditor*/)
|
||||
{
|
||||
QtStyleCodeFormatter codeFormatter(tabSettings, codeStyleSettings());
|
||||
|
||||
@@ -180,7 +183,9 @@ CppCodeStyleSettings CppQtStyleIndenter::codeStyleSettings() const
|
||||
}
|
||||
|
||||
TextEditor::IndentationForBlock CppQtStyleIndenter::indentationForBlocks(
|
||||
const QVector<QTextBlock> &blocks, const TextEditor::TabSettings &tabSettings)
|
||||
const QVector<QTextBlock> &blocks,
|
||||
const TextEditor::TabSettings &tabSettings,
|
||||
int /*cursorPositionInEditor*/)
|
||||
{
|
||||
QtStyleCodeFormatter codeFormatter(tabSettings, codeStyleSettings());
|
||||
|
||||
|
||||
@@ -46,17 +46,22 @@ public:
|
||||
bool isElectricCharacter(const QChar &ch) const override;
|
||||
void indentBlock(const QTextBlock &block,
|
||||
const QChar &typedChar,
|
||||
const TextEditor::TabSettings &tabSettings) override;
|
||||
const TextEditor::TabSettings &tabSettings,
|
||||
int cursorPositionInEditor = -1) override;
|
||||
|
||||
void indent(const QTextCursor &cursor,
|
||||
const QChar &typedChar,
|
||||
const TextEditor::TabSettings &tabSettings) override;
|
||||
const TextEditor::TabSettings &tabSettings,
|
||||
int cursorPositionInEditor = -1) override;
|
||||
|
||||
void setCodeStylePreferences(TextEditor::ICodeStylePreferences *preferences) override;
|
||||
void invalidateCache() override;
|
||||
int indentFor(const QTextBlock &block, const TextEditor::TabSettings &tabSettings) override;
|
||||
TextEditor::IndentationForBlock indentationForBlocks(
|
||||
const QVector<QTextBlock> &blocks, const TextEditor::TabSettings &tabSettings) override;
|
||||
int indentFor(const QTextBlock &block,
|
||||
const TextEditor::TabSettings &tabSettings,
|
||||
int cursorPositionInEditor = -1) override;
|
||||
TextEditor::IndentationForBlock indentationForBlocks(const QVector<QTextBlock> &blocks,
|
||||
const TextEditor::TabSettings &tabSettings,
|
||||
int cursorPositionInEditor = -1) override;
|
||||
|
||||
private:
|
||||
CppCodeStyleSettings codeStyleSettings() const;
|
||||
|
||||
Reference in New Issue
Block a user