Skip to content

Commit

Permalink
Fix bug from pasteboard refactoring + unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
pjrobertson committed Feb 3, 2025
1 parent 4787bc7 commit a60a4e4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Quicksilver/Code-QuickStepCore/QSObject_Pasteboard.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ id objectForPasteboardType(NSPasteboard *pasteboard, NSString *type) {
if ([PLISTTYPES containsObject:type]) {
return [pasteboard propertyListForType:type];
}
if ([NSPasteboardTypeString isEqualToString:type] || UTTypeConformsTo((__bridge CFStringRef)type, kUTTypeText) || [type hasPrefix:@"QSObject"]) {
// NOTE: The NSStringPboardType is required here, since for some stupid reason NSPasteboardTypeString != NSStringPboardType
if ([NSPasteboardTypeString isEqualToString:type] || UTTypeConformsTo((__bridge CFStringRef)type, kUTTypeText) || [type hasPrefix:@"QSObject"] || [type isEqual:NSStringPboardType]) {
if ([pasteboard stringForType:type]) {
return [pasteboard stringForType:type];
}
Expand Down
22 changes: 22 additions & 0 deletions Quicksilver/Quicksilver Tests/Quicksilver_Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,28 @@ - (void)testRightArrowIntoSynonym {
XCTAssertTrue([[i dSelector] objectValue] != proxy);
}

- (void)testCreateObjectFromRTFClipboard {
// create an rtf string in the clipboard
NSPasteboard *pboard = [NSPasteboard generalPasteboard];

NSAttributedString *rtfString = [[NSAttributedString alloc] initWithRTF:[@"{\\rtf1\\ansi\\ansicpg1252\\cocoartf1187\\cocoasubrtf340\n{\\fonttbl\\f0\\fnil\\fcharset0 Monaco;}\n{\\colortbl;\\red255\\green0\\blue0;}\n\\margl1440\\margr1440\\vieww10800\\viewh8400\\viewkind0\n\\pard\\tx720\\tx1440\\tx2160\\tx2880\\tx3600\\tx4320\\tx5040\\tx5760\\tx6480\\tx7200\\tx7920\\tx8640\\ql\\qnatural\\pardirnatural\n\n\\f0\\fs24 \\cf1 hello}" dataUsingEncoding:NSUTF8StringEncoding] documentAttributes:nil];
[pboard clearContents];
[pboard writeObjects:@[rtfString]];

// create a QSObject from the clipboard
QSObject *obj = [QSObject objectWithPasteboard:pboard];
XCTAssertTrue([obj containsType:NSPasteboardTypeRTF] && [[obj primaryType] isEqualToString:NSPasteboardTypeRTF]);

// now write this object to the pasteboard
[pboard clearContents];
XCTAssertTrue([obj putOnPasteboard:pboard]);

// read the object back from the pasteboard
QSObject *obj2 = [QSObject objectWithPasteboard:pboard];
XCTAssertTrue([obj2 containsType:NSPasteboardTypeRTF] && [[obj2 primaryType] isEqualToString:NSPasteboardTypeRTF]);

}

// test to make sure when file objects are added to the clipboard, a string of their path is also copied
- (void)testAddingFileObjectToPasteboard {
NSString *path = @"/Applications/Safari.app";
Expand Down

0 comments on commit a60a4e4

Please sign in to comment.