Implement NSTextFinder protocol on NSTextView.

This commit is contained in:
Gregory John Casamento 2020-08-03 07:11:38 -04:00
parent 3030efa9f7
commit 405b9bae2f
4 changed files with 73 additions and 8 deletions

View file

@ -115,21 +115,24 @@ APPKIT_EXPORT NSPasteboardTypeTextFinderOptionKey const NSTextFinderMatchingType
- (NSString *) string;
- (NSString *)stringAtIndex:(NSUInteger)characterIndex effectiveRange:(NSRangePointer)outRange endsWithSearchBoundary:(BOOL *)outFlag;
- (NSUInteger)stringLength;
- (NSString *) stringAtIndex: (NSUInteger)characterIndex
effectiveRange: (NSRangePointer)outRange
endsWithSearchBoundary: (BOOL *)outFlag;
- (NSUInteger) stringLength;
- (NSRange) firstSelectedRange;
- (NSArray *) selectedRanges;
- (void) setSelectedRanges: (NSArray *)ranges;
- (void)scrollRangeToVisible:(NSRange)range;
- (void) scrollRangeToVisible:(NSRange)range;
- (BOOL) shouldReplaceCharactersInRanges: (NSArray *)ranges withStrings: (NSArray *)strings;
- (void) replaceCharactersInRange: (NSRange)range withString: (NSString *)string;
- (void) didReplaceCharacters;
- (NSView *) contentViewAtIndex: (NSUInteger)index effectiveCharacterRange: (NSRangePointer)outRange;
- (NSArray *) rectsForCharacterRange: (NSRange)range;
- (NSArray *) visibleCharacterRanges;
- (void)drawCharactersInRange: (NSRange)range forContentView: (NSView *)view;
- (void) drawCharactersInRange: (NSRange)range forContentView: (NSView *)view;
@end
@ -148,8 +151,6 @@ APPKIT_EXPORT NSPasteboardTypeTextFinderOptionKey const NSTextFinderMatchingType
@end
#if defined(__cplusplus)
}
#endif

View file

@ -34,6 +34,7 @@
#import <GNUstepBase/GSVersionMacros.h>
#import <AppKit/NSText.h>
#import <AppKit/NSTextFinder.h>
#import <AppKit/NSInputManager.h>
#import <AppKit/NSDragging.h>
#import <AppKit/NSTextAttachment.h>
@ -92,7 +93,7 @@ be stored in the NSTextView. Non-persistant attributes don't, and should
therefore be stored in the NSLayoutManager to avoid problems.
*/
@interface NSTextView : NSText <NSTextInput, NSUserInterfaceValidations>
@interface NSTextView : NSText <NSTextInput, NSUserInterfaceValidations, NSTextFinderClient>
{
/* These attributes are shared by all text views attached to a layout
manager. Any changes must be replicated in all those text views. */
@ -247,6 +248,9 @@ therefore be stored in the NSLayoutManager to avoid problems.
// Text checking (spelling/grammar)
NSTimer *_textCheckingTimer;
NSRect _lastCheckedRect;
// NSTextFinder vars...
NSArray *_selectedRanges;
}

View file

@ -17,7 +17,6 @@ MISSING HEADERS ( * = difficult, - = quick, + = placeholder )
> NSItemProvider.h +
> NSMenuToolbarItem.h -
> NSOpenGLLayer.h
> NSRuleEditor.h *
> NSStackView.h *
> NSTableCellView.h *
> NSTableRowView.h *

View file

@ -6078,6 +6078,67 @@ configuation! */
withTextView: self];
}
// NSTextFinder methods implementation...
// isSelectable, isEditable, string, selectedRanges, setSelectedRanges
// implemented by NSTextView already...
- (BOOL) allowsMultipleSelection
{
return NO;
}
- (NSString *) stringAtIndex: (NSUInteger)characterIndex
effectiveRange: (NSRangePointer)outRange
endsWithSearchBoundary: (BOOL *)outFlag
{
return nil;
}
- (NSUInteger) stringLength
{
return [[self string] length];
}
- (NSRange) firstSelectedRange
{
NSString *rangeString = [[self selectedRanges] objectAtIndex: 0];
return NSRangeFromString(rangeString);
}
- (BOOL) shouldReplaceCharactersInRanges: (NSArray *)ranges withStrings: (NSArray *)strings
{
return YES;
}
- (void) replaceCharactersInRange: (NSRange)range withString: (NSString *)string
{
// nothing...
}
- (void) didReplaceCharacters
{
// nothing...
}
- (NSView *) contentViewAtIndex: (NSUInteger)index effectiveCharacterRange: (NSRangePointer)outRange
{
return nil;
}
- (NSArray *) rectsForCharacterRange: (NSRange)range
{
return nil;
}
- (NSArray *) visibleCharacterRanges
{
return nil;
}
- (void) drawCharactersInRange: (NSRange)range forContentView: (NSView *)view
{
}
@end