diff options
author | Leandro Melo <leandro.melo@nokia.com> | 2010-06-15 10:35:39 +0200 |
---|---|---|
committer | Leandro Melo <leandro.melo@nokia.com> | 2010-06-15 10:44:15 +0200 |
commit | 0894033f9387dc3afa688ed0c4adcd0b27949f7b (patch) | |
tree | 6d40f5676c953c2cc1015828724601054fd7934d /src/plugins/texteditor/generichighlighter/highlighter.cpp | |
parent | 54ea41af470d31a2cb4526f31327397c0ea1a30c (diff) | |
download | qt-creator-0894033f9387dc3afa688ed0c4adcd0b27949f7b.tar.gz |
Coloring white spaces even if there's no highlight syntax definition set.
Relative to QTCREATORBUG-1225.
Diffstat (limited to 'src/plugins/texteditor/generichighlighter/highlighter.cpp')
-rw-r--r-- | src/plugins/texteditor/generichighlighter/highlighter.cpp | 66 |
1 files changed, 34 insertions, 32 deletions
diff --git a/src/plugins/texteditor/generichighlighter/highlighter.cpp b/src/plugins/texteditor/generichighlighter/highlighter.cpp index 8b4df9a0a5..fc2fa35bd6 100644 --- a/src/plugins/texteditor/generichighlighter/highlighter.cpp +++ b/src/plugins/texteditor/generichighlighter/highlighter.cpp @@ -51,15 +51,12 @@ namespace { const Highlighter::KateFormatMap Highlighter::m_kateFormats; -Highlighter::Highlighter(const QSharedPointer<Context> &defaultContext,QTextDocument *parent) : +Highlighter::Highlighter(QTextDocument *parent) : QSyntaxHighlighter(parent), m_persistentStatesCounter(PersistentsStart), m_dynamicContextsCounter(0), - m_isBroken(false), - m_defaultContext(defaultContext) -{ - m_persistentStates.insert(m_defaultContext->name(), Default); -} + m_isBroken(false) +{} Highlighter::~Highlighter() {} @@ -88,37 +85,47 @@ Highlighter::KateFormatMap::KateFormatMap() m_ids.insert(QLatin1String("dsError"), Highlighter::Error); } -void Highlighter::highlightBlock(const QString &text) +void Highlighter::configureFormat(TextFormatId id, const QTextCharFormat &format) { - if (m_isBroken) - return; + m_creatorFormats[id] = format; +} - try { - setupDataForBlock(text); +void Highlighter::setDefaultContext(const QSharedPointer<Context> &defaultContext) +{ + m_defaultContext = defaultContext; + m_persistentStates.insert(m_defaultContext->name(), Default); +} - handleContextChange(m_currentContext->lineBeginContext(), m_currentContext->definition()); +void Highlighter::highlightBlock(const QString &text) +{ + if (!m_defaultContext.isNull() && !m_isBroken) { + try { + setupDataForBlock(text); - ProgressData progress; - const int length = text.length(); - while (progress.offset() < length) { + handleContextChange(m_currentContext->lineBeginContext(), + m_currentContext->definition()); - if (progress.offset() > 0 && - progress.onlySpacesSoFar() && - !text.at(progress.offset()).isSpace()) { - progress.setOnlySpacesSoFar(false); + ProgressData progress; + const int length = text.length(); + while (progress.offset() < length) { + if (progress.offset() > 0 && + progress.onlySpacesSoFar() && + !text.at(progress.offset()).isSpace()) { + progress.setOnlySpacesSoFar(false); + } + + iterateThroughRules(text, length, &progress, false, m_currentContext->rules()); } - iterateThroughRules(text, length, &progress, false, m_currentContext->rules()); + handleContextChange(m_currentContext->lineEndContext(), + m_currentContext->definition(), + false); + m_contexts.clear(); + } catch (const HighlighterException &) { + m_isBroken = true; } - - handleContextChange(m_currentContext->lineEndContext(), m_currentContext->definition(), - false); - } catch (const HighlighterException &) { - m_isBroken = true; - return; } - m_contexts.clear(); applyVisualWhitespaceFormat(text); } @@ -462,8 +469,3 @@ void Highlighter::setCurrentContext() } m_currentContext = m_contexts.back(); } - -void Highlighter::configureFormat(TextFormatId id, const QTextCharFormat &format) -{ - m_creatorFormats[id] = format; -} |