diff --git a/ChangeLog b/ChangeLog index abdb41e3e..ddf444b71 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-01-26 Fred Kiefer + + * Source/NSTextView.m (-copySelection, -pasteSelection): Add new X + secondary selection behaviour. + See http://www.freedesktop.org/wiki/Specifications/ClipboardsWiki + 2008-01-19 Fred Kiefer * Source/GSFontInfo.m: diff --git a/Source/NSTextView.m b/Source/NSTextView.m index 569f54b9e..a7050e1ea 100644 --- a/Source/NSTextView.m +++ b/Source/NSTextView.m @@ -5042,16 +5042,73 @@ configuation! */ special section pasteboard */ - (void) copySelection { - [self writeSelectionToPasteboard: [NSPasteboard pasteboardWithName: @"Selection"] - type: NSStringPboardType]; +#if 1 + NSString *newSelection; + NSString *oldSelection; + NSRange range = _layoutManager->_selected_range; + + if (range.location != NSNotFound && range.length != 0) + { + newSelection = [[self string] substringWithRange: range]; + oldSelection = [[NSPasteboard pasteboardWithName: @"Selection"] + stringForType: NSStringPboardType]; + + if (oldSelection != nil && + ![newSelection isEqualToString: oldSelection]) + { + NSPasteboard *secondary; + + secondary = [NSPasteboard pasteboardWithName: @"Secondary"]; + [secondary declareTypes: [NSArray arrayWithObject: NSStringPboardType] + owner: self]; + [secondary setString: oldSelection + forType: NSStringPboardType]; + } + else + { + return; + } + } + else + { + return; + } +#endif + + [self writeSelectionToPasteboard: + [NSPasteboard pasteboardWithName: @"Selection"] + type: NSStringPboardType]; } /** Extension method that pastes the current selected text from the special section pasteboard */ - (void) pasteSelection { - [self readSelectionFromPasteboard: [NSPasteboard pasteboardWithName: @"Selection"] - type: NSStringPboardType]; +#if 1 + NSString *newSelection; + NSString *oldSelection; + NSRange range = _layoutManager->_selected_range; + + if (range.location != NSNotFound && range.length != 0) + { + newSelection = [[self string] substringWithRange: range]; + oldSelection = [[NSPasteboard pasteboardWithName: @"Selection"] + stringForType: NSStringPboardType]; + + if (oldSelection != nil && + [newSelection isEqualToString: oldSelection]) + { + [self readSelectionFromPasteboard: + [NSPasteboard pasteboardWithName: @"Secondary"] + type: NSStringPboardType]; + return; + } + } +#endif + + [self readSelectionFromPasteboard: + [NSPasteboard pasteboardWithName: @"Selection"] + type: NSStringPboardType]; } @end