double-click support
[fanfix.git] / src / jexer / TEditorWidget.java
index 690c5731f280a936cd1ce6f5ac3bbcf0c4d4f4ac..3d8d57e16569c4d89dbcc8ae3867cb7e00f6a1ff 100644 (file)
@@ -45,6 +45,11 @@ import static jexer.TKeypress.*;
  */
 public final class TEditorWidget extends TWidget {
 
+    /**
+     * The number of lines to scroll on mouse wheel up/down.
+     */
+    private static final int wheelScrollSize = 3;
+
     /**
      * The document being edited.
      */
@@ -122,16 +127,20 @@ public final class TEditorWidget extends TWidget {
     @Override
     public void onMouseDown(final TMouseEvent mouse) {
         if (mouse.isMouseWheelUp()) {
-            if (topLine > 0) {
-                topLine--;
-                alignDocument(false);
+            for (int i = 0; i < wheelScrollSize; i++) {
+                if (topLine > 0) {
+                    topLine--;
+                    alignDocument(false);
+                }
             }
             return;
         }
         if (mouse.isMouseWheelDown()) {
-            if (topLine < document.getLineCount() - 1) {
-                topLine++;
-                alignDocument(true);
+            for (int i = 0; i < wheelScrollSize; i++) {
+                if (topLine < document.getLineCount() - 1) {
+                    topLine++;
+                    alignDocument(true);
+                }
             }
             return;
         }
@@ -376,6 +385,28 @@ public final class TEditorWidget extends TWidget {
         return document.getLineCount();
     }
 
+    /**
+     * Get the current visible top row number.  1-based.
+     *
+     * @return the visible top row number.  Row 1 is the first row.
+     */
+    public int getVisibleRowNumber() {
+        return topLine + 1;
+    }
+
+    /**
+     * Set the current visible row number.  1-based.
+     *
+     * @param row the new visible row number.  Row 1 is the first row.
+     */
+    public void setVisibleRowNumber(final int row) {
+        assert (row > 0);
+        if ((row > 0) && (row < document.getLineCount())) {
+            topLine = row - 1;
+            alignDocument(true);
+        }
+    }
+
     /**
      * Get the current editing row number.  1-based.
      *