From 0f915a95811d1b8e3c8fc395a6ce76f3f8c1933e Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Wed, 4 Oct 2017 17:14:07 +0300 Subject: [PATCH] Script editor fixed --- limereport/scripteditor/lrcodeeditor.cpp | 79 ++++++++++++------------ 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/limereport/scripteditor/lrcodeeditor.cpp b/limereport/scripteditor/lrcodeeditor.cpp index 273a1b3..97b300e 100644 --- a/limereport/scripteditor/lrcodeeditor.cpp +++ b/limereport/scripteditor/lrcodeeditor.cpp @@ -148,31 +148,33 @@ QString CodeEditor::textUnderCursor() const bool CodeEditor::matchLeftParenthesis(QTextBlock currentBlock, QChar parenthesisType, int i, int numLeftParentheses) { TextBlockData *data = static_cast(currentBlock.userData()); - QVector infos = data->parentheses(); + if (data){ + QVector infos = data->parentheses(); - int docPos = currentBlock.position(); - for (; i < infos.size(); ++i) { - ParenthesisInfo *info = infos.at(i); + int docPos = currentBlock.position(); + for (; i < infos.size(); ++i) { + ParenthesisInfo *info = infos.at(i); + + if (info->character == parenthesisType) { + ++numLeftParentheses; + continue; + } + + if (info->character == getParenthesisReverceChar(parenthesisType)){ + if (numLeftParentheses == 0) { + createParenthesisSelection(docPos + info->position); + return true; + } else + --numLeftParentheses; + } - if (info->character == parenthesisType) { - ++numLeftParentheses; - continue; - } - - if (info->character == getParenthesisReverceChar(parenthesisType)){ - if (numLeftParentheses == 0) { - createParenthesisSelection(docPos + info->position); - return true; - } else - --numLeftParentheses; } + currentBlock = currentBlock.next(); + if (currentBlock.isValid()) + return matchLeftParenthesis(currentBlock, parenthesisType, 0, numLeftParentheses); } - currentBlock = currentBlock.next(); - if (currentBlock.isValid()) - return matchLeftParenthesis(currentBlock, parenthesisType, 0, numLeftParentheses); - return false; } @@ -180,27 +182,28 @@ bool CodeEditor::matchRightParenthesis(QTextBlock currentBlock, QChar parenthesi { TextBlockData *data = static_cast(currentBlock.userData()); QVector parentheses = data->parentheses(); + if (data){ + int docPos = currentBlock.position(); + for (; i > -1 && parentheses.size() > 0; --i) { + ParenthesisInfo *info = parentheses.at(i); + if (info->character == parenthesisType) { + ++numRightParentheses; + continue; + } + if (info->character == getParenthesisReverceChar(parenthesisType)){ + if (numRightParentheses == 0) { + createParenthesisSelection(docPos + info->position); + return true; + } else + --numRightParentheses; + } + } + + currentBlock = currentBlock.previous(); + if (currentBlock.isValid()) + return matchRightParenthesis(currentBlock, parenthesisType, 0, numRightParentheses); - int docPos = currentBlock.position(); - for (; i > -1 && parentheses.size() > 0; --i) { - ParenthesisInfo *info = parentheses.at(i); - if (info->character == parenthesisType) { - ++numRightParentheses; - continue; - } - if (info->character == getParenthesisReverceChar(parenthesisType)){ - if (numRightParentheses == 0) { - createParenthesisSelection(docPos + info->position); - return true; - } else - --numRightParentheses; - } } - - currentBlock = currentBlock.previous(); - if (currentBlock.isValid()) - return matchRightParenthesis(currentBlock, parenthesisType, 0, numRightParentheses); - return false; }