diff options
author | David Schulz <david.schulz@qt.io> | 2021-01-29 14:25:23 +0100 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2021-02-10 09:32:35 +0000 |
commit | 63668f8119d61dfc6470be16b7f09cdcb51dbd46 (patch) | |
tree | 46c25746f411d2be2b8b41ad9ad42b74b2cd8f95 /src/plugins/texteditor/refactoringchanges.cpp | |
parent | 4b6f1c136635c48efa021a1d413ff9fe1335920b (diff) |
TextEditor: RefactoringChanges improve readability
Change-Id: I0626f3e97eda6228130fe094c596ccbb3901b079
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins/texteditor/refactoringchanges.cpp')
-rw-r--r-- | src/plugins/texteditor/refactoringchanges.cpp | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/plugins/texteditor/refactoringchanges.cpp b/src/plugins/texteditor/refactoringchanges.cpp index f40a00c02b..9732972b01 100644 --- a/src/plugins/texteditor/refactoringchanges.cpp +++ b/src/plugins/texteditor/refactoringchanges.cpp @@ -361,8 +361,8 @@ bool RefactoringFile::apply() m_changes.apply(&c); m_changes.clear(); - indentOrReindent(&RefactoringChangesData::indentSelection, indentSelections); - indentOrReindent(&RefactoringChangesData::reindentSelection, reindentSelections); + indentOrReindent(indentSelections, Indent); + indentOrReindent(reindentSelections, Reindent); c.endEditBlock(); @@ -386,18 +386,17 @@ bool RefactoringFile::apply() return result; } -void RefactoringFile::indentOrReindent(void (RefactoringChangesData::*mf)(const QTextCursor &, - const QString &, - const TextDocument *) const, - const RefactoringSelections &ranges) +void RefactoringFile::indentOrReindent(const RefactoringSelections &ranges, + RefactoringFile::IndentType indent) { - using CursorPair = QPair<QTextCursor, QTextCursor>; - - foreach (const CursorPair &p, ranges) { - QTextCursor selection(p.first.document()); - selection.setPosition(p.first.position()); - selection.setPosition(p.second.position(), QTextCursor::KeepAnchor); - ((*m_data).*(mf))(selection, m_fileName, m_editor ? m_editor->textDocument() : nullptr); + TextDocument * document = m_editor ? m_editor->textDocument() : nullptr; + for (const auto &[position, anchor]: ranges) { + QTextCursor selection(anchor); + selection.setPosition(position.position(), QTextCursor::KeepAnchor); + if (indent == Indent) + m_data->indentSelection(selection, m_fileName, document); + else + m_data->reindentSelection(selection, m_fileName, document); } } |