diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2023-11-16 16:09:26 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2023-11-17 09:43:02 +0000 |
commit | 6f3bc431fc5a0bcde258f53d8c6e1d2d5ad80539 (patch) | |
tree | 82467a5b2270342371850832c3b1fba3ea12c0b4 /src/plugins/qmljstools | |
parent | 4c0abb6d2c93704a1909b3f24dfb02c0e191fd31 (diff) |
TextEditor: Move more code into RefactoringFile
We want to get rid of RefactoringChangesData.
Change-Id: Ia428563a0ff70ec9660761beac3eb7168b8e9eca
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/qmljstools')
-rw-r--r-- | src/plugins/qmljstools/qmljsrefactoringchanges.cpp | 90 | ||||
-rw-r--r-- | src/plugins/qmljstools/qmljsrefactoringchanges.h | 7 |
2 files changed, 48 insertions, 49 deletions
diff --git a/src/plugins/qmljstools/qmljsrefactoringchanges.cpp b/src/plugins/qmljstools/qmljsrefactoringchanges.cpp index 67ab64858e7..24bd14f52b0 100644 --- a/src/plugins/qmljstools/qmljsrefactoringchanges.cpp +++ b/src/plugins/qmljstools/qmljsrefactoringchanges.cpp @@ -24,53 +24,6 @@ public: , m_snapshot(snapshot) {} - void indentSelection(const QTextCursor &selection, - const Utils::FilePath &filePath, - const TextEditor::TextDocument *textDocument) const override - { - // ### shares code with QmlJSTextEditor::indent - QTextDocument *doc = selection.document(); - - QTextBlock block = doc->findBlock(selection.selectionStart()); - const QTextBlock end = doc->findBlock(selection.selectionEnd()).next(); - - const TextEditor::TabSettings &tabSettings = - ProjectExplorer::actualTabSettings(filePath, textDocument); - CreatorCodeFormatter codeFormatter(tabSettings); - codeFormatter.updateStateUntil(block); - do { - int depth = codeFormatter.indentFor(block); - if (depth != -1) { - if (QStringView(block.text()).trimmed().isEmpty()) { - // we do not want to indent empty lines (as one is indentent when pressing tab - // assuming that the user will start writing something), and get rid of that - // space if one had pressed tab in an empty line just before refactoring. - // If depth == -1 (inside a multiline string for example) leave the spaces. - depth = 0; - } - tabSettings.indentLine(block, depth); - } - codeFormatter.updateLineStateChange(block); - block = block.next(); - } while (block.isValid() && block != end); - } - - void reindentSelection(const QTextCursor &selection, - const Utils::FilePath &filePath, - const TextEditor::TextDocument *textDocument) const override - { - const TextEditor::TabSettings &tabSettings = - ProjectExplorer::actualTabSettings(filePath, textDocument); - - QmlJSEditor::Internal::Indenter indenter(selection.document()); - indenter.reindent(selection, tabSettings); - } - - void fileChanged(const Utils::FilePath &filePath) override - { - m_modelManager->updateSourceFiles({filePath}, true); - } - ModelManagerInterface *m_modelManager; Snapshot m_snapshot; }; @@ -193,8 +146,49 @@ QmlJSRefactoringChangesData *QmlJSRefactoringFile::data() const void QmlJSRefactoringFile::fileChanged() { + QTC_ASSERT(!m_filePath.isEmpty(), return); m_qmljsDocument.clear(); - RefactoringFile::fileChanged(); + data()->m_modelManager->updateSourceFiles({filePath()}, true); +} + +void QmlJSRefactoringFile::indentSelection(const QTextCursor &selection, + const TextEditor::TextDocument *textDocument) const +{ + // ### shares code with QmlJSTextEditor::indent + QTextDocument *doc = selection.document(); + + QTextBlock block = doc->findBlock(selection.selectionStart()); + const QTextBlock end = doc->findBlock(selection.selectionEnd()).next(); + + const TextEditor::TabSettings &tabSettings = + ProjectExplorer::actualTabSettings(filePath(), textDocument); + CreatorCodeFormatter codeFormatter(tabSettings); + codeFormatter.updateStateUntil(block); + do { + int depth = codeFormatter.indentFor(block); + if (depth != -1) { + if (QStringView(block.text()).trimmed().isEmpty()) { + // we do not want to indent empty lines (as one is indentent when pressing tab + // assuming that the user will start writing something), and get rid of that + // space if one had pressed tab in an empty line just before refactoring. + // If depth == -1 (inside a multiline string for example) leave the spaces. + depth = 0; + } + tabSettings.indentLine(block, depth); + } + codeFormatter.updateLineStateChange(block); + block = block.next(); + } while (block.isValid() && block != end); +} + +void QmlJSRefactoringFile::reindentSelection(const QTextCursor &selection, + const TextEditor::TextDocument *textDocument) const +{ + const TextEditor::TabSettings &tabSettings = + ProjectExplorer::actualTabSettings(filePath(), textDocument); + + QmlJSEditor::Internal::Indenter indenter(selection.document()); + indenter.reindent(selection, tabSettings); } } // namespace QmlJSTools diff --git a/src/plugins/qmljstools/qmljsrefactoringchanges.h b/src/plugins/qmljstools/qmljsrefactoringchanges.h index fa4e381edd7..8c5cf8501ae 100644 --- a/src/plugins/qmljstools/qmljsrefactoringchanges.h +++ b/src/plugins/qmljstools/qmljsrefactoringchanges.h @@ -34,13 +34,18 @@ public: bool isCursorOn(QmlJS::AST::UiQualifiedId *ast) const; bool isCursorOn(QmlJS::SourceLocation loc) const; -protected: +private: QmlJSRefactoringFile(const Utils::FilePath &filePath, const QSharedPointer<TextEditor::RefactoringChangesData> &data); QmlJSRefactoringFile(TextEditor::TextEditorWidget *editor, QmlJS::Document::Ptr document); QmlJSRefactoringChangesData *data() const; + void fileChanged() override; + void indentSelection(const QTextCursor &selection, + const TextEditor::TextDocument *textDocument) const override; + void reindentSelection(const QTextCursor &selection, + const TextEditor::TextDocument *textDocument) const override; mutable QmlJS::Document::Ptr m_qmljsDocument; |