From 3805013b5d2f8f40176f9ef05dab3d55076b2037 Mon Sep 17 00:00:00 2001 From: nemu Date: Fri, 22 May 2009 18:13:37 +0000 Subject: [PATCH] improved (un)comment handling --- src/musrgui/PTextEdit.cpp | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/musrgui/PTextEdit.cpp b/src/musrgui/PTextEdit.cpp index 7459efbe..553581a3 100644 --- a/src/musrgui/PTextEdit.cpp +++ b/src/musrgui/PTextEdit.cpp @@ -996,11 +996,21 @@ void PTextEdit::editComment() // get selection text str = currentEditor()->selectedText(); // check line by line if (un)comment is needed - QStringList strList = QStringList::split("\n", str); + QStringList strList = QStringList::split("\n", str, TRUE); for (QStringList::Iterator it = strList.begin(); it != strList.end(); ++it) { - if ((*it).stripWhiteSpace().startsWith("#")) { // comment -> uncomment it - (*it).remove(0,1); - (*it) = (*it).stripWhiteSpace(); + str = *it; + if (str.stripWhiteSpace().startsWith("#")) { // comment -> uncomment it + int idx = -1; + for (unsigned int i=0; i<(*it).length(); i++) { + if ((*it)[i] == '#') { + idx = i; + break; + } + } + (*it).remove(idx,1); + if ((*it)[idx] == ' ') { + (*it).remove(idx,1); + } } else { // no comment -> comment it (*it).prepend("# "); } @@ -1016,10 +1026,21 @@ void PTextEdit::editComment() str = currentEditor()->text(para); // check if it is a comment line or not if (str.stripWhiteSpace().startsWith("#")) { // comment -> uncomment it - str.remove(0,1); - str = str.stripWhiteSpace(); + str = currentEditor()->text(para); + int idx = -1; + for (unsigned int i=0; i comment it - str.prepend("# "); + if (!str.isEmpty()) + str.prepend("# "); } // select current line currentEditor()->setSelection(para, 0, para, currentEditor()->text(para).length());