Add |-computeLineIndex| to map the first character index of a frame rectangle to...
authorRobert Sesek <rsesek@bluestatic.org>
Wed, 12 Jan 2011 03:28:24 +0000 (22:28 -0500)
committerRobert Sesek <rsesek@bluestatic.org>
Sun, 16 Jan 2011 04:45:08 +0000 (23:45 -0500)
Source/BSSourceView.mm

index 4a728a179c8aab6f0536fe249a156d87f01ac025..a7628039683e0ff6f7156ccf5c1fb191d3a67c83 100644 (file)
@@ -22,6 +22,7 @@
 - (void)setupViews;
 - (void)errorHighlightingFile:(NSNotification*)notif;
 - (void)setPlainTextStringFromFile:(NSString*)filePath;
+- (void)computeLineIndex;
 @end
 
 @implementation BSSourceView
     // If the PHP executable is not available then the NSTask will throw an exception
     [self setPlainTextStringFromFile:f];
   }
+
+  [self computeLineIndex];
 }
 
 /**
     [file release];
     file = [path copy];
   }
+
+  [self computeLineIndex];
 }
 
 /**
   [textView_ setString:contents];
 }
 
+/**
+ * Iterates over the text storage system and computes a map of line numbers to
+ * first character index for a line's frame rectangle.
+ */
+- (void)computeLineIndex
+{
+  lineIndex_.clear();
+
+  NSString* text = [textView_ string];
+  NSUInteger stringLength = [text length];
+  NSUInteger index = 0;
+
+  while (index < stringLength) {
+    lineIndex_.push_back(index);
+    index = NSMaxRange([text lineRangeForRange:NSMakeRange(index, 0)]);
+  }
+
+  NSUInteger lineEnd, contentEnd;
+  [text getLineStart:NULL
+                 end:&lineEnd
+         contentsEnd:&contentEnd
+            forRange:NSMakeRange(lineIndex_.back(), 0)];
+  if (contentEnd < lineEnd)
+    lineIndex_.push_back(index);
+
+  NSLog(@"line count = %d", lineIndex_.size());
+}
+
+// Drag Handlers ///////////////////////////////////////////////////////////////
+
 /**
  * Validates an initiated drag operation.
  */