2002-02-02 11:48:54 +00:00
|
|
|
#import "HexTextView.h"
|
|
|
|
|
|
|
|
@implementation HexTextView
|
|
|
|
|
2002-02-14 23:24:53 +00:00
|
|
|
- (id)init
|
2002-02-02 11:48:54 +00:00
|
|
|
{
|
2002-02-14 23:24:53 +00:00
|
|
|
self = [super init];
|
|
|
|
if( !self ) return self;
|
2002-02-06 20:57:56 +00:00
|
|
|
|
2002-02-14 23:24:53 +00:00
|
|
|
[self setFieldEditor:YES];
|
|
|
|
return self;
|
2002-02-02 11:48:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setSelectedRange:(NSRange)charRange affinity:(NSSelectionAffinity)affinity stillSelecting:(BOOL)flag
|
|
|
|
{
|
|
|
|
NSRange newRange = charRange;
|
|
|
|
|
|
|
|
// select whole bytes at a time (only if selecting in hex!)
|
2002-02-06 20:57:56 +00:00
|
|
|
if( self == (id) [[self delegate] hex] )
|
|
|
|
{
|
|
|
|
// move selection offset to beginning of byte
|
|
|
|
newRange.location -= (charRange.location % 3);
|
|
|
|
newRange.length += (charRange.location % 3);
|
|
|
|
|
|
|
|
// set selection length to whole number of bytes
|
|
|
|
if( charRange.length != 0 )
|
|
|
|
newRange.length -= (newRange.length % 3) -2;
|
|
|
|
else newRange.length = 0;
|
|
|
|
|
|
|
|
// move insertion point to next byte if needs be
|
|
|
|
if( newRange.location == charRange.location -1 && newRange.length == 0 )
|
|
|
|
newRange.location += 3;
|
|
|
|
}
|
2002-02-11 01:22:17 +00:00
|
|
|
|
2002-02-06 20:57:56 +00:00
|
|
|
// select return character if selecting ascii
|
|
|
|
else if( self == (id) [[self delegate] ascii] )
|
2002-02-02 11:48:54 +00:00
|
|
|
{
|
2002-02-06 20:57:56 +00:00
|
|
|
// if ascii selection goes up to sixteenth byte on last line, select return character too
|
|
|
|
if( (charRange.length + charRange.location) % 17 == 16)
|
|
|
|
{
|
|
|
|
// if selection is zero bytes long, move insertion point to character after return
|
|
|
|
if( charRange.length == 0 )
|
|
|
|
{
|
|
|
|
// if moving back from first byte of line to previous line, skip return char
|
|
|
|
NSRange selected = [self selectedRange];
|
|
|
|
if( (selected.length + selected.location) % 17 == 0 )
|
|
|
|
newRange.location -= 1;
|
|
|
|
else newRange.location += 1;
|
|
|
|
}
|
|
|
|
else newRange.length += 1;
|
|
|
|
}
|
2002-02-02 11:48:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// call the superclass to update the selection
|
|
|
|
[super setSelectedRange:newRange affinity:affinity stillSelecting:NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|