mirror of
https://github.com/nickshanks/ResKnife.git
synced 2024-07-26 11:29:33 +00:00
59 lines
1.6 KiB
Objective-C
59 lines
1.6 KiB
Objective-C
#import "HexTextView.h"
|
|
|
|
@implementation HexTextView
|
|
|
|
- (id)init
|
|
{
|
|
self = [super init];
|
|
if( !self ) return self;
|
|
|
|
[self setFieldEditor:YES];
|
|
return self;
|
|
}
|
|
|
|
- (void)setSelectedRange:(NSRange)charRange affinity:(NSSelectionAffinity)affinity stillSelecting:(BOOL)flag
|
|
{
|
|
NSRange newRange = charRange;
|
|
|
|
// select whole bytes at a time (only if selecting in hex!)
|
|
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;
|
|
}
|
|
|
|
// select return character if selecting ascii
|
|
else if( self == (id) [[self delegate] ascii] )
|
|
{
|
|
// 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;
|
|
}
|
|
}
|
|
|
|
// call the superclass to update the selection
|
|
[super setSelectedRange:newRange affinity:affinity stillSelecting:NO];
|
|
}
|
|
|
|
@end
|