[Adium-commits] adium 2060:db0f678b0863: Patch from wixardy to preserve formatti...
adium-commits at adiumx.com
adium-commits at adiumx.com
Sat May 2 17:14:54 UTC 2009
details: http://hg.adiumx.com/adium/rev/db0f678b0863
revision: 2060:db0f678b0863
author: Zachary West <zacw at adiumx.com>
date: Sat May 02 13:14:49 2009 -0400
Patch from wixardy to preserve formatting when inserting a shortened URL or twitter prefix. Fixes #11095.
diffstat:
Plugins/Twitter Plugin/AITwitterURLHandler.m | 10 +++++++++-
Source/AIURLShortenerPlugin.m | 6 ++++--
2 files changed, 13 insertions(+), 3 deletions(-)
diffs (44 lines):
diff -r 36ef68b22590 -r db0f678b0863 Plugins/Twitter Plugin/AITwitterURLHandler.m
--- a/Plugins/Twitter Plugin/AITwitterURLHandler.m Sat May 02 12:52:34 2009 -0400
+++ b/Plugins/Twitter Plugin/AITwitterURLHandler.m Sat May 02 13:14:49 2009 -0400
@@ -30,6 +30,7 @@
#import <Adium/AIAccountControllerProtocol.h>
#import <Adium/AIChatControllerProtocol.h>
#import <Adium/AIInterfaceControllerProtocol.h>
+#import <Adium/AIContentControllerProtocol.h>
@implementation AITwitterURLHandler
@@ -128,7 +129,14 @@
}
if (![textView.string hasPrefix:prefix]) {
- NSMutableAttributedString *newString = [[[NSAttributedString stringWithString:prefix] mutableCopy] autorelease];
+ NSMutableAttributedString *newString;
+ if (textView.attributedString.length > 0){
+ newString = [[[textView.attributedString attributedSubstringFromRange:NSMakeRange(0, 1)] mutableCopy] autorelease];
+ [newString replaceCharactersInRange:NSMakeRange(0, 1) withString:prefix];
+ }
+ else
+ newString = [[[NSMutableAttributedString alloc] initWithString:prefix attributes:[adium.contentController defaultFormattingAttributes]] autorelease];
+
[newString appendAttributedString:textView.attributedString];
[textView setAttributedString:newString];
diff -r 36ef68b22590 -r db0f678b0863 Source/AIURLShortenerPlugin.m
--- a/Source/AIURLShortenerPlugin.m Sat May 02 12:52:34 2009 -0400
+++ b/Source/AIURLShortenerPlugin.m Sat May 02 13:14:49 2009 -0400
@@ -277,9 +277,11 @@
NSRange selectedRange = textView.selectedRange;
// Replace the current selection with the new URL
+ NSMutableDictionary *attrs = [NSMutableDictionary dictionaryWithDictionary:[textView.attributedString attributesAtIndex:selectedRange.location effectiveRange:nil]];
+ [attrs setObject:shortenedURL forKey:NSLinkAttributeName];
+
[textView.textStorage replaceCharactersInRange:selectedRange
- withAttributedString:[NSAttributedString attributedStringWithLinkLabel:shortenedURL
- linkDestination:shortenedURL]];
+ withAttributedString:[[[NSAttributedString alloc] initWithString:shortenedURL attributes:attrs] autorelease]];
// Select the inserted URL
textView.selectedRange = NSMakeRange(selectedRange.location, shortenedURL.length);
More information about the commits
mailing list