diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2023-11-20 11:28:41 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2023-11-22 13:47:16 +0000 |
commit | 240748c106678218d7ed85e3a7a2d79db099b0e6 (patch) | |
tree | 4e872d9f67ddd6e18b0bc38e11a841b92bcb9f97 /src/plugins/qmljstools | |
parent | 2bd02671d81dd550881cc7384d9bdf9d2bde4394 (diff) |
TextEditor: Get rid of extra indent ranges in RefactoringFile
Having extra indent regions complicates the interface, the
implementation and the calling code.
Instead, derive the indent regions from the change set and let callers
opt out for the relatively few cases where indentation is not desired.
Change-Id: I49d2854830a51778534ef260fb5c9f2c7685554a
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/qmljstools')
-rw-r--r-- | src/plugins/qmljstools/qmljsrefactoringchanges.cpp | 41 | ||||
-rw-r--r-- | src/plugins/qmljstools/qmljsrefactoringchanges.h | 5 |
2 files changed, 5 insertions, 41 deletions
diff --git a/src/plugins/qmljstools/qmljsrefactoringchanges.cpp b/src/plugins/qmljstools/qmljsrefactoringchanges.cpp index ddc2ca25c83..fea9c5d87a5 100644 --- a/src/plugins/qmljstools/qmljsrefactoringchanges.cpp +++ b/src/plugins/qmljstools/qmljsrefactoringchanges.cpp @@ -2,9 +2,11 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "qmljsrefactoringchanges.h" + #include "qmljsqtstylecodeformatter.h" #include "qmljsmodelmanager.h" #include "qmljsindenter.h" +#include "qmljstoolsconstants.h" #include <qmljs/parser/qmljsast_p.h> #include <texteditor/textdocument.h> @@ -139,44 +141,9 @@ void QmlJSRefactoringFile::fileChanged() m_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 +Utils::Id QmlJSRefactoringFile::indenterId() const { - const TextEditor::TabSettings &tabSettings = - ProjectExplorer::actualTabSettings(filePath(), textDocument); - - QmlJSEditor::Internal::Indenter indenter(selection.document()); - indenter.reindent(selection, tabSettings); + return Constants::QML_JS_SETTINGS_ID; } } // namespace QmlJSTools diff --git a/src/plugins/qmljstools/qmljsrefactoringchanges.h b/src/plugins/qmljstools/qmljsrefactoringchanges.h index 56051d4dfa3..a5b995c0ea1 100644 --- a/src/plugins/qmljstools/qmljsrefactoringchanges.h +++ b/src/plugins/qmljstools/qmljsrefactoringchanges.h @@ -40,10 +40,7 @@ private: QmlJSRefactoringFile(TextEditor::TextEditorWidget *editor, QmlJS::Document::Ptr document); 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; + Utils::Id indenterId() const override; mutable QmlJS::Document::Ptr m_qmljsDocument; QSharedPointer<QmlJSRefactoringChangesData> m_data; |