Re: Controlling line-breaking in a text view
Re: Controlling line-breaking in a text view
- Subject: Re: Controlling line-breaking in a text view
- From: Andy Kim <email@hidden>
- Date: Tue, 12 Aug 2008 17:12:35 -0700
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
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