From acf79d7fc61bdaefd2b108902b85f4ab48653bbe Mon Sep 17 00:00:00 2001 From: Francois Ferrand Date: Thu, 16 Oct 2014 10:18:48 +0200 Subject: CppTools: Fix C++ diagnostics hightlighting. When the length of the highlight is specified, the code does not properly check for end of line. This causes some lines to be highlighted when only the last word was supposed to be. For example, with this code: 1: void foo(int x); 2: int a = foo 3: (); 4: int b = foo( 5: ); line 2 and 4 used to be completely highlighted (underlined), instead of just 'foo'. Change-Id: I40e895410ce0f38bad0adbccd509fd2943c93c97 Reviewed-by: Nikolai Kosjar --- src/plugins/cpptools/baseeditordocumentprocessor.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/plugins/cpptools/baseeditordocumentprocessor.cpp') diff --git a/src/plugins/cpptools/baseeditordocumentprocessor.cpp b/src/plugins/cpptools/baseeditordocumentprocessor.cpp index 30a3e7937f..816b937586 100644 --- a/src/plugins/cpptools/baseeditordocumentprocessor.cpp +++ b/src/plugins/cpptools/baseeditordocumentprocessor.cpp @@ -95,9 +95,9 @@ QList BaseEditorDocumentProcessor::toTextEditorSelect QTextCursor c(textDocument->findBlockByNumber(m.line() - 1)); const QString text = c.block().text(); - if (m.length() > 0 && m.column() + m.length() < (unsigned)text.size()) { - int column = m.column() > 0 ? m.column() - 1 : 0; - c.setPosition(c.position() + column); + const int startPos = m.column() > 0 ? m.column() - 1 : 0; + if (m.length() > 0 && startPos + m.length() <= (unsigned)text.size()) { + c.setPosition(c.position() + startPos); c.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, m.length()); } else { for (int i = 0; i < text.size(); ++i) { -- cgit v1.2.1