forked from qt-creator/qt-creator
QmlDesigner: Fix selection from code editor
Calculate the correct node length if nodes are enclosed. We cannot just look for the next closing brace, we have to ignore opened and closed braces. Task-number: QDS-12543 Change-Id: Ieee232777637f4bc022e65af5d8cb437e025a146 Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
@@ -844,6 +844,26 @@ static bool isInNodeDefinition(int nodeTextOffset, int nodeTextLength, int curso
|
|||||||
return (nodeTextOffset <= cursorPosition) && (nodeTextOffset + nodeTextLength > cursorPosition);
|
return (nodeTextOffset <= cursorPosition) && (nodeTextOffset + nodeTextLength > cursorPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int findEvenClosingBrace(const QStringView &string)
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
for (auto currentChar : string) {
|
||||||
|
if (currentChar == '{')
|
||||||
|
count++;
|
||||||
|
|
||||||
|
if (currentChar == '}') {
|
||||||
|
if (count == 1)
|
||||||
|
return index;
|
||||||
|
else
|
||||||
|
count--;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
ModelNode RewriterView::nodeAtTextCursorPositionHelper(const ModelNode &root, int cursorPosition) const
|
ModelNode RewriterView::nodeAtTextCursorPositionHelper(const ModelNode &root, int cursorPosition) const
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_textModifier, return {});
|
QTC_ASSERT(m_textModifier, return {});
|
||||||
@@ -865,8 +885,9 @@ ModelNode RewriterView::nodeAtTextCursorPositionHelper(const ModelNode &root, in
|
|||||||
ModelNode node = pair.first;
|
ModelNode node = pair.first;
|
||||||
|
|
||||||
const int nodeTextOffset = nodeOffset(node);
|
const int nodeTextOffset = nodeOffset(node);
|
||||||
const int nodeTextLength = m_textModifier->text().indexOf("}", nodeTextOffset)
|
|
||||||
- nodeTextOffset - 1;
|
const int nodeTextLength = findEvenClosingBrace(m_textModifier->text().sliced(nodeTextOffset))
|
||||||
|
- 1;
|
||||||
|
|
||||||
if (isInNodeDefinition(nodeTextOffset, nodeTextLength, cursorPosition))
|
if (isInNodeDefinition(nodeTextOffset, nodeTextLength, cursorPosition))
|
||||||
lastNode = node;
|
lastNode = node;
|
||||||
|
Reference in New Issue
Block a user