aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/texteditor/refactoringchanges.cpp
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2023-11-17 12:31:43 +0100
committerChristian Kandeler <christian.kandeler@qt.io>2023-11-20 11:56:47 +0000
commitf163a4f9a194abeb10021a6d6706275d57b01261 (patch)
tree3aa7adc152b322741a27daf56d7d6d1c04307b3b /src/plugins/texteditor/refactoringchanges.cpp
parent1dafa53b3bca031e99ddd925e9712723dc4fe323 (diff)
TextEditor: Move more code out of RefactoringChanges
The only callers are in RefactoringFile, so put the functions there. Change-Id: I94141d759d32c20a334804e98dfeb262e10c5e11 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/texteditor/refactoringchanges.cpp')
-rw-r--r--src/plugins/texteditor/refactoringchanges.cpp84
1 files changed, 40 insertions, 44 deletions
diff --git a/src/plugins/texteditor/refactoringchanges.cpp b/src/plugins/texteditor/refactoringchanges.cpp
index 4391822d9c..cfbfe58d3b 100644
--- a/src/plugins/texteditor/refactoringchanges.cpp
+++ b/src/plugins/texteditor/refactoringchanges.cpp
@@ -28,23 +28,6 @@ namespace TextEditor {
RefactoringChanges::~RefactoringChanges() = default;
-RefactoringSelections RefactoringChanges::rangesToSelections(QTextDocument *document,
- const QList<Range> &ranges)
-{
- RefactoringSelections selections;
-
- for (const Range &range : ranges) {
- QTextCursor start(document);
- start.setPosition(range.start);
- start.setKeepPositionOnInsert(true);
- QTextCursor end(document);
- end.setPosition(qMin(range.end, document->characterCount() - 1));
- selections.push_back({start, end});
- }
-
- return selections;
-}
-
bool RefactoringChanges::createFile(const FilePath &filePath,
const QString &contents,
bool reindent,
@@ -53,25 +36,6 @@ bool RefactoringChanges::createFile(const FilePath &filePath,
return file(filePath)->create(contents, reindent, openEditor);
}
-TextEditorWidget *RefactoringChanges::openEditor(const FilePath &filePath,
- bool activate,
- int line,
- int column)
-{
- EditorManager::OpenEditorFlags flags = EditorManager::IgnoreNavigationHistory;
- if (activate)
- flags |= EditorManager::SwitchSplitIfAlreadyVisible;
- else
- flags |= EditorManager::DoNotChangeCurrentEditor;
- if (line != -1) {
- // openEditorAt uses a 1-based line and a 0-based column!
- column -= 1;
- }
- IEditor *editor = EditorManager::openEditorAt(Link{filePath, line, column}, Id(), flags);
-
- return TextEditorWidget::fromEditor(editor);
-}
-
RefactoringFilePtr RefactoringChanges::file(const FilePath &filePath) const
{
return RefactoringFilePtr(new RefactoringFile(filePath));
@@ -97,7 +61,7 @@ RefactoringFile::RefactoringFile(const FilePath &filePath) : m_filePath(filePath
}
}
-bool RefactoringFile::create(const QString &contents, bool reindent, bool openEditor)
+bool RefactoringFile::create(const QString &contents, bool reindent, bool openInEditor)
{
if (m_filePath.isEmpty() || m_filePath.exists() || m_editor)
return false;
@@ -126,8 +90,8 @@ bool RefactoringFile::create(const QString &contents, bool reindent, bool openEd
fileChanged();
- if (openEditor)
- RefactoringChanges::openEditor(m_filePath, /*bool activate =*/ false, -1, -1);
+ if (openInEditor)
+ openEditor(/*bool activate =*/ false, -1, -1);
return true;
}
@@ -290,7 +254,7 @@ bool RefactoringFile::apply()
lineAndColumn(m_editorCursorPosition, &line, &column);
ensureCursorVisible = true;
}
- m_editor = RefactoringChanges::openEditor(m_filePath, m_activateEditor, line, column);
+ m_editor = openEditor(m_activateEditor, line, column);
m_openEditor = false;
m_activateEditor = false;
m_editorCursorPosition = -1;
@@ -313,11 +277,10 @@ bool RefactoringFile::apply()
sort(m_reindentRanges);
// build indent selections now, applying the changeset will change locations
- const RefactoringSelections &indentSelections =
- RefactoringChanges::rangesToSelections(doc, m_indentRanges);
+ const RefactoringSelections &indentSelections = rangesToSelections(doc, m_indentRanges);
m_indentRanges.clear();
- const RefactoringSelections &reindentSelections =
- RefactoringChanges::rangesToSelections(doc, m_reindentRanges);
+ const RefactoringSelections &reindentSelections
+ = rangesToSelections(doc, m_reindentRanges);
m_reindentRanges.clear();
// apply changes
@@ -486,4 +449,37 @@ void RefactoringFile::reindentSelection(const QTextCursor &selection,
Q_UNUSED(textDocument)
}
+TextEditorWidget *RefactoringFile::openEditor(bool activate, int line, int column)
+{
+ EditorManager::OpenEditorFlags flags = EditorManager::IgnoreNavigationHistory;
+ if (activate)
+ flags |= EditorManager::SwitchSplitIfAlreadyVisible;
+ else
+ flags |= EditorManager::DoNotChangeCurrentEditor;
+ if (line != -1) {
+ // openEditorAt uses a 1-based line and a 0-based column!
+ column -= 1;
+ }
+ IEditor *editor = EditorManager::openEditorAt(Link{m_filePath, line, column}, Id(), flags);
+
+ return TextEditorWidget::fromEditor(editor);
+}
+
+RefactoringSelections RefactoringFile::rangesToSelections(QTextDocument *document,
+ const QList<Range> &ranges)
+{
+ RefactoringSelections selections;
+
+ for (const Range &range : ranges) {
+ QTextCursor start(document);
+ start.setPosition(range.start);
+ start.setKeepPositionOnInsert(true);
+ QTextCursor end(document);
+ end.setPosition(qMin(range.end, document->characterCount() - 1));
+ selections.push_back({start, end});
+ }
+
+ return selections;
+}
+
} // namespace TextEditor