TextEditor: RefactoringChanges improve readability

Change-Id: I0626f3e97eda6228130fe094c596ccbb3901b079
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2021-01-29 14:25:23 +01:00
parent 4b6f1c1366
commit 63668f8119
2 changed files with 14 additions and 17 deletions

View File

@@ -361,8 +361,8 @@ bool RefactoringFile::apply()
m_changes.apply(&c); m_changes.apply(&c);
m_changes.clear(); m_changes.clear();
indentOrReindent(&RefactoringChangesData::indentSelection, indentSelections); indentOrReindent(indentSelections, Indent);
indentOrReindent(&RefactoringChangesData::reindentSelection, reindentSelections); indentOrReindent(reindentSelections, Reindent);
c.endEditBlock(); c.endEditBlock();
@@ -386,18 +386,17 @@ bool RefactoringFile::apply()
return result; return result;
} }
void RefactoringFile::indentOrReindent(void (RefactoringChangesData::*mf)(const QTextCursor &, void RefactoringFile::indentOrReindent(const RefactoringSelections &ranges,
const QString &, RefactoringFile::IndentType indent)
const TextDocument *) const,
const RefactoringSelections &ranges)
{ {
using CursorPair = QPair<QTextCursor, QTextCursor>; TextDocument * document = m_editor ? m_editor->textDocument() : nullptr;
for (const auto &[position, anchor]: ranges) {
foreach (const CursorPair &p, ranges) { QTextCursor selection(anchor);
QTextCursor selection(p.first.document()); selection.setPosition(position.position(), QTextCursor::KeepAnchor);
selection.setPosition(p.first.position()); if (indent == Indent)
selection.setPosition(p.second.position(), QTextCursor::KeepAnchor); m_data->indentSelection(selection, m_fileName, document);
((*m_data).*(mf))(selection, m_fileName, m_editor ? m_editor->textDocument() : nullptr); else
m_data->reindentSelection(selection, m_fileName, document);
} }
} }

View File

@@ -93,10 +93,8 @@ protected:
// derived classes may want to clear language specific extra data // derived classes may want to clear language specific extra data
virtual void fileChanged(); virtual void fileChanged();
void indentOrReindent(void (RefactoringChangesData::*mf)(const QTextCursor &, enum IndentType {Indent, Reindent};
const QString &, void indentOrReindent(const RefactoringSelections &ranges, IndentType indent);
const TextDocument *) const,
const RefactoringSelections &ranges);
protected: protected:
QString m_fileName; QString m_fileName;