Text alignment
David Dunham
dunham at mac.com
Mon Aug 13 23:20:44 PDT 2007
I've been trying to update an alignment menu for an NSTextView, to
show the current alignment (left, center, justified, right). I
thought this was working, but an NSTextView with multiple paragraphs
always shows as NSJustifiedTextAlignment.
In my validateMenuItem: I have
} else if (cmd == @selector(alignJustified:)) {
sel = [self selectedRange];
if (sel.length == 0)
p = [[self typingAttributes] objectForKey:
NSParagraphStyleAttributeName];
else
p = [[self textStorage] attribute: NSParagraphStyleAttributeName
atIndex: sel.location effectiveRange: nil];
[anItem setState: [p alignment] == NSJustifiedTextAlignment];
}
and this is indeed set in the dictionary (p).
Elsewhere, I'm using -[NSText alignment] to get the alignment. It too
is returning NSJustifiedTextAlignment when an NSTextView has multiple
alignments (in different paragraphs). There doesn't have to be any
justified text at all for this to happen.
I'm guessing this is probably a bug. Has anyone else run into it? Is
there a workaround for Tiger? (I haven't tried under Leopard yet.)
David Dunham www.pensee.com/dunham/
Imagination is more important than knowledge. -- Albert Einstein
More information about the MacOSX-dev
mailing list