Skip to content

Instantly share code, notes, and snippets.

@zonble
Created September 10, 2010 15:20
Show Gist options
  • Save zonble/573821 to your computer and use it in GitHub Desktop.
Save zonble/573821 to your computer and use it in GitHub Desktop.
// PTYTextView 27858
if([self hasMarkedText]) {
int len=[markedText length];
if (len>WIDTH-x1) len=WIDTH-x1;
NSRect inputFrame = NSMakeRect(floor(x1 * charWidth + MARGIN), (yStart + [dataSource numberOfLines] - HEIGHT) * lineHeight + (lineHeight - cursorHeight), ceil((WIDTH-x1)*cursorWidth),cursorHeight);
[markedText drawInRect:inputFrame];
NSAttributedString *attributedStringBeforeCursor = [markedText attributedSubstringFromRange:NSMakeRange(0, IM_INPUT_SELRANGE.location) ];
NSRect spaceFrame = [attributedStringBeforeCursor boundingRectWithSize:inputFrame.size options:0];
NSRect cursorFrame = NSMakeRect(inputFrame.origin.x + spaceFrame.size.width, inputFrame.origin.y, 2.0, inputFrame.size.height);
[[NSColor redColor] set];
NSRectFill(cursorFrame);
memset([dataSource dirty] + yStart * WIDTH + x1,
1,
WIDTH - x1 > len*2 ? len*2 : WIDTH-x1); //len*2 is an over-estimation, but safe
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment