Improve Find pasteboard interaction

Put two representation of the search pattern on the Find pasteboard: one
that holds the unmodified pattern, and a second one that removes some
common backslash escapes from the first.  The second pattern will be
used by other applications so e.g. hitting * in MacVim and then Cmd+g in
another app now works.
This commit is contained in:
Bjorn Winckler
2009-11-28 19:10:03 +01:00
parent 1c1f5c6646
commit e98f8a27c2
4 changed files with 61 additions and 11 deletions
+9 -2
View File
@@ -1039,8 +1039,15 @@
if (!query) {
// Use find pasteboard for next query.
NSPasteboard *pb = [NSPasteboard pasteboardWithName:NSFindPboard];
NSArray *types = [NSArray arrayWithObject:NSStringPboardType];
if ([pb availableTypeFromArray:types])
NSArray *supportedTypes = [NSArray arrayWithObjects:VimFindPboardType,
NSStringPboardType, nil];
NSString *bestType = [pb availableTypeFromArray:supportedTypes];
// See gui_macvim_add_to_find_pboard() for an explanation of these
// types.
if ([bestType isEqual:VimFindPboardType])
query = [pb stringForType:VimFindPboardType];
else
query = [pb stringForType:NSStringPboardType];
}
+3 -1
View File
@@ -257,13 +257,15 @@ enum {
// Vim pasteboard type (holds motion type + string)
extern NSString *VimPBoardType;
extern NSString *VimPboardType;
extern NSString *VimFindPboardType;
@interface NSString (MMExtras)
- (NSString *)stringByEscapingSpecialFilenameCharacters;
- (NSString *)stringByRemovingFindPatterns;
@end
+33 -1
View File
@@ -111,7 +111,9 @@ NSString *MMAutosaveColumnsKey = @"MMAutosaveColumns";
NSString *MMRendererKey = @"MMRenderer";
// Vim pasteboard type (holds motion type + string)
NSString *VimPBoardType = @"VimPBoardType";
NSString *VimPboardType = @"VimPboardType";
// Vim find pasteboard type (string contains Vim regex patterns)
NSString *VimFindPboardType = @"VimFindPboardType";
int ASLogLevel = ASL_LEVEL_NOTICE;
@@ -198,6 +200,36 @@ debugStringForMessageQueue(NSArray *queue)
return [string autorelease];
}
- (NSString *)stringByRemovingFindPatterns
{
// Remove some common patterns added to search strings that other apps are
// not aware of.
NSMutableString *string = [self mutableCopy];
// Added when doing * search
[string replaceOccurrencesOfString:@"\\<"
withString:@""
options:NSLiteralSearch
range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"\\>"
withString:@""
options:NSLiteralSearch
range:NSMakeRange(0, [string length])];
// \V = match whole word
[string replaceOccurrencesOfString:@"\\V"
withString:@""
options:NSLiteralSearch
range:NSMakeRange(0, [string length])];
// \c = case insensitive, \C = case sensitive
[string replaceOccurrencesOfString:@"\\c"
withString:@""
options:NSCaseInsensitiveSearch|NSLiteralSearch
range:NSMakeRange(0, [string length])];
return [string autorelease];
}
@end // NSString (MMExtras)
+16 -7
View File
@@ -611,7 +611,7 @@ clip_mch_own_selection(VimClipboard *cbd)
clip_mch_request_selection(VimClipboard *cbd)
{
NSPasteboard *pb = [NSPasteboard generalPasteboard];
NSArray *supportedTypes = [NSArray arrayWithObjects:VimPBoardType,
NSArray *supportedTypes = [NSArray arrayWithObjects:VimPboardType,
NSStringPboardType, nil];
NSString *bestType = [pb availableTypeFromArray:supportedTypes];
if (!bestType) return;
@@ -619,12 +619,12 @@ clip_mch_request_selection(VimClipboard *cbd)
int motion_type = MCHAR;
NSString *string = nil;
if ([bestType isEqual:VimPBoardType]) {
if ([bestType isEqual:VimPboardType]) {
// This type should consist of an array with two objects:
// 1. motion type (NSNumber)
// 2. text (NSString)
// If this is not the case we fall back on using NSStringPboardType.
id plist = [pb propertyListForType:VimPBoardType];
id plist = [pb propertyListForType:VimPboardType];
if ([plist isKindOfClass:[NSArray class]] && [plist count] == 2) {
id obj = [plist objectAtIndex:1];
if ([obj isKindOfClass:[NSString class]]) {
@@ -718,13 +718,13 @@ clip_mch_set_selection(VimClipboard *cbd)
// See clip_mch_request_selection() for info on pasteboard types.
NSPasteboard *pb = [NSPasteboard generalPasteboard];
NSArray *supportedTypes = [NSArray arrayWithObjects:VimPBoardType,
NSArray *supportedTypes = [NSArray arrayWithObjects:VimPboardType,
NSStringPboardType, nil];
[pb declareTypes:supportedTypes owner:nil];
NSNumber *motion = [NSNumber numberWithInt:motion_type];
NSArray *plist = [NSArray arrayWithObjects:motion, string, nil];
[pb setPropertyList:plist forType:VimPBoardType];
[pb setPropertyList:plist forType:VimPboardType];
[pb setString:string forType:NSStringPboardType];
@@ -1818,8 +1818,17 @@ gui_macvim_add_to_find_pboard(char_u *pat)
if (!s) return;
NSPasteboard *pb = [NSPasteboard pasteboardWithName:NSFindPboard];
[pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
[pb setString:s forType:NSStringPboardType];
NSArray *supportedTypes = [NSArray arrayWithObjects:VimFindPboardType,
NSStringPboardType, nil];
[pb declareTypes:supportedTypes owner:nil];
// Put two entries on the Find pasteboard:
// * the pattern Vim uses
// * same as above but with some backslash escaped characters removed
// The second entry will be used by other applications when taking entries
// off the Find pasteboard, whereas MacVim will use the first if present.
[pb setString:s forType:VimFindPboardType];
[pb setString:[s stringByRemovingFindPatterns] forType:NSStringPboardType];
}
void