From 6adb3f617e5b89ac300df0530cac58ee78d3a466 Mon Sep 17 00:00:00 2001 From: mae Date: Thu, 11 Dec 2008 13:20:59 +0100 Subject: [PATCH 1/4] connect the parenthesis matcher with the ifdefed out information. --- src/plugins/texteditor/basetexteditor.cpp | 33 ++++++++++++++--------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 8d5bf3ff683..d613db7a294 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -734,12 +734,15 @@ void BaseTextEditor::moveLineUpDown(bool up) move.clearSelection(); move.insertText(text); int end = move.position(); - move.endEditBlock(); + if (hasSelection) { move.setPosition(start); move.setPosition(end, QTextCursor::KeepAnchor); } + indent(document(), move, QChar::Null); + move.endEditBlock(); + setTextCursor(move); } @@ -2951,12 +2954,13 @@ void BaseTextEditor::markBlocksAsChanged(QList blockNumbers) { TextBlockUserData::MatchType TextBlockUserData::checkOpenParenthesis(QTextCursor *cursor, QChar c) { - if (!TextEditDocumentLayout::hasParentheses(cursor->block())) + QTextBlock block = cursor->block(); + if (!TextEditDocumentLayout::hasParentheses(block) || TextEditDocumentLayout::ifdefedOut(block)) return NoMatch; - Parentheses parenList = TextEditDocumentLayout::parentheses(cursor->block()); + Parentheses parenList = TextEditDocumentLayout::parentheses(block); Parenthesis openParen, closedParen; - QTextBlock closedParenParag = cursor->block(); + QTextBlock closedParenParag = block; const int cursorPos = cursor->position() - closedParenParag.position(); int i = 0; @@ -2981,7 +2985,8 @@ TextBlockUserData::MatchType TextBlockUserData::checkOpenParenthesis(QTextCursor closedParenParag = closedParenParag.next(); if (!closedParenParag.isValid()) return NoMatch; - if (TextEditDocumentLayout::hasParentheses(closedParenParag)) { + if (TextEditDocumentLayout::hasParentheses(closedParenParag) + && !TextEditDocumentLayout::ifdefedOut(closedParenParag)) { parenList = TextEditDocumentLayout::parentheses(closedParenParag); break; } @@ -3018,12 +3023,13 @@ TextBlockUserData::MatchType TextBlockUserData::checkOpenParenthesis(QTextCursor TextBlockUserData::MatchType TextBlockUserData::checkClosedParenthesis(QTextCursor *cursor, QChar c) { - if (!TextEditDocumentLayout::hasParentheses(cursor->block())) + QTextBlock block = cursor->block(); + if (!TextEditDocumentLayout::hasParentheses(block) || TextEditDocumentLayout::ifdefedOut(block)) return NoMatch; - Parentheses parenList = TextEditDocumentLayout::parentheses(cursor->block()); + Parentheses parenList = TextEditDocumentLayout::parentheses(block); Parenthesis openParen, closedParen; - QTextBlock openParenParag = cursor->block(); + QTextBlock openParenParag = block; const int cursorPos = cursor->position() - openParenParag.position(); int i = parenList.count() - 1; @@ -3049,7 +3055,8 @@ TextBlockUserData::MatchType TextBlockUserData::checkClosedParenthesis(QTextCurs if (!openParenParag.isValid()) return NoMatch; - if (TextEditDocumentLayout::hasParentheses(openParenParag)) { + if (TextEditDocumentLayout::hasParentheses(openParenParag) + && !TextEditDocumentLayout::ifdefedOut(openParenParag)) { parenList = TextEditDocumentLayout::parentheses(openParenParag); break; } @@ -3091,7 +3098,7 @@ bool TextBlockUserData::findPreviousOpenParenthesis(QTextCursor *cursor, bool se int ignore = 0; while (block.isValid()) { Parentheses parenList = TextEditDocumentLayout::parentheses(block); - if (!parenList.isEmpty()) { + if (!parenList.isEmpty() && !TextEditDocumentLayout::ifdefedOut(block)) { for (int i = parenList.count()-1; i >= 0; --i) { Parenthesis paren = parenList.at(i); if (block == cursor->block() && position - block.position() <= paren.pos + 1) @@ -3118,7 +3125,7 @@ bool TextBlockUserData::findNextClosingParenthesis(QTextCursor *cursor, bool sel int ignore = 0; while (block.isValid()) { Parentheses parenList = TextEditDocumentLayout::parentheses(block); - if (!parenList.isEmpty()) { + if (!parenList.isEmpty() && !TextEditDocumentLayout::ifdefedOut(block)) { for (int i = 0; i < parenList.count(); ++i) { Parenthesis paren = parenList.at(i); if (block == cursor->block() && position - block.position() >= paren.pos) @@ -3143,7 +3150,7 @@ TextBlockUserData::MatchType TextBlockUserData::matchCursorBackward(QTextCursor cursor->clearSelection(); const QTextBlock block = cursor->block(); - if (!TextEditDocumentLayout::hasParentheses(block)) + if (!TextEditDocumentLayout::hasParentheses(block) || TextEditDocumentLayout::ifdefedOut(block)) return NoMatch; const int relPos = cursor->position() - block.position(); @@ -3165,7 +3172,7 @@ TextBlockUserData::MatchType TextBlockUserData::matchCursorForward(QTextCursor * cursor->clearSelection(); const QTextBlock block = cursor->block(); - if (!TextEditDocumentLayout::hasParentheses(block)) + if (!TextEditDocumentLayout::hasParentheses(block) || TextEditDocumentLayout::ifdefedOut(block)) return NoMatch; const int relPos = cursor->position() - block.position(); From ddfd46b3224811d0e202e8a44a97150c50856d99 Mon Sep 17 00:00:00 2001 From: mae Date: Thu, 11 Dec 2008 13:35:58 +0100 Subject: [PATCH 2/4] nicer (un)comment selection, avoid C-style selections when you can do C++ style. --- src/plugins/cppeditor/cppeditor.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index f233c0121f8..8aec6e39203 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -744,7 +744,8 @@ void CPPEditor::unCommentSelection() QString endText = endBlock.text(); int endPos = end - endBlock.position(); - bool hasTrailingCharacters = !endText.mid(endPos).trimmed().isEmpty(); + bool hasTrailingCharacters = !endText.left(endPos).remove(QLatin1String("//")).trimmed().isEmpty() + && !endText.mid(endPos).trimmed().isEmpty(); if ((endPos <= endText.length() - 2 && endText.at(endPos) == QLatin1Char('*') && endText.at(endPos+1) == QLatin1Char('/'))) { From 9890705295a7dda84507b8969953925ade38169f Mon Sep 17 00:00:00 2001 From: mae Date: Thu, 11 Dec 2008 14:11:28 +0100 Subject: [PATCH 3/4] make the home key jump to column 0 if the caret if before the first non-space --- src/plugins/texteditor/basetexteditor.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index d613db7a294..9b4e4254f59 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -2767,6 +2767,8 @@ void BaseTextEditor::handleHomeKey(bool anchor) while (character == tab || character.category() == QChar::Separator_Space) { ++pos; + if (pos == initpos) + break; character = characterAt(pos); } From f149c17d17c2fc86654f770550d43ab98721056e Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Thu, 11 Dec 2008 14:44:24 +0100 Subject: [PATCH 4/4] Fixed possible crash when merging the evironments. --- src/libs/cplusplus/TypeOfExpression.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libs/cplusplus/TypeOfExpression.cpp b/src/libs/cplusplus/TypeOfExpression.cpp index 53fa7e78396..68732f78ea0 100644 --- a/src/libs/cplusplus/TypeOfExpression.cpp +++ b/src/libs/cplusplus/TypeOfExpression.cpp @@ -107,6 +107,8 @@ void TypeOfExpression::processEnvironment(QMap documents Document::Ptr doc, Environment *env, QSet *processed) const { + if (! doc) + return; if (processed->contains(doc->fileName())) return; processed->insert(doc->fileName());