0

I'm observing a strange behavior in my NSTextView.

Assume there are multiple lines (separated by enter key presses) and when I keep pressing tabs, the whole paragraph turns into bulleted lines.

I did set the tabStops and enabled the Ruler to see the tabStops as mentioned in Premature line wrapping in NSTextView when tabs are used

For an empty NSTextView it works fine, but when I apply it to an existing text, even though the tabStops are properly set, there is this strange behavior of turning into bulleted paragraph when pressing tabs.

Here is my code used to retrieve the existing string in the NSTextView and to set the tabStops

- (IBAction)formatTextView:(EditorTextView *)editorTextView tableWidth:(double) width
{
    int cnt;
    int numStops;
    int tabInterval = 30;

    NSTextTab *tabStop;

    //attributes for attributed String of TextView
    NSMutableDictionary* attrs = [[[editorTextView textStorage] attributesAtIndex:0 effectiveRange:NULL] mutableCopy];
    NSParagraphStyle *paraStyle = [attrs objectForKey:NSParagraphStyleAttributeName];
    NSMutableParagraphStyle *paraStyleM = [paraStyle mutableCopy];

    // This first clears all tab stops, then adds tab stops, at desired intervals...
    [paraStyle setTabStops:[NSArray array]];

    for (cnt = 1; cnt <= numStops; cnt++) {
        tabStop = [[NSTextTab alloc] initWithType:NSLeftTabStopType location: tabInterval * (cnt)];
        [paraStyleM addTabStop:tabStop];
    }

    [attrs setObject:paraStyleM forKey:NSParagraphStyleAttributeName];
    [[editorTextView textStorage] addAttributes:attrs range:NSMakeRange(0, [[[editorTextView textStorage] string] length])];
}
Community
  • 1
  • 1
SajithP
  • 592
  • 8
  • 19

1 Answers1

1

Is your existing text from HTML? I’m guessing it’s got some kind of <ul> thing going on in it.

They only recently (last six years?) hacked HTML ordered list and unordered list support into NSTextView to support richer messages in Mail, and it’s still pretty ugly.

Wil Shipley
  • 9,343
  • 35
  • 59
  • Nope :( It's just plain text. It happens for almost all the types of text with and without bullets… Thanks a lot for your response. – SajithP Feb 07 '14 at 04:09
  • In the debugger, could you do a “po editorTextView.textStorage” and append the result before / after you add your style? – Wil Shipley Feb 07 '14 at 06:59