ui: Fixed code color not reset after annotation in dark schemes
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user