• 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: "Ken Ferry" <email@hidden>
  • Date: Tue, 12 Aug 2008 18:07:52 -0700

Hi Andy,

I'm still not familiar with the text system, so I don't know if the
proxy was a good way to do this.

But assuming it was, try implementing forwardingTargetForSelector:
instead of forwardInvocation:. It's less flexible, but much faster,
and your case doesn't require the flexibility.

-Ken

On Tue, Aug 12, 2008 at 5:12 PM, Andy Kim <email@hidden> wrote:
> Many thanks to everyone who helped in this thread.
>
>> 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.
>
> Matt,
>
> I may have to go with your solution for cell drawing although I'm hesitant
> before proceeding. The program has to make it seem like the character is not
> there and that could get a bit hairy with all the delete operations and copy
> paste, but I'm leaning towards that solution because I can't figure out how
> to get an outline view cell to draw efficiently using a custom
> NSTextStorage.
>
> In a text view though, Ken's suggestion of subclassing a NSTextStorage and
> overriding lineBreakBeforeIndex:withinRange: worked out well. It turns out
> that subclassing is a little tricky because NSTextStorage is not a concrete
> class so here's what I did for posterity sake:
>
> @interface PFTextStorage : NSProxy
> {
>        NSTextStorage *realStorage;
> }
> - (id)initWithTextStorage:(NSTextStorage *)storage;
> @end
>
>
> @implementation PFTextStorage
>
> - (id)init
> {
>        realStorage = [[NSTextStorage alloc] init];
>        return self;
> }
>
> - (id)initWithTextStorage:(NSTextStorage *)storage
> {
>        realStorage = [storage retain];
>        return self;
> }
>
> - (void)dealloc
> {
>        [realStorage release];
>        [super dealloc];
> }
>
> - (BOOL)respondsToSelector:(SEL)aSelector
> {
>        return [realStorage respondsToSelector:aSelector];
> }
>
> - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
> {
>        return [realStorage methodSignatureForSelector:aSelector];
> }
>
> - (void)forwardInvocation:(NSInvocation *)invocation
> {
>        SEL aSelector = [invocation selector];
>
>   if ([realStorage respondsToSelector:aSelector])
>       [invocation invokeWithTarget:realStorage];
>   else
>       [realStorage doesNotRecognizeSelector:aSelector];
> }
>
> - (NSUInteger)lineBreakBeforeIndex:(NSUInteger)index
> withinRange:(NSRange)aRange
> {
>        NSString *string = [realStorage string];
>        NSUInteger breakIndex = [realStorage lineBreakBeforeIndex:index
> withinRange:aRange];
>        if (breakIndex >= 2 &&
>                [string characterAtIndex:breakIndex-1] == '/' &&
>                [[NSCharacterSet whitespaceCharacterSet]
> characterIsMember:[string characterAtIndex:breakIndex-2]])
>                return breakIndex - 2;
>
>        return breakIndex;
> }
>
> @end
>
> _______________________________________________
>
> 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
>
_______________________________________________

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: Ross Carter <email@hidden>
References: 
 >Controlling line-breaking in a text view (From: Andy Kim <email@hidden>)
 >Re: Controlling line-breaking in a text view (From: "Ken Ferry" <email@hidden>)
 >Re: Controlling line-breaking in a text view (From: Andy Kim <email@hidden>)

  • Prev by Date: Subclassing NSTextView
  • Next by Date: Re: Accessing memory of another application?
  • 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