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:
Ivan Donchevskii
2019-01-28 08:11:20 +01:00
parent 80fb0178fd
commit 1dee275f58
24 changed files with 185 additions and 95 deletions

View File

@@ -53,7 +53,8 @@ bool Indenter::isElectricCharacter(const QChar &ch) const
void Indenter::indentBlock(const QTextBlock &block,
const QChar &typedChar,
const TextEditor::TabSettings &tabSettings)
const TextEditor::TabSettings &tabSettings,
int /*cursorPositionInEditor*/)
{
const int depth = indentFor(block, tabSettings);
if (depth == -1)
@@ -79,7 +80,9 @@ void Indenter::invalidateCache()
codeFormatter.invalidateCache(m_doc);
}
int Indenter::indentFor(const QTextBlock &block, const TextEditor::TabSettings &tabSettings)
int Indenter::indentFor(const QTextBlock &block,
const TextEditor::TabSettings &tabSettings,
int /*cursorPositionInEditor*/)
{
QmlJSTools::CreatorCodeFormatter codeFormatter(tabSettings);
codeFormatter.updateStateUntil(block);
@@ -87,7 +90,9 @@ int Indenter::indentFor(const QTextBlock &block, const TextEditor::TabSettings &
}
TextEditor::IndentationForBlock Indenter::indentationForBlocks(
const QVector<QTextBlock> &blocks, const TextEditor::TabSettings &tabSettings)
const QVector<QTextBlock> &blocks,
const TextEditor::TabSettings &tabSettings,
int /*cursorPositionInEditor*/)
{
QmlJSTools::CreatorCodeFormatter codeFormatter(tabSettings);

View File

@@ -41,12 +41,16 @@ 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 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;
};
} // Internal