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])];
}