The R Project SVN R-packages

Rev

Rev 7916 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7916 Rev 8075
Line 474... Line 474...
474
 
474
 
475
	}
475
	}
476
 
476
 
477
}
477
}
478
 
478
 
-
 
479
- (NSUInteger) positionAtLine: (NSUInteger) line {
-
 
480
	NSArray *lines = [self lineIndices];
-
 
481
	if (line < [lines count]) {
-
 
482
		NSUInteger pos = [NSArrayObjectAtIndex(lines, line) unsignedIntegerValue];
-
 
483
		if (pos) pos--;
-
 
484
		return pos;
-
 
485
	}
-
 
486
	return [[clientView string] length];
-
 
487
}
-
 
488
 
479
- (void)mouseDown:(NSEvent *)theEvent
489
- (void)mouseDown:(NSEvent *)theEvent
480
{
490
{
481
 
491
 
482
	NSUInteger  line;
492
	NSUInteger  line;
483
	NSTextView  *view;
493
	NSTextView  *view;
Line 488... Line 498...
488
	NSPoint p = [self convertPoint:[theEvent locationInWindow] fromView:nil];
498
	NSPoint p = [self convertPoint:[theEvent locationInWindow] fromView:nil];
489
 
499
 
490
	line = [self lineNumberForLocation:p.y];
500
	line = [self lineNumberForLocation:p.y];
491
 
501
 
492
	// Check if click was inside folding marker
502
	// Check if click was inside folding marker
-
 
503
	if (line != NSNotFound && isFoldingEnabled &&
493
	if(isFoldingEnabled && ((NSWidth([self bounds]) - RULER_MARGIN)+3) - p.x >= 0 && ((NSWidth([self bounds]) - RULER_MARGIN)-3) - p.x < 7) {
504
	    ((NSWidth([self bounds]) - RULER_MARGIN)+3) - p.x >= 0 && ((NSWidth([self bounds]) - RULER_MARGIN)-3) - p.x < 7) {
494
 
-
 
-
 
505
		if (line < 1) line = 1;
495
		NSUInteger caretPosition = 0;
506
		NSUInteger caretPosition = 0;
496
		NSArray *lines           = [self lineIndices];
507
		NSArray *lines           = [self lineIndices];
497
		NSInteger index = [NSArrayObjectAtIndex(lines, line-1) unsignedIntegerValue];
508
		NSInteger index = [NSArrayObjectAtIndex(lines, line-1) unsignedIntegerValue];
498
		
509
		
499
		// Check for folding markers
510
		// Check for folding markers
500
		NSRange r;
511
		NSRange r;
501
		NSUInteger selectionEnd = 0;
-
 
502
		if (line < [lines count]) {
-
 
503
			selectionEnd = [NSArrayObjectAtIndex(lines, line) unsignedIntegerValue] - 1;
-
 
504
		} else {
-
 
505
			selectionEnd = [[clientView string] length];
512
		NSUInteger selectionEnd = [self positionAtLine: line];
506
		}
-
 
507
 
513
 
508
		if(index < 0 || (selectionEnd - index) >= [[clientView string] length]) {
514
		if(index < 0 || (selectionEnd - index) >= [[clientView string] length])
509
			return;
515
			return;
510
		}
-
 
511
 
516
 
512
		r = NSMakeRange(index, selectionEnd - index);
517
		r = NSMakeRange(index, selectionEnd - index);
513
 
518
 
514
		NSInteger foldItem = 0;
519
		NSInteger foldItem = 0;
515
		unichar c;
520
		unichar c;
Line 517... Line 522...
517
		if(r.length) {
522
		if(r.length) {
518
			foldItem = [(RScriptEditorTextView*)clientView foldStatusAtIndex:NSMaxRange(r)-1];
523
			foldItem = [(RScriptEditorTextView*)clientView foldStatusAtIndex:NSMaxRange(r)-1];
519
		}
524
		}
520
		
525
		
521
		if(foldItem < 2) {
526
		if(foldItem < 2) {
522
			caretPosition = [NSArrayObjectAtIndex([self lineIndices], line) unsignedIntegerValue];
-
 
523
			if(caretPosition > 0) caretPosition--;
527
			caretPosition = [self positionAtLine: line];
524
		} else {
528
		} else {
525
			caretPosition = index;
529
			caretPosition = index;
526
		}
530
		}
527
 
531
 
528
		NSUInteger stringLength = [[clientView string] length];
532
		NSUInteger stringLength = [[clientView string] length];
Line 678... Line 682...
678
			endLine = line;
682
			endLine = line;
679
		} else {
683
		} else {
680
			startLine = line;
684
			startLine = line;
681
			endLine = dragSelectionStartLine;
685
			endLine = dragSelectionStartLine;
682
		}
686
		}
683
 
-
 
-
 
687
		if (startLine < 1) startLine = 1;
-
 
688
		if (startLine > [lines count]) return;
684
		selectionStart = [NSArrayObjectAtIndex(lines, (startLine - 1)) unsignedIntegerValue];
689
		selectionStart = [NSArrayObjectAtIndex(lines, (startLine - 1)) unsignedIntegerValue];
685
		if (endLine < [lines count]) {
690
		if (endLine < [lines count]) {
686
			selectionEnd = [NSArrayObjectAtIndex(lines, endLine) unsignedIntegerValue];
691
			selectionEnd = [NSArrayObjectAtIndex(lines, endLine) unsignedIntegerValue];
687
		} else {
692
		} else {
688
			selectionEnd = [[view string] length];
693
			selectionEnd = [[view string] length];