Permalink
Browse files

also fix indentation for paragraph-style-based RTF data upon pasting

  • Loading branch information...
scrod committed Mar 17, 2011
1 parent ec57ba7 commit f7f845a0c27a3d985693bfea70a8149d2e07b7c8
Showing with 25 additions and 19 deletions.
  1. +24 −19 AttributedPlainText.m
  2. +1 −0 LinkingEditor.m
View
@@ -53,26 +53,31 @@ - (void)trimLeadingWhitespace {
}
- (void)indentTextLists {
- NSString *string = [self string];
- NSUInteger paraStart, paraEnd, contentsEnd;
- paraEnd = 0;
- while (paraEnd < [self length]) {
- [string getParagraphStart:&paraStart end:&paraEnd contentsEnd:&contentsEnd
- forRange:NSMakeRange(paraEnd, 0)];
- NSParagraphStyle *style = [self attribute:NSParagraphStyleAttributeName
- atIndex:paraStart effectiveRange:NULL];
- NSArray *textLists = [style textLists];
- if ([textLists count] > 0) {
- NSUInteger level = [textLists count] - 1;
- NSString *indent = [@"" stringByPaddingToLength:level withString: @"\t" startingAtIndex:0];
- /* Covered by restyleTextToFont
- NSRange paraRange = NSMakeRange(paraStart, contentsEnd - paraStart);
- [self removeAttribute:NSParagraphStyleAttributeName range:paraRange];
- */
- [self replaceCharactersInRange:NSMakeRange(paraStart, 1) withString:@" "]; /* Leading tab to space */
- [self replaceCharactersInRange:NSMakeRange(paraStart, 0) withString:indent]; /* Changes length */
- paraEnd += level;
+ //contributed by tewe
+ @try {
+ NSString *string = [self string];
+ NSUInteger paraStart, paraEnd, contentsEnd;
+ paraEnd = 0;
+ while (paraEnd < [self length]) {
+ [string getParagraphStart:&paraStart end:&paraEnd contentsEnd:&contentsEnd
+ forRange:NSMakeRange(paraEnd, 0)];
+ NSParagraphStyle *style = [self attribute:NSParagraphStyleAttributeName
+ atIndex:paraStart effectiveRange:NULL];
+ NSArray *textLists = [style textLists];
+ if ([textLists count] > 0) {
+ NSUInteger level = [textLists count] - 1;
+ NSString *indent = [@"" stringByPaddingToLength:level withString: @"\t" startingAtIndex:0];
+ /* Covered by restyleTextToFont
+ NSRange paraRange = NSMakeRange(paraStart, contentsEnd - paraStart);
+ [self removeAttribute:NSParagraphStyleAttributeName range:paraRange];
+ */
+ [self replaceCharactersInRange:NSMakeRange(paraStart, 1) withString:@" "]; /* Leading tab to space */
+ [self replaceCharactersInRange:NSMakeRange(paraStart, 0) withString:indent]; /* Changes length */
+ paraEnd += level;
+ }
}
+ } @catch (NSException *e) {
+ NSLog(@"indentTextLists: %@", e);
}
}
View
@@ -375,6 +375,7 @@ - (BOOL)readSelectionFromPasteboard:(NSPasteboard *)pboard type:(NSString *)type
//remove the link attribute, because it will be re-added after we paste, and restyleText would preserve it otherwise
//and we only want real URLs to be linked
[newString removeAttribute:NSLinkAttributeName range:NSMakeRange(0, [newString length])];
+ [newString indentTextLists];
[newString restyleTextToFont:[prefsController noteBodyFont] usingBaseFont:nil];
}

0 comments on commit f7f845a

Please sign in to comment.