void DiffBar::DiffStyler::Style(StyleRun& sr) { if (m_diffs.empty()) return; const unsigned int rstart = sr.GetRunStart(); const unsigned int rend = sr.GetRunEnd(); const cxChangeType primaryType = m_isLeft ? cxDELETION : cxINSERTION; const wxColor& primaryColor = m_isLeft ? m_delColor : m_insColor; const wxColor& secondaryColor = m_isLeft ? m_insColor : m_delColor; for (std::vector<Change>::const_iterator c = m_diffs.begin(); c != m_diffs.end(); ++c) { if (c->type == primaryType) { if (c->end_pos > rstart && c->start_pos < rend) { const unsigned int start = wxMax(rstart, c->start_pos); const unsigned int end = wxMin(rend, c->end_pos); sr.SetBackgroundColor(start, end, primaryColor); sr.SetShowHidden(start, end, true); } if (c->end_pos > rend) break; } else { if (c->rev_pos > rend) break; else if (c->rev_pos > rstart) { sr.SetBackgroundColor(c->rev_pos, c->rev_pos, secondaryColor); // zero-len } } } }
void Styler_SearchHL::ApplyStyle(StyleRun& sr, unsigned int start, unsigned int end) { sr.SetBackgroundColor(start, end, m_hlcolor); sr.SetShowHidden(start, end, true); }
void Styler_SearchHL::Style(StyleRun& sr) { const unsigned int rstart = sr.GetRunStart(); const unsigned int rend = sr.GetRunEnd(); // Style the run with search ranges if (!m_searchRanges.empty()) { for (size_t i = 0; i < m_searchRanges.size(); ++i) { const interval& r = m_searchRanges[i]; if (r.end > rstart && r.start < rend) { unsigned int start = wxMax(rstart, r.start); unsigned int end = wxMin(rend, r.end); sr.SetBackgroundColor(start, end, m_rangeColor); //const unsigned int cursor = m_cursors[i]; //if (cursor > rstart && cursor < rend) sr.SetBackgroundColor(cursor, cursor, m_hlcolor); } } } // No need for more styling if no search text if (m_text.empty()) return; // Extend stylerun start/end to get better search results (round up to whole EXTSIZEs) unsigned int sr_start = rstart> 100 ? rstart - 100 : 0; const unsigned int ext_end = ((rend/EXTSIZE) * EXTSIZE) + EXTSIZE; unsigned int sr_end = ext_end < m_lines.GetLength() ? ext_end : m_lines.GetLength(); // Make sure the extended positions are valid cxLOCKDOC_READ(m_doc) sr_start = doc.GetValidCharPos(sr_start); if (sr_end != m_lines.GetLength()) sr_end = doc.GetValidCharPos(sr_end); cxENDLOCK //wxLogDebug("Style %u %u", rstart, rend); //wxLogDebug(" %u %u - %u %u", sr_start, sr_end, m_search_start, m_search_end); // Check if we need to do a new search if (sr_start < m_search_start || m_search_end < sr_end) { // Check if there is overlap so we can just extend the search area if (sr_end > m_search_start && sr_start < m_search_end) { sr_start = wxMin(sr_start, m_search_start); sr_end = wxMax(sr_end, m_search_end); } else { // Else we have to move it m_matches.clear(); m_search_start = 0; m_search_end = 0; } // Do the search if (sr_start < m_search_start) { // Search from top DoSearch(sr_start, sr_end); } else if (sr_end > m_search_end) { // Search from bottom DoSearch(sr_start, sr_end, true); } else wxASSERT(false); m_search_start = sr_start; m_search_end = sr_end; } // Style the run with matches for (vector<interval>::iterator p = m_matches.begin(); p != m_matches.end(); ++p) { if (p->start > rend) break; // Check for overlap (or zero-length sel at start-of-line) if ((p->end > rstart && p->start < rend) || (p->start == p->end && p->end == rstart)) { unsigned int start = wxMax(rstart, p->start); unsigned int end = wxMin(rend, p->end); // Only draw it if it is in range if (!m_searchRanges.empty()) { bool inRange = false; for (vector<interval>::const_iterator s = m_searchRanges.begin(); s != m_searchRanges.end(); ++s) { if (start >= s->start && start < s->end) { inRange = true; break; } } if (!inRange) continue; } sr.SetBackgroundColor(start, end, m_hlcolor); sr.SetShowHidden(start, end, true); } } }