• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Controlling line-breaking in a text view
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Controlling line-breaking in a text view


  • Subject: Re: Controlling line-breaking in a text view
  • From: Matt Neuburg <email@hidden>
  • Date: Sun, 10 Aug 2008 05:33:20 -0700
  • Thread-topic: Controlling line-breaking in a text view

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@hidden> 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@hidden, <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 (email@hidden)

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:

This email sent to email@hidden

  • Prev by Date: Re: Does [NSApp setApplicationIconImage] leak memory?
  • Next by Date: CGImage masking via CGCreateImageWithMask getting odd results
  • Previous by thread: Re: Controlling line-breaking in a text view
  • Next by thread: Re: Controlling line-breaking in a text view
  • Index(es):
    • Date
    • Thread