Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

indent TextEdit lists with tabs on import

  • Loading branch information...
commit 0bc9e96a2b365c9b30e1c451352dc33ad102e2bc 1 parent 51e9ddb
tewe authored committed
Showing with 26 additions and 0 deletions.
  1. +1 −0  AttributedPlainText.h
  2. +25 −0 AttributedPlainText.m
View
1  AttributedPlainText.h
@@ -31,6 +31,7 @@ extern NSString *NVHiddenBulletIndentAttributeName;
@interface NSMutableAttributedString (AttributedPlainText)
- (void)trimLeadingWhitespace;
+- (void)indentTextLists;
- (void)removeAttachments;
- (NSString*)prefixWithSourceString:(NSString*)source;
View
25 AttributedPlainText.m
@@ -52,6 +52,30 @@ - (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;
+ }
+ }
+}
+
- (void)removeAttachments {
unsigned loc = 0;
unsigned end = [self length];
@@ -92,6 +116,7 @@ - (NSString*)prefixWithSourceString:(NSString*)source {
- (void)santizeForeignStylesForImporting {
NSRange range = NSMakeRange(0, [self length]);
[self removeAttribute:NSLinkAttributeName range:range];
+ [self indentTextLists];
[self restyleTextToFont:[[GlobalPrefs defaultPrefs] noteBodyFont] usingBaseFont:nil];
[self addLinkAttributesForRange:range];
[self addStrikethroughNearDoneTagsForRange:range];
Please sign in to comment.
Something went wrong with that request. Please try again.