QmlDesigner: Do not jump to EOF

Task-number: QDS-739
Change-Id: I8594e30aad20494d89c748e7f848180bc9af862d
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Thomas Hartmann
2019-08-19 11:35:53 +02:00
parent 7393305b31
commit d83243fbe6

View File

@@ -969,13 +969,13 @@ void RewriterView::delayedSetup()
static QString annotationsEnd() static QString annotationsEnd()
{ {
const static QString end = QString(" %1*/").arg(annotationsEscapeSequence); const static QString end = QString("%1*/").arg(annotationsEscapeSequence);
return end; return end;
} }
static QString annotationsStart() static QString annotationsStart()
{ {
const static QString start = QString("/*%1 ").arg(annotationsEscapeSequence); const static QString start = QString("/*%1").arg(annotationsEscapeSequence);
return start; return start;
} }
@@ -1000,29 +1000,27 @@ void RewriterView::writeAuxiliaryData()
const QString oldText = m_textModifier->text(); const QString oldText = m_textModifier->text();
QString newText = oldText; const int startIndex = oldText.indexOf(annotationsStart());
const int endIndex = oldText.indexOf(annotationsEnd());
int startIndex = newText.indexOf(annotationsStart());
int endIndex = newText.indexOf(annotationsEnd());
if (startIndex > 0 && endIndex > 0)
newText.remove(startIndex, endIndex - startIndex + annotationsEnd().length());
newText = newText.trimmed();
newText.append("\n");
QString auxData = auxiliaryDataAsQML(); QString auxData = auxiliaryDataAsQML();
const bool replace = startIndex > 0 && endIndex > 0;
if (!auxData.isEmpty()) { if (!auxData.isEmpty()) {
auxData.prepend("\n" + annotationsStart()); auxData.prepend("\n");
auxData.append(annotationsEnd() + "\n"); auxData.prepend(annotationsStart());
newText.append(auxData); if (!replace)
auxData.prepend("\n");
auxData.append(annotationsEnd());
if (!replace)
auxData.append("\n");
} }
QTextCursor tc(m_textModifier->textDocument()); if (replace)
Utils::ChangeSet changeSet; m_textModifier->replace(startIndex, endIndex - startIndex + annotationsEnd().length(), auxData);
changeSet.replace(0, oldText.length(), newText); else
changeSet.apply(&tc); m_textModifier->replace(oldText.length(), 0, auxData);
} }
static void checkNode(const QmlJS::SimpleReaderNode::Ptr &node, RewriterView *view); static void checkNode(const QmlJS::SimpleReaderNode::Ptr &node, RewriterView *view);