2014-02-05 15 views
0

我觀察我NSTextView一個奇怪的行爲奇怪的行爲在NSTextView。按下標籤時(即使製表位設置)

假設有多個行(分立的輸入按鍵),當我按住標籤,全段變成符號線。

我沒設置製表位並啓用標尺看到製表位在 Premature line wrapping in NSTextView when tabs are used

提到它工作正常空NSTextView,但是當我把它應用到現有的文本,即使製表位是正確的設置,當按下製表符時,會出現這種奇怪的行爲,會變成帶有段落的段落。

這裏用到我的代碼來檢索NSTextView現有的字符串,並設置製表位

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

回答

1

是從HTML您現有的文字?我猜它有一些事情正在進行。

他們只是在最近(過去六年?)砍死HTML有序列表和無序列表支持到NSTextView支持郵件更豐富的信息,它仍然是相當難看。

+0

不是:(它只是純文本,幾乎所有類型的文本都有或沒有子彈...感謝你的回覆。 – SajithP

+0

在調試器中,你可以做一個「po editorTextView.textStorage」並追加添加風格之前/之後的結果? –