NSTextFinder: endless loops asking for string at index that doesn't exist.
NSTextFinder: endless loops asking for string at index that doesn't exist.
- Subject: NSTextFinder: endless loops asking for string at index that doesn't exist.
- From: Eric Slosser <email@hidden>
- Date: Wed, 28 Mar 2012 16:58:16 -0400
I'm using the NSTextFinder API with the stringAtIndex:len:effectiveRange: style of exposing the text.
I have a test case which has 4 strings in it, "foo1" .. "foo4". I show the findbar, type 'foo', and click the 'find next' control.
Here are the calls that my client receives and the results being passed back.
firstSelectedRange = {0, 0} (char)
stringLength:16
firstSelectedRange = {0, 0} (char)
stringAtIndex:0 len:4 effRange:{0, 4} 'foo1'
stringAtIndex:4 len:4 effRange:{4, 4} 'foo2'
stringAtIndex:8 len:4 effRange:{8, 4} 'foo3'
stringAtIndex:12 len:4 effRange:{12, 4} 'foo4'
setFirstSelectedRange = {0, 3}
KESIImageView+Finding scrollRangeToVisible: = {0,3}
So far, so good. But when I check the replace checkbox, then click the replace control, I see the following:
--- replace "foo" with "BA"
stringLength:16
firstSelectedRange = {0, 3} (char)
replaceCharactersInRange: {0, 3} withString:'BA'
setFirstSelectedRange = {0, 2}
firstSelectedRange = {0, 2} (char)
stringAtIndex:2 len:3 effRange:{0, 3} 'BA1'
stringAtIndex:3 len:4 effRange:{3, 4} 'foo2'
stringAtIndex:7 len:4 effRange:{7, 4} 'foo3'
stringAtIndex:11 len:4 effRange:{11, 4} 'foo4'
stringAtIndex:15 len:0 effRange:{15, 0} '(null)'
stringAtIndex:15 len:0 effRange:{15, 0} '(null)'
stringAtIndex:15 len:0 effRange:{15, 0} '(null)'
… <endless loop>
NSTextFinder keeps asking about the string that starts at index 15, but because of the replacement, the only flattened string is only 15 chars long. My 'stringLength' is only called before the replace, not after.
Incremental searching is not enabled, so it's not that I'm forgetting to call -(void)noteClientStringWithChange.
Am I doing something wrong? How can I get NSTF to understand that the client doesn't have anything at index 15?
_______________________________________________
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