Skip to content

Commit

Permalink
compiler warning
Browse files Browse the repository at this point in the history
  • Loading branch information
pebble8888 committed Jan 9, 2017
1 parent b96010f commit 442eda3
Showing 1 changed file with 54 additions and 57 deletions.
111 changes: 54 additions & 57 deletions XVim/NSTextView+VimOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ @interface NSTextView ()

@interface NSTextView(VimOperationPrivate)
@property BOOL xvim_lockSyncStateFromView;
- (void)xvim_moveCursor:(NSUInteger)pos preserveColumn:(BOOL)preserve;
- (void)xvim_syncStateWithScroll:(BOOL)scroll;
- (void)xvim_syncState; // update self's properties with our variables
- (NSArray*)xvim_selectedRanges;
Expand All @@ -68,9 +67,7 @@ - (XVimRange)xvim_getMotionRange:(NSUInteger)current Motion:(XVimMotion*)motion;
- (NSRange)xvim_getOperationRangeFrom:(NSUInteger)from To:(NSUInteger)to Type:(MOTION_TYPE)type;
- (void)xvim_indentCharacterRange:(NSRange)range;
- (void)xvim_scrollCommon_moveCursorPos:(NSUInteger)lineNumber firstNonblank:(BOOL)fnb;
- (NSUInteger)xvim_lineNumberFromBottom:(NSUInteger)count;
- (NSUInteger)xvim_lineNumberAtMiddle;
- (NSUInteger)xvim_lineNumberFromTop:(NSUInteger)count;
- (NSRange)xvim_search:(NSString*)regex count:(NSUInteger)count option:(MOTION_OPTION)opt forward:(BOOL)forward;
- (void)xvim_swapCaseForRange:(NSRange)range;
- (void)xvim_registerInsertionPointForUndo;
Expand All @@ -81,6 +78,32 @@ @implementation NSTextView (VimOperation)

#pragma mark internal helpers

/**
* Returns start and end position of the specified motion.
* Note that this may return NSNotFound
**/

- (void)xvim_moveCursor:(NSUInteger)pos preserveColumn:(BOOL)preserve{
// This method only update the internal state(like self.insertionPoint)

if( pos > [self xvim_string].length){
//ERROR_LOG(@"[%p]Position specified exceeds the length of the text", self);
pos = [self xvim_string].length;
}

if( self.cursorMode == CURSOR_MODE_COMMAND && !(self.selectionMode == XVIM_VISUAL_BLOCK)){
self.insertionPoint = [self.textStorage convertToValidCursorPositionForNormalMode:pos];
}else{
self.insertionPoint = pos;
}

if( !preserve ){
self.preservedColumn = [self.textStorage xvim_columnOfIndex:self.insertionPoint];
}

//DEBUG_LOG(@"[%p]New Insertion Point:%d Preserved Column:%d", self, self.insertionPoint, self.preservedColumn);
}

- (void)_xvim_insertSpaces:(NSUInteger)count replacementRange:(NSRange)replacementRange
{
if (count || replacementRange.length) {
Expand Down Expand Up @@ -2197,6 +2220,34 @@ - (void)xvim_syncStateFromView{
self.selectionBegin = self.insertionPoint;
}

- (NSUInteger)xvim_lineNumberFromTop:(NSUInteger)count{
NSAssert( 0 != count , @"count starts from 1" );
if( count > [self xvim_numberOfLinesInVisibleRect] ){
count = [self xvim_numberOfLinesInVisibleRect];
}
NSScrollView *scrollView = [self enclosingScrollView];
NSTextContainer *container = [self textContainer];
NSRect glyphRect = [[self layoutManager] boundingRectForGlyphRange:[self selectedRange] inTextContainer:container];
NSPoint top = [[scrollView contentView] bounds].origin;
// Add height of "count" of lines to downwards
top.y += (NSHeight(glyphRect) / 2.0f) + (NSHeight(glyphRect) * (count-1));
return [self.textStorage xvim_lineNumberAtIndex:[[scrollView documentView] characterIndexForInsertionAtPoint:top]];
}

- (NSUInteger)xvim_lineNumberFromBottom:(NSUInteger)count { // L
NSAssert( 0 != count , @"count starts from 1" );
if( count > [self xvim_numberOfLinesInVisibleRect] ){
count = [self xvim_numberOfLinesInVisibleRect];
}
NSScrollView *scrollView = [self enclosingScrollView];
NSTextContainer *container = [self textContainer];
NSRect glyphRect = [[self layoutManager] boundingRectForGlyphRange:[self selectedRange] inTextContainer:container];
NSPoint bottom = [[scrollView contentView] bounds].origin;
// This calculate the position of the bottom line and substruct height of "count" of lines to upwards
bottom.y += [[scrollView contentView] bounds].size.height - (NSHeight(glyphRect) / 2.0f) - (NSHeight(glyphRect) * (count-1));
return [self.textStorage xvim_lineNumberAtIndex:[[scrollView documentView] characterIndexForInsertionAtPoint:bottom]];
}

@end


Expand All @@ -2212,32 +2263,6 @@ - (void)setXvim_lockSyncStateFromView:(BOOL)lock{
[self setBool:lock forName:@"lockSyncStateFromView"];
}

/**
* Returns start and end position of the specified motion.
* Note that this may return NSNotFound
**/

- (void)xvim_moveCursor:(NSUInteger)pos preserveColumn:(BOOL)preserve{
// This method only update the internal state(like self.insertionPoint)

if( pos > [self xvim_string].length){
//ERROR_LOG(@"[%p]Position specified exceeds the length of the text", self);
pos = [self xvim_string].length;
}

if( self.cursorMode == CURSOR_MODE_COMMAND && !(self.selectionMode == XVIM_VISUAL_BLOCK)){
self.insertionPoint = [self.textStorage convertToValidCursorPositionForNormalMode:pos];
}else{
self.insertionPoint = pos;
}

if( !preserve ){
self.preservedColumn = [self.textStorage xvim_columnOfIndex:self.insertionPoint];
}

//DEBUG_LOG(@"[%p]New Insertion Point:%d Preserved Column:%d", self, self.insertionPoint, self.preservedColumn);
}

- (void)_adjustCursorPosition{
//TRACE_LOG(@"[%p]ENTER", self);
if( ![self.textStorage isValidCursorPosition:self.insertionPoint] ){
Expand Down Expand Up @@ -2643,41 +2668,13 @@ - (void)xvim_scrollCommon_moveCursorPos:(NSUInteger)lineNumber firstNonblank:(BO
}
}

- (NSUInteger)xvim_lineNumberFromBottom:(NSUInteger)count { // L
NSAssert( 0 != count , @"count starts from 1" );
if( count > [self xvim_numberOfLinesInVisibleRect] ){
count = [self xvim_numberOfLinesInVisibleRect];
}
NSScrollView *scrollView = [self enclosingScrollView];
NSTextContainer *container = [self textContainer];
NSRect glyphRect = [[self layoutManager] boundingRectForGlyphRange:[self selectedRange] inTextContainer:container];
NSPoint bottom = [[scrollView contentView] bounds].origin;
// This calculate the position of the bottom line and substruct height of "count" of lines to upwards
bottom.y += [[scrollView contentView] bounds].size.height - (NSHeight(glyphRect) / 2.0f) - (NSHeight(glyphRect) * (count-1));
return [self.textStorage xvim_lineNumberAtIndex:[[scrollView documentView] characterIndexForInsertionAtPoint:bottom]];
}

- (NSUInteger)xvim_lineNumberAtMiddle{
NSScrollView *scrollView = [self enclosingScrollView];
NSPoint center = [[scrollView contentView] bounds].origin;
center.y += [[scrollView contentView] bounds].size.height / 2;
return [self.textStorage xvim_lineNumberAtIndex:[[scrollView documentView] characterIndexForInsertionAtPoint:center]];
}

- (NSUInteger)xvim_lineNumberFromTop:(NSUInteger)count{
NSAssert( 0 != count , @"count starts from 1" );
if( count > [self xvim_numberOfLinesInVisibleRect] ){
count = [self xvim_numberOfLinesInVisibleRect];
}
NSScrollView *scrollView = [self enclosingScrollView];
NSTextContainer *container = [self textContainer];
NSRect glyphRect = [[self layoutManager] boundingRectForGlyphRange:[self selectedRange] inTextContainer:container];
NSPoint top = [[scrollView contentView] bounds].origin;
// Add height of "count" of lines to downwards
top.y += (NSHeight(glyphRect) / 2.0f) + (NSHeight(glyphRect) * (count-1));
return [self.textStorage xvim_lineNumberAtIndex:[[scrollView documentView] characterIndexForInsertionAtPoint:top]];
}

- (NSRange)xvim_search:(NSString*)regex count:(NSUInteger)count option:(MOTION_OPTION)opt forward:(BOOL)forward{
NSRange ret = NSMakeRange(NSNotFound, 0);
if( forward ){
Expand Down

0 comments on commit 442eda3

Please sign in to comment.