This project is read-only.

Automatically wrap around when reaching the last marker/bookmark

Jan 22, 2009 at 8:18 PM
Edited Jan 22, 2009 at 8:23 PM
I've added 2 shortcuts to my ScintillaNET project that can move to the next/previous bookmarks using FindNextMarker/FindPreviousMarker. It worked well except that when you reach the last bookmark, it just sat there and did not automatically wrap around the file to the first bookmark. This is just personal preference since other people may find the existing functionality just fine as it is. For me, wrapping around seems a better fit for what i'm doing.

I post the code below so you can use it if you want. This modifies only the Lines.cs file. You probably want to modify the Markers.cs file also since there's duplicated functionalities in both files.


--- C:/Temp/ScintillaNET-45552/Branches/2.0/ScintillaNET/Line.cs Thu Jan 22 11:58:30 2009
+++ C:/Temp/MyScintillaNet/ScintillaNET/Line.cs Thu Jan 22 11:38:33 2009
@@ -205,8 +205,12 @@
   public Line FindNextMarker(uint markerMask)
   {
    int foundLine = NativeScintilla.MarkerNext(_number + 1, markerMask);
-   if (foundLine < 0)
-    return null;
+            if (foundLine < 0) {
+                foundLine = NativeScintilla.MarkerNext(1, markerMask);
+                if (foundLine < 0) {
+                    return null;
+                }
+            }
 
    return Scintilla.Lines[foundLine];
   }
@@ -229,8 +233,12 @@
   public Line FindPreviousMarker(uint markerMask)
   {
    int foundLine = NativeScintilla.MarkerPrevious(_number - 1, markerMask);
-   if (foundLine < 0)
-    return null;
+            if (foundLine < 0) {
+                foundLine = NativeScintilla.MarkerPrevious(Scintilla.Lines.Count - 1, markerMask);
+                if (foundLine < 0) {
+                    return null;
+                }
+            }
 
    return Scintilla.Lines[foundLine];
   }
Feb 10, 2009 at 9:03 AM
I like it, the only change I would suggest is making the behavior configurable. Either a bool or enum on the Markers class for wrap/nowrap.
Feb 10, 2009 at 5:17 PM
Wellcome back Chris. I know you're not going to be actively involved but answering questions is also very helpful to us in resolving bugs.

If you could explain the relationship between Markers.cs and Lines.cs as far as the relevant FindNextMarker & FindPreviousMarker sections, i'll modify both files as you've suggested and post it here.