forked from qt-creator/qt-creator
Editor: add formatter support
Change-Id: I65590273b2541e08a39970cd9bb4739a5634b2f7 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -349,24 +349,6 @@ Utils::Text::Replacements utf16Replacements(const QTextDocument *doc,
|
||||
return convertedReplacements;
|
||||
}
|
||||
|
||||
void applyReplacements(QTextDocument *doc, const Utils::Text::Replacements &replacements)
|
||||
{
|
||||
if (replacements.empty())
|
||||
return;
|
||||
|
||||
int fullOffsetShift = 0;
|
||||
QTextCursor editCursor(doc);
|
||||
for (const Utils::Text::Replacement &replacement : replacements) {
|
||||
editCursor.setPosition(replacement.offset + fullOffsetShift);
|
||||
editCursor.movePosition(QTextCursor::NextCharacter,
|
||||
QTextCursor::KeepAnchor,
|
||||
replacement.length);
|
||||
editCursor.removeSelectedText();
|
||||
editCursor.insertText(replacement.text);
|
||||
fullOffsetShift += replacement.text.length() - replacement.length;
|
||||
}
|
||||
}
|
||||
|
||||
QString selectedLines(QTextDocument *doc, const QTextBlock &startBlock, const QTextBlock &endBlock)
|
||||
{
|
||||
return Utils::Text::textAt(QTextCursor(doc),
|
||||
@@ -554,7 +536,7 @@ Utils::Text::Replacements ClangFormatBaseIndenter::format(
|
||||
clangReplacements = clangReplacements.merge(formatReplacements);
|
||||
|
||||
const Utils::Text::Replacements toReplace = utf16Replacements(m_doc, buffer, clangReplacements);
|
||||
applyReplacements(m_doc, toReplace);
|
||||
Utils::Text::applyReplacements(m_doc, toReplace);
|
||||
|
||||
return toReplace;
|
||||
}
|
||||
|
||||
@@ -287,7 +287,7 @@ void ClangFormatConfigWidget::updatePreview()
|
||||
QTextCursor cursor(m_preview->document());
|
||||
cursor.setPosition(0);
|
||||
cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
|
||||
m_preview->textDocument()->autoFormatOrIndent(cursor);
|
||||
m_preview->textDocument()->autoIndent(cursor);
|
||||
}
|
||||
|
||||
static inline void ltrim(std::string &s)
|
||||
|
||||
Reference in New Issue
Block a user