fixup! Extend gutter theming to selection foreground

Previous solution didn’t handle soft wrapped lines.

This solution also scales better, as we no longer need to break up ranges and create an entry per selected line.
This commit is contained in:
Allan Odgaard
2012-08-25 13:50:32 +02:00
parent ed534778a7
commit 23576923fd
2 changed files with 6 additions and 11 deletions

View File

@@ -42,7 +42,6 @@ struct GVLineRecord
NSMutableSet* hiddenColumns;
std::string highlightedRange;
std::vector<CGRect> backgroundRects, borderRects;
std::set<size_t> selectedLines;
NSPoint mouseDownAtPoint;
NSPoint mouseHoveringAtPoint;

View File

@@ -116,7 +116,6 @@ struct data_source_t
{
backgroundRects.clear();
borderRects.clear();
selectedLines.clear();
citerate(range, text::selection_t(highlightedRange))
{
@@ -125,12 +124,6 @@ struct data_source_t
auto fragment = [delegate lineFragmentForLine:to.line column:to.column];
CGFloat lastY = to.column == 0 && from.line != to.line ? fragment.firstY : fragment.lastY;
for(size_t i = from.line; i < to.line; ++i)
selectedLines.insert(i);
if(!(to.column == 0 && from.line != to.line))
selectedLines.insert(to.line);
backgroundRects.push_back(CGRectMake(0, firstY+1, self.frame.size.width, lastY - firstY - 2));
borderRects.push_back(CGRectMake(0, firstY, self.frame.size.width, 1));
borderRects.push_back(CGRectMake(0, lastY-1, self.frame.size.width, 1));
@@ -364,10 +357,13 @@ static void DrawText (std::string const& text, CGRect const& rect, CGFloat basel
break;
prevLine = std::make_pair(record.lineNumber, record.softlineOffset);
NSColor* textColor;
if(selectedLines.find(record.lineNumber) != selectedLines.end())
NSRect rowRect = NSMakeRect(0, record.firstY, CGRectGetWidth(self.frame), record.lastY - record.firstY);
NSColor* textColor = self.foregroundColor;
iterate(rect, backgroundRects)
{
if(NSIntersectsRect(*rect, rowRect))
textColor = self.selectionForegroundColor;
else textColor = self.foregroundColor;
}
citerate(dataSource, [self visibleColumnDataSources])
{