• 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
Controlling line-breaking in a text view
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Controlling line-breaking in a text view


  • Subject: Controlling line-breaking in a text view
  • From: Andy Kim <email@hidden>
  • Date: Sat, 9 Aug 2008 20:43:37 -0700

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?

- Andy Kim

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

  • Follow-Ups:
    • Re: Controlling line-breaking in a text view
      • From: "Ken Ferry" <email@hidden>
  • Prev by Date: Re: Challenge 18 in Hillegass Book
  • Next by Date: Re: Controlling line-breaking in a text view
  • Previous by thread: Re: generating a moveRight
  • Next by thread: Re: Controlling line-breaking in a text view
  • Index(es):
    • Date
    • Thread