diff --git a/src/MacVim/MMBackend.m b/src/MacVim/MMBackend.m index 92e7e67f81..9e3acd917d 100644 --- a/src/MacVim/MMBackend.m +++ b/src/MacVim/MMBackend.m @@ -2092,6 +2092,8 @@ extern GuiFont gui_mch_retain_font(GuiFont font); [self setImState:NO]; } else if (BackingPropertiesChangedMsgID == msgid) { [self redrawScreen]; + } else if (RedrawBlockMsgID == msgid) { + [self handleRedrawBlock:data]; } else { ASLogWarn(@"Unknown message received (msgid=%d)", msgid); } @@ -3008,6 +3010,17 @@ extern GuiFont gui_mch_retain_font(GuiFont font); } } +- (void)handleRedrawBlock:(NSData *)data +{ + const void *bytes = [data bytes]; + int row1 = *((int*)bytes); bytes += sizeof(int); + int col1 = *((int*)bytes); bytes += sizeof(int); + int row2 = *((int*)bytes); bytes += sizeof(int); + int col2 = *((int*)bytes); + + gui_redraw_block(row1, col1, row2, col2, GUI_MON_NOCLEAR); +} + #ifdef FEAT_BEVAL - (void)bevalCallback:(id)sender { diff --git a/src/MacVim/MMCoreTextView.h b/src/MacVim/MMCoreTextView.h index c606310317..975cb324e0 100644 --- a/src/MacVim/MMCoreTextView.h +++ b/src/MacVim/MMCoreTextView.h @@ -18,6 +18,8 @@ int maxRows, maxColumns; NSColor *defaultBackgroundColor; NSColor *defaultForegroundColor; + int defaultBackgroundHexColor; + int defaultForegroundHexColor; NSSize cellSize; NSFont *font; NSFont *fontWide; @@ -51,6 +53,12 @@ void *trackingRectUserData_; NSTrackingRectTag lastToolTipTag_; NSString* toolTip_; + + NSUInteger markedRangeLength; + int markedTextStartRow; + int markedTextStartColumn; + int markedTextEndRow; + int markedTextEndColumn; } - (id)initWithFrame:(NSRect)frame; @@ -90,6 +98,7 @@ - (void)setInlineIm:(BOOL)enable; - (void)activateIm:(BOOL)enable; - (void)checkImState; +- (void)clearMarkedText; - (BOOL)convertPoint:(NSPoint)point toRow:(int *)row column:(int *)column; - (NSRect)rectForRow:(int)row column:(int)column numRows:(int)nr numColumns:(int)nc; diff --git a/src/MacVim/MMCoreTextView.m b/src/MacVim/MMCoreTextView.m index e708b50ba8..f5fc320564 100644 --- a/src/MacVim/MMCoreTextView.m +++ b/src/MacVim/MMCoreTextView.m @@ -205,6 +205,13 @@ defaultAdvanceForFont(NSFont *font) if (defaultBackgroundColor != bgColor) { [defaultBackgroundColor release]; defaultBackgroundColor = bgColor ? [bgColor retain] : nil; + if (bgColor) { + defaultBackgroundHexColor = + (int)(bgColor.blueComponent * 0xff) | + ((int)(bgColor.greenComponent * 0xff) << 8) | + ((int)(bgColor.redComponent * 0xff) << 16) | + (0xff << 24); + } } // NOTE: The default foreground color isn't actually used for anything, but @@ -213,6 +220,13 @@ defaultAdvanceForFont(NSFont *font) if (defaultForegroundColor != fgColor) { [defaultForegroundColor release]; defaultForegroundColor = fgColor ? [fgColor retain] : nil; + if (fgColor) { + defaultForegroundHexColor = + (int)(fgColor.blueComponent * 0xff) | + ((int)(fgColor.greenComponent * 0xff) << 8) | + ((int)(fgColor.redComponent * 0xff) << 16) | + (0xff << 24); + } } } @@ -499,6 +513,23 @@ defaultAdvanceForFont(NSFont *font) [helper setMarkedText:text selectedRange:range]; } +- (void)clearMarkedText +{ + if (![helper inlineIm]) { + [self redrawMarkedTextBlock]; + } +} + +- (void)redrawMarkedTextBlock +{ + NSMutableData *data = [NSMutableData data]; + [data appendBytes:&markedTextStartRow length:sizeof(int)]; + [data appendBytes:&markedTextStartColumn length:sizeof(int)]; + [data appendBytes:&markedTextEndRow length:sizeof(int)]; + [data appendBytes:&markedTextEndColumn length:sizeof(int)]; + [[self vimController] sendMessage:RedrawBlockMsgID data:data]; +} + - (void)unmarkText { [helper unmarkText]; @@ -652,6 +683,40 @@ defaultAdvanceForFont(NSFont *font) [drawData removeAllObjects]; } + + if ([helper hasMarkedText] && ![helper inlineIm]) { + NSString *text = [[helper markedText] string]; + // Draw marked text + CFStringRef sref = (__bridge CFStringRef)text; + CFIndex unilength = CFStringGetLength(sref); + const UniChar *unichars = CFStringGetCharactersPtr(sref); + UniChar *buffer = NULL; + if (unichars == NULL) { + buffer = malloc(unilength * sizeof(UniChar)); + CFStringGetCharacters(sref, CFRangeMake(0, unilength), buffer); + unichars = buffer; + } + + int row = [helper preEditRow]; + int col = [helper preEditColumn]; + + markedTextStartRow = row; + markedTextEndRow = row; + markedTextStartColumn = col; + markedTextEndColumn = col + unilength * 2; + + [self drawString:unichars length:unilength + atRow:row column:col cells:(unilength * 2) + withFlags:(DRAW_WIDE|DRAW_UNDERL) + foregroundColor:defaultForegroundHexColor + backgroundColor:defaultBackgroundHexColor + specialColor:defaultForegroundHexColor]; + + if (buffer) { + free(buffer); + buffer = NULL; + } + } } - (void)performBatchDrawWithData:(NSData *)data diff --git a/src/MacVim/MMTextView.h b/src/MacVim/MMTextView.h index e53735989a..5f4d019836 100644 --- a/src/MacVim/MMTextView.h +++ b/src/MacVim/MMTextView.h @@ -75,4 +75,5 @@ - (void)deleteSign:(NSString *)signName; - (void)setToolTipAtMousePoint:(NSString *)string; - (void)setCGLayerEnabled:(BOOL)enabled; +- (void)clearMarkedText; @end diff --git a/src/MacVim/MMTextView.m b/src/MacVim/MMTextView.m index a2724e615e..021253c1cd 100644 --- a/src/MacVim/MMTextView.m +++ b/src/MacVim/MMTextView.m @@ -731,6 +731,10 @@ [helper unmarkText]; } +- (void)clearMarkedText +{ +} + - (NSRect)firstRectForCharacterRange:(NSRange)range { return [helper firstRectForCharacterRange:range]; diff --git a/src/MacVim/MMTextViewHelper.m b/src/MacVim/MMTextViewHelper.m index e1d9c2202a..37eca81b45 100644 --- a/src/MacVim/MMTextViewHelper.m +++ b/src/MacVim/MMTextViewHelper.m @@ -213,6 +213,7 @@ KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b) // called the input manager expects the marked text to be unmarked // automatically, hence the explicit unmarkText: call here. [self unmarkText]; + [textView clearMarkedText]; } // NOTE: 'string' is either an NSString or an NSAttributedString. Since we @@ -317,6 +318,7 @@ KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b) // marked text moves outside the view as a result of scrolling. [self sendMarkedText:nil position:0]; [self unmarkText]; + [textView clearMarkedText]; [[NSTextInputContext currentInputContext] discardMarkedText]; } diff --git a/src/MacVim/MacVim.h b/src/MacVim/MacVim.h index c4df1d8762..a9b1b825c6 100644 --- a/src/MacVim/MacVim.h +++ b/src/MacVim/MacVim.h @@ -253,6 +253,7 @@ enum { DisableThinStrokesMsgID, EnableInlineImMsgID, DisableInlineImMsgID, + RedrawBlockMsgID, LastMsgID // NOTE: MUST BE LAST MESSAGE IN ENUM! }; diff --git a/src/MacVim/MacVim.m b/src/MacVim/MacVim.m index 0b43c6fd92..3d59c02eec 100644 --- a/src/MacVim/MacVim.m +++ b/src/MacVim/MacVim.m @@ -107,6 +107,7 @@ char *MessageStrings[] = "DisableThinStrokesMsgID", "EnableInlineImMsgID", "DisableInlineImMsgID", + "RedrawBlockMsgID", "END OF MESSAGE IDs" // NOTE: Must be last! };