aboutsummaryrefslogtreecommitdiffstats
path: root/Source/CMTextView.m
diff options
context:
space:
mode:
Diffstat (limited to 'Source/CMTextView.m')
-rw-r--r--Source/CMTextView.m32
1 files changed, 32 insertions, 0 deletions
diff --git a/Source/CMTextView.m b/Source/CMTextView.m
index a19edb25..b6bb1229 100644
--- a/Source/CMTextView.m
+++ b/Source/CMTextView.m
@@ -194,6 +194,38 @@ YY_BUFFER_STATE yy_scan_string (const char *);
}
}
+
+/*
+ * Selects the line lineNumber relatively to a selection (if given) and scrolls to it
+ */
+- (void) selectLineNumber:(unsigned int)lineNumber ignoreLeadingNewLines:(BOOL)ignLeadingNewLines
+{
+ NSRange selRange;
+ NSArray *lineRanges;
+ if([self selectedRange].length)
+ lineRanges = [[[self string] substringWithRange:[self selectedRange]] lineRangesForRange:NSMakeRange(0, [self selectedRange].length)];
+ else
+ lineRanges = [[self string] lineRangesForRange:NSMakeRange(0, [[self string] length])];
+ int offset = 0;
+ if(ignLeadingNewLines) // ignore leading empty lines
+ {
+ int arrayCount = [lineRanges count];
+ int i;
+ for (i = 0; i < arrayCount; i++) {
+ if(NSRangeFromString([lineRanges objectAtIndex:i]).length > 0)
+ break;
+ offset++;
+ }
+ }
+ selRange = NSRangeFromString([lineRanges objectAtIndex:lineNumber-1+offset]);
+
+ // adjust selRange if a selection was given
+ if([self selectedRange].length)
+ selRange.location += [self selectedRange].location;
+ [self setSelectedRange:selRange];
+ [self scrollRangeToVisible:selRange];
+}
+
/*
* Handle some keyDown events in order to provide autopairing functionality (if enabled).
*/