From 1f699552f71f5dd9e0aa96f96e55a508926904ce Mon Sep 17 00:00:00 2001 From: PlutonicOverkill Date: Wed, 26 Apr 2017 15:49:39 +1200 Subject: [PATCH] Fix infinite recursion bug in uncommentSelection() --- apps/opencs/view/world/scriptedit.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/apps/opencs/view/world/scriptedit.cpp b/apps/opencs/view/world/scriptedit.cpp index 2a2165e1f..eb9757f60 100644 --- a/apps/opencs/view/world/scriptedit.cpp +++ b/apps/opencs/view/world/scriptedit.cpp @@ -293,9 +293,9 @@ void CSVWorld::ScriptEdit::commentSelection() begin.movePosition(QTextCursor::StartOfLine); end.setPosition(end.selectionEnd()); - end.movePosition(QTextCursor::StartOfLine); + end.movePosition(QTextCursor::EndOfLine); - for (; begin <= end; begin.movePosition(QTextCursor::StartOfLine), begin.movePosition(QTextCursor::Down)) + for (; begin < end; begin.movePosition(QTextCursor::StartOfLine), begin.movePosition(QTextCursor::Down)) { begin.insertText(";"); } @@ -309,13 +309,15 @@ void CSVWorld::ScriptEdit::uncommentSelection() begin.movePosition(QTextCursor::StartOfLine); end.setPosition(end.selectionEnd()); - end.movePosition(QTextCursor::StartOfLine); + end.movePosition(QTextCursor::EndOfLine); - for (; begin <= end; begin.movePosition(QTextCursor::StartOfLine), begin.movePosition(QTextCursor::Down)) { - // loop through line until a nonspace character is reached + for (; begin < end; begin.movePosition(QTextCursor::StartOfLine), begin.movePosition(QTextCursor::Down)) { begin.select(QTextCursor::LineUnderCursor); QString line = begin.selectedText(); + if (line.size() == 0) + continue; + // get first nonspace character in line int index; for (index = 0; index != line.size(); ++index) @@ -326,10 +328,11 @@ void CSVWorld::ScriptEdit::uncommentSelection() if (index != line.size() && line[index] == ';') { + // remove the semicolon line.remove(index, 1); + // put the line back + begin.insertText(line); } - - begin.insertText(line); } }