ui: Fixed code color not reset after annotation in dark schemes

This commit is contained in:
Eberhard Graether
2017-09-03 23:15:40 +02:00
parent 602ebbfe46
commit 919e3ad0cb
2 changed files with 41 additions and 1 deletions
+36
View File
@@ -199,6 +199,8 @@ void QtHighlighter::highlightRange(int startLine, int endLine)
{
if (!m_highlightedLines[index])
{
applyFormatWithoutRanges(it.position(), it.position() + it.length() - 1, s_textFormat, m_ranges);
foreach (const HighlightingRule &rule, m_highlightingRules)
{
formatBlock(it, rule, &m_ranges, false);
@@ -242,6 +244,40 @@ void QtHighlighter::applyFormat(int startPosition, int endPosition, const QTextC
cursor.setCharFormat(format);
}
void QtHighlighter::applyFormatWithoutRanges(
int startPosition, int endPosition, const QTextCharFormat& format, const std::vector<std::pair<int, int>>& ranges
){
std::vector<std::pair<int, int>> highlightRanges;
for (const std::pair<int, int> p : ranges)
{
if (p.first <= startPosition && p.second >= endPosition)
{
return;
}
if (p.first > startPosition && p.first < endPosition)
{
highlightRanges.push_back(std::pair<int, int>(startPosition, p.first - 1));
}
if (p.second > startPosition && p.second < endPosition)
{
highlightRanges.push_back(std::pair<int, int>(p.second + 1, endPosition));
}
}
if (!highlightRanges.size())
{
highlightRanges.push_back(std::pair<int, int>(startPosition, endPosition));
}
for (const std::pair<int, int> p : highlightRanges)
{
applyFormat(p.first, p.second, format);
}
}
QTextCharFormat QtHighlighter::getFormat(int startPosition, int endPosition) const
{
QTextCursor cursor(document());
+5 -1
View File
@@ -21,6 +21,9 @@ public:
void rehighlightLines(const std::vector<int>& lines);
void applyFormat(int startPosition, int endPosition, const QTextCharFormat& format);
void applyFormatWithoutRanges(
int startPosition, int endPosition, const QTextCharFormat& format, const std::vector<std::pair<int, int>>& ranges);
QTextCharFormat getFormat(int startPosition, int endPosition) const;
private:
@@ -36,7 +39,8 @@ private:
void highlightMultiLineComments(std::vector<std::pair<int, int>>* ranges);
bool isInRange(int index, const std::vector<std::pair<int, int>>& ranges) const;
void formatBlock(const QTextBlock& block, const HighlightingRule& rule, std::vector<std::pair<int, int>>* ranges, bool saveRange);
void formatBlock(
const QTextBlock& block, const HighlightingRule& rule, std::vector<std::pair<int, int>>* ranges, bool saveRange);
QTextDocument* document() const;