Permalink
Browse files

Clip to cell when drawing insertion point

This fixes an issue where the cursor would spill over into the
neighboring cells on Retina displays (only).
  • Loading branch information...
1 parent a1f636d commit ce5b7a2d6d8b69d240eddcbb8a9a43e5a1de644a @b4winckler committed Aug 10, 2012
Showing with 10 additions and 1 deletion.
  1. +10 −1 src/MacVim/MMCoreTextView.m
@@ -1241,6 +1241,9 @@ - (void)drawInsertionPointAtRow:(int)row column:(int)col shape:(int)shape
{
CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
NSRect rect = [self rectForRow:row column:col numRows:1 numColumns:1];
+ CGRect clipRect = *(CGRect *)▭
+
+ CGContextSaveGState(context);
if (MMInsertionPointHorizontal == shape) {
int frac = (cellSize.height * percent + 99)/100;
@@ -1259,6 +1262,12 @@ - (void)drawInsertionPointAtRow:(int)row column:(int)col shape:(int)shape
// over into adjacent display cells and it may look ugly.
CGContextSetShouldAntialias(context, NO);
+ // Even though antialiasing is disabled and we adjust the rect to fit
+ // inside the display cell it still happens on Retina displays (only) that
+ // the cursor bleeds over into the neighboring cells. To work around this
+ // issue we enable clipping.
+ CGContextClipToRect(context, clipRect);
+
if (MMInsertionPointHollow == shape) {
// When stroking a rect its size is effectively 1 pixel wider/higher
// than we want so make it smaller to avoid having it bleed over into
@@ -1275,7 +1284,7 @@ - (void)drawInsertionPointAtRow:(int)row column:(int)col shape:(int)shape
CGContextFillRect(context, *(CGRect*)&rect);
}
- CGContextSetShouldAntialias(context, antialias);
+ CGContextRestoreGState(context);
}
- (void)drawInvertedRectAtRow:(int)row column:(int)col numRows:(int)nrows

0 comments on commit ce5b7a2

Please sign in to comment.