aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmljstools
diff options
context:
space:
mode:
authorFawzi Mohamed <fawzi.mohamed@qt.io>2020-08-01 02:20:32 +0200
committerFawzi Mohamed <fawzi.mohamed@qt.io>2020-09-30 08:32:38 +0000
commit103b35bcd5a393dcd9febff6bfcbfb9ec96ca040 (patch)
treec05485f4240eb54983be8ef28198a944c81496c7 /src/plugins/qmljstools
parenteddf2bead8c4c4d6358bf8b29190e8acea254a29 (diff)
qml: fix refactoring to separate component
* avoid extra spaces * warn about existing files Fixes: QTCREATORBUG-21091 Change-Id: Ic9ed4444bd028455e1b2d1755e6c43f352dfd5e3 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/plugins/qmljstools')
-rw-r--r--src/plugins/qmljstools/qmljsrefactoringchanges.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/plugins/qmljstools/qmljsrefactoringchanges.cpp b/src/plugins/qmljstools/qmljsrefactoringchanges.cpp
index 2cb21f4f555..85202d46559 100644
--- a/src/plugins/qmljstools/qmljsrefactoringchanges.cpp
+++ b/src/plugins/qmljstools/qmljsrefactoringchanges.cpp
@@ -60,11 +60,18 @@ public:
ProjectExplorer::actualTabSettings(fileName, textDocument);
CreatorCodeFormatter codeFormatter(tabSettings);
codeFormatter.updateStateUntil(block);
-
do {
- const int depth = codeFormatter.indentFor(block);
- if (depth != -1)
+ 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);