aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/NoodleLineNumberView.h3
-rw-r--r--Source/NoodleLineNumberView.m65
2 files changed, 67 insertions, 1 deletions
diff --git a/Source/NoodleLineNumberView.h b/Source/NoodleLineNumberView.h
index 7d12d47d..85316dd0 100644
--- a/Source/NoodleLineNumberView.h
+++ b/Source/NoodleLineNumberView.h
@@ -39,6 +39,9 @@
NSColor *textColor;
NSColor *alternateTextColor;
NSColor *backgroundColor;
+
+ // Add support for selection by clicking/dragging
+ unsigned dragSelectionStartLine;
}
- (id)initWithScrollView:(NSScrollView *)aScrollView;
diff --git a/Source/NoodleLineNumberView.m b/Source/NoodleLineNumberView.m
index d1ecbd96..a4383102 100644
--- a/Source/NoodleLineNumberView.m
+++ b/Source/NoodleLineNumberView.m
@@ -28,7 +28,7 @@
//
// This version of the NoodleLineNumberView for Sequel Pro removes marker
-// functionality.
+// functionality and adds selection by clicking on the ruler.
#import "NoodleLineNumberView.h"
@@ -439,6 +439,69 @@
}
}
+- (void)mouseDown:(NSEvent *)theEvent
+{
+ NSPoint location;
+ unsigned line;
+ NSTextView *view;
+
+ if (![[self clientView] isKindOfClass:[NSTextView class]]) return;
+ view = (NSTextView *)[self clientView];
+
+ location = [self convertPoint:[theEvent locationInWindow] fromView:nil];
+ line = [self lineNumberForLocation:location.y];
+ dragSelectionStartLine = line;
+
+ if (line != NSNotFound)
+ {
+ unsigned int selectionStart, selectionEnd;
+ NSMutableArray *lines = [self lineIndices];
+
+ selectionStart = [[lines objectAtIndex:(line - 1)] unsignedIntValue];
+ if (line < [lines count]) {
+ selectionEnd = [[lines objectAtIndex:line] unsignedIntValue];
+ } else {
+ selectionEnd = [[view string] length];
+ }
+ [view setSelectedRange:NSMakeRange(selectionStart, selectionEnd - selectionStart)];
+ }
+}
+
+- (void)mouseDragged:(NSEvent *)theEvent
+{
+ NSPoint location;
+ unsigned line, startLine, endLine;
+ NSTextView *view;
+
+ if (![[self clientView] isKindOfClass:[NSTextView class]] || dragSelectionStartLine == NSNotFound) return;
+ view = (NSTextView *)[self clientView];
+
+ location = [self convertPoint:[theEvent locationInWindow] fromView:nil];
+ line = [self lineNumberForLocation:location.y];
+
+ if (line != NSNotFound)
+ {
+ unsigned int selectionStart, selectionEnd;
+ NSMutableArray *lines = [self lineIndices];
+ if (line >= dragSelectionStartLine) {
+ startLine = dragSelectionStartLine;
+ endLine = line;
+ } else {
+ startLine = line;
+ endLine = dragSelectionStartLine;
+ }
+
+ selectionStart = [[lines objectAtIndex:(startLine - 1)] unsignedIntValue];
+ if (endLine < [lines count]) {
+ selectionEnd = [[lines objectAtIndex:endLine] unsignedIntValue];
+ } else {
+ selectionEnd = [[view string] length];
+ }
+ [view setSelectedRange:NSMakeRange(selectionStart, selectionEnd - selectionStart)];
+ }
+
+ [view autoscroll:theEvent];
+}
#pragma mark NSCoding methods