From 987cd438f64b6b06cffe31a512584e55b41cad9d Mon Sep 17 00:00:00 2001 From: don bright Date: Sun, 13 Jan 2013 00:37:20 +0100 Subject: fix qt4.4, old gcc, and mention Giles' Rapcad higlighter diff --git a/src/highlighter.cc b/src/highlighter.cc index 98eff8c..a7592da 100644 --- a/src/highlighter.cc +++ b/src/highlighter.cc @@ -39,8 +39,13 @@ Also, QT 4.5 and lower do not have rehighlightBlock(), so they will be slow on large files as well, as they re-highlight everything after each compile. - The vast majority of OpenSCAD files, however, are not 50,000 lines + The vast majority of OpenSCAD files, however, are not 50,000 lines and + most machines ship with Qt > 4.5 + See Also: + + Giles Bathgate's Rapcad lexer-based highlighter: rapcad.org + Test suite: 1. action: open example001, remove first {, hit f5 @@ -177,7 +182,7 @@ void Highlighter::highlightError(int error_pos) err_block = err_block.previous(); errorPos = err_block.position()+err_block.length() - 2; } - if ( errorPos == document()->characterCount()-1 ) { + if ( errorPos == lastDocumentPos()-1 ) { errorPos--; } @@ -204,10 +209,22 @@ void Highlighter::portable_rehighlightBlock( const QTextBlock &block ) #if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)) rehighlightBlock( block ); #else - rehighlight(); // slow on big files + rehighlight(); // slow on very large files #endif } +int Highlighter::lastDocumentPos() +{ +// fixme - test it +#if (QT_VERSION >= QT_VERSION_CHECK(4, 5, 0)) + return document()->characterCount(); +#else + QTextBlock lastblock = document()->lastBlock(); + return lastblock.position() + lastblock.length(); +#endif +} + + void Highlighter::highlightBlock(const QString &text) { int block_first_pos = currentBlock().position(); diff --git a/src/highlighter.h b/src/highlighter.h index 09bba39..428bbbb 100644 --- a/src/highlighter.h +++ b/src/highlighter.h @@ -2,6 +2,8 @@ #define HIGHLIGHTER_H_ #include +#include +#include class Highlighter : public QSyntaxHighlighter { @@ -17,8 +19,9 @@ private: QTextBlock lastErrorBlock; int errorPos; bool errorState; - QMap tokentypes; - QMap typeformats; + QMap tokentypes; + QMap typeformats; + int lastDocumentPos(); void portable_rehighlightBlock( const QTextBlock &text ); }; -- cgit v0.10.1