From 82fdf529ecc8b9c6c071199182d5207e0765304e Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Sat, 13 Oct 2007 11:55:37 +0000 Subject: [PATCH] Merged George's underline & draw speed patch git-svn-id: http://macvim.googlecode.com/svn/trunk@310 96c4425d-ca35-0410-94e5-3396d5c13a8f --- MMBackend.m | 8 ++- MMTextStorage.m | 156 +++++++++++++++++++++++++++++++--------------- MMVimController.m | 2 +- MacVim.h | 6 +- 4 files changed, 114 insertions(+), 58 deletions(-) diff --git a/MMBackend.m b/MMBackend.m index 848f20f9e9..70e34c93f9 100644 --- a/MMBackend.m +++ b/MMBackend.m @@ -26,6 +26,7 @@ // long periods without the screen updating (e.g. when sourcing a large session // file). (The unit is seconds.) static float MMFlushTimeoutInterval = 0.1f; +static int MMFlushQueueLenHint = 80*40; static unsigned MMServerMax = 1000; @@ -377,7 +378,8 @@ enum { // was called MacVim would feel unresponsive. So there is a time out which // ensures that the queue isn't flushed too often. if (!force && lastFlushDate && -[lastFlushDate timeIntervalSinceNow] - < MMFlushTimeoutInterval) + < MMFlushTimeoutInterval + && [drawData length] < MMFlushQueueLenHint) return; if ([drawData length] > 0) { @@ -1016,7 +1018,7 @@ enum { [self queueMessage:LeaveFullscreenMsgID data:nil]; } -- (oneway void)processInput:(int)msgid data:(in NSData *)data +- (oneway void)processInput:(int)msgid data:(in bycopy NSData *)data { // NOTE: This method might get called whenever the run loop is tended to. // Thus it might get called whilst input is being processed. Normally this @@ -1040,7 +1042,7 @@ enum { } } -- (oneway void)processInputAndData:(in NSArray *)messages +- (oneway void)processInputAndData:(in bycopy NSArray *)messages { // NOTE: See comment in processInput:data:. unsigned i, count = [messages count]; diff --git a/MMTextStorage.m b/MMTextStorage.m index 719b18b2b3..af82156e72 100644 --- a/MMTextStorage.m +++ b/MMTextStorage.m @@ -231,12 +231,25 @@ else if (flags & DRAW_ITALIC) theFont = italicFont; - NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: + NSDictionary *attributes; + + if (flags & DRAW_UNDERC) { + // move the undercurl down a bit so it is visible + attributes = [NSDictionary dictionaryWithObjectsAndKeys: + theFont, NSFontAttributeName, + bg, NSBackgroundColorAttributeName, + fg, NSForegroundColorAttributeName, + sp, NSUnderlineColorAttributeName, + [NSNumber numberWithFloat:2],NSBaselineOffsetAttributeName, + nil]; + } else { + attributes = [NSDictionary dictionaryWithObjectsAndKeys: theFont, NSFontAttributeName, bg, NSBackgroundColorAttributeName, fg, NSForegroundColorAttributeName, sp, NSUnderlineColorAttributeName, nil]; + } [attribString setAttributes:attributes range:range]; if (flags & DRAW_UNDERL) { @@ -282,33 +295,54 @@ NSRange srcRange = { (row+count)*(maxColumns+1) + left, width }; int i; - for (i = 0; i < move; ++i) { - NSAttributedString *srcString = [attribString - attributedSubstringFromRange:srcRange]; - [attribString replaceCharactersInRange:destRange - withAttributedString:srcString]; - [self edited:(NSTextStorageEditedCharacters - | NSTextStorageEditedAttributes) - range:destRange changeInLength:0]; - destRange.location += maxColumns+1; - srcRange.location += maxColumns+1; - } + if (width != maxColumns) { // if this is the case, then left must be 0 + for (i = 0; i < move; ++i) { + NSAttributedString *srcString = [attribString + attributedSubstringFromRange:srcRange]; + [attribString replaceCharactersInRange:destRange + withAttributedString:srcString]; + [self edited:(NSTextStorageEditedCharacters + | NSTextStorageEditedAttributes) + range:destRange changeInLength:0]; + destRange.location += maxColumns+1; + srcRange.location += maxColumns+1; + } + + NSRange emptyRange = {0,width}; + NSAttributedString *emptyString = + [emptyRowString attributedSubstringFromRange: emptyRange]; + NSDictionary *attribs = [NSDictionary dictionaryWithObjectsAndKeys: + font, NSFontAttributeName, + color, NSBackgroundColorAttributeName, nil]; - NSRange emptyRange = {0,width}; - NSAttributedString *emptyString = - [emptyRowString attributedSubstringFromRange: emptyRange]; - NSDictionary *attribs = [NSDictionary dictionaryWithObjectsAndKeys: - font, NSFontAttributeName, - color, NSBackgroundColorAttributeName, nil]; - - for (i = 0; i < count; ++i) { - [attribString replaceCharactersInRange:destRange - withAttributedString:emptyString]; - [attribString setAttributes:attribs range:destRange]; + for (i = 0; i < count; ++i) { + [attribString replaceCharactersInRange:destRange + withAttributedString:emptyString]; + [attribString setAttributes:attribs range:destRange]; + [self edited:(NSTextStorageEditedAttributes + | NSTextStorageEditedCharacters) range:destRange + changeInLength:0]; + destRange.location += maxColumns+1; + } + } else { + NSRange delRange = {row*(maxColumns+1), count*(maxColumns+1)}; + [attribString deleteCharactersInRange: delRange]; + destRange.location += move*(maxColumns+1); + + NSDictionary *attribs = [NSDictionary dictionaryWithObjectsAndKeys: + font, NSFontAttributeName, + color, NSBackgroundColorAttributeName, nil]; + destRange.length = maxColumns; + for (i = 0; i < count; ++i) { + [attribString insertAttributedString:emptyRowString + atIndex:destRange.location]; + [attribString setAttributes:attribs range:destRange]; + destRange.location += maxColumns+1; + } + NSRange editedRange = {row*(maxColumns+1),total*(maxColumns+1)}; [self edited:(NSTextStorageEditedAttributes - | NSTextStorageEditedCharacters) range:destRange - changeInLength:0]; - destRange.location += maxColumns+1; + | NSTextStorageEditedCharacters) range:editedRange + changeInLength:0]; } } @@ -336,33 +370,53 @@ NSRange srcRange = { (row+move-1)*(maxColumns+1) + left, width }; int i; - for (i = 0; i < move; ++i) { - NSAttributedString *srcString = [attribString - attributedSubstringFromRange:srcRange]; - [attribString replaceCharactersInRange:destRange - withAttributedString:srcString]; - [self edited:(NSTextStorageEditedCharacters - | NSTextStorageEditedAttributes) - range:destRange changeInLength:0]; - destRange.location -= maxColumns+1; - srcRange.location -= maxColumns+1; - } - - NSRange emptyRange = {0,width}; - NSAttributedString *emptyString = - [emptyRowString attributedSubstringFromRange:emptyRange]; - NSDictionary *attribs = [NSDictionary dictionaryWithObjectsAndKeys: - font, NSFontAttributeName, - color, NSBackgroundColorAttributeName, nil]; - - for (i = 0; i < count; ++i) { - [attribString replaceCharactersInRange:destRange - withAttributedString:emptyString]; - [attribString setAttributes:attribs range:destRange]; + if (width != maxColumns) { // if this is the case, then left must be 0 + for (i = 0; i < move; ++i) { + NSAttributedString *srcString = [attribString + attributedSubstringFromRange:srcRange]; + [attribString replaceCharactersInRange:destRange + withAttributedString:srcString]; + [self edited:(NSTextStorageEditedCharacters + | NSTextStorageEditedAttributes) + range:destRange changeInLength:0]; + destRange.location -= maxColumns+1; + srcRange.location -= maxColumns+1; + } + + NSRange emptyRange = {0,width}; + NSAttributedString *emptyString = + [emptyRowString attributedSubstringFromRange:emptyRange]; + NSDictionary *attribs = [NSDictionary dictionaryWithObjectsAndKeys: + font, NSFontAttributeName, + color, NSBackgroundColorAttributeName, nil]; + + for (i = 0; i < count; ++i) { + [attribString replaceCharactersInRange:destRange + withAttributedString:emptyString]; + [attribString setAttributes:attribs range:destRange]; + [self edited:(NSTextStorageEditedAttributes + | NSTextStorageEditedCharacters) range:destRange + changeInLength:0]; + destRange.location -= maxColumns+1; + } + } else { + NSRange delRange = {(row+move)*(maxColumns+1),count*(maxColumns+1)}; + [attribString deleteCharactersInRange: delRange]; + + NSDictionary *attribs = [NSDictionary dictionaryWithObjectsAndKeys: + font, NSFontAttributeName, + color, NSBackgroundColorAttributeName, nil]; + + destRange.location = row*(maxColumns+1); + for (i = 0; i < count; ++i) { + [attribString insertAttributedString:emptyRowString + atIndex:destRange.location]; + [attribString setAttributes:attribs range:destRange]; + } + NSRange editedRange = {row*(maxColumns+1),total*(maxColumns+1)}; [self edited:(NSTextStorageEditedAttributes - | NSTextStorageEditedCharacters) range:destRange + | NSTextStorageEditedCharacters) range:editedRange changeInLength:0]; - destRange.location -= maxColumns+1; } } diff --git a/MMVimController.m b/MMVimController.m index 2d86a2146e..19fa0d8470 100644 --- a/MMVimController.m +++ b/MMVimController.m @@ -414,7 +414,7 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag) [alert release]; } -- (oneway void)processCommandQueue:(in NSArray *)queue +- (oneway void)processCommandQueue:(in bycopy NSArray *)queue { if (!isInitialized) return; diff --git a/MacVim.h b/MacVim.h index 0fb1965e07..81420eb0a3 100644 --- a/MacVim.h +++ b/MacVim.h @@ -30,8 +30,8 @@ // @try/@catch/@finally to deal with timeouts. // @protocol MMBackendProtocol -- (oneway void)processInput:(int)msgid data:(in NSData *)data; -- (oneway void)processInputAndData:(in NSArray *)messages; +- (oneway void)processInput:(int)msgid data:(in bycopy NSData *)data; +- (oneway void)processInputAndData:(in bycopy NSArray *)messages; - (BOOL)checkForModifiedBuffers; - (oneway void)setDialogReturn:(in bycopy id)obj; - (BOOL)starRegisterToPasteboard:(byref NSPasteboard *)pboard; @@ -42,7 +42,7 @@ // This is the protocol MMVimController implements. // @protocol MMFrontendProtocol -- (oneway void)processCommandQueue:(in NSArray *)queue; +- (oneway void)processCommandQueue:(in bycopy NSArray *)queue; - (oneway void)showSavePanelForDirectory:(in bycopy NSString *)dir title:(in bycopy NSString *)title saving:(int)saving;