I wonder if this is a larger bug in the text system? I was going to suggest
just inserting the Unicode character "zero-width no-break space" (U+FEFF)
after the slash, but when I tried it (in TextEdit) I got the very phenomenon
you describe - the break occurs before "delete", not after.

I was able to solve the problem, though, by also inserting a "zero-width
space" (U+200B) before the slash... So there's a solution for you, but it
seems unnecessarily elaborate. m.

On Sat, 9 Aug 2008 20:43:37 -0700, Andy Kim <[EMAIL PROTECTED]> said:
>Hi,
>
>I'm having trouble figuring out how to make the text system not break
>words that begin with a '/', such as paths, when wrapping. Let's say
>that we're laying out the following line of text:
>
>=====================================
>Normally, you should never delete /Applications
>=====================================
>
>I want '/Applications' to stay intact when wrapping. By default, the
>text system wraps it the following way:
>
>=====================================
>Normally, you should never delete /
>Applications
>=====================================
>
>I'd like it to look like this:
>
>=====================================
>Normally, you should never delete
>/Applications
>=====================================
>
>After much searching, the best solution I've come up with so far is a
>subclass of NSATSTypesetter with the following method implementation
>in it:
>
>- (BOOL)shouldBreakLineByWordBeforeCharacterAtIndex:
>(NSUInteger)charIndex
>{
> NSString *string = [[[self layoutManager] textStorage] string];
>
> if (charIndex >= 1) {
>  NSTextStorage *ts = [[self layoutManager] textStorage];
>  if ([ts attribute:PFPathAttributeName atIndex:charIndex
>effectiveRange:NULL]) {
>   // Only break if the previous character is not part of the path
>   return [ts attribute:PFPathAttributeName atIndex:charIndex-1
>effectiveRange:NULL] == nil;
>  }
> }
>
> return YES;
>}
>
>I am setting the attribute PFPathAttributeName to the text storage to
>mark the path. This works somewhat, but now the problem is that after
>wrapping, the text looks like this:
>
>=====================================
>Normally, you should never
>delete /Applications
>=====================================
>
>This happens because -shouldBreakLineByWordBeforeCharacterAtIndex:
>never gets called for the '/' and the next time it gets called is for
>the 'd' in 'delete'.
>
>This modified wrapping behavior makes it seem like 'delete /
>Applications' is one word. I think it's better than the default
>behavior but still not ideal.
>
>So how can I make it wrap exactly the way I want?


-- 
matt neuburg, phd = [EMAIL PROTECTED], <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
One of the 2007 MacTech Top 25: <http://tinyurl.com/2rh4pf>
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to