X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTEditorWidget.java;h=5ab7a239f76721fac9b2bd91ac3125a743dc4154;hb=051e29138b18fb4b731a72f8727475b10e4c74e4;hp=690c5731f280a936cd1ce6f5ac3bbcf0c4d4f4ac;hpb=fe0770f988e64fc0ccafd3d3b086b4a0eb559d3b;p=fanfix.git diff --git a/src/jexer/TEditorWidget.java b/src/jexer/TEditorWidget.java index 690c573..5ab7a23 100644 --- a/src/jexer/TEditorWidget.java +++ b/src/jexer/TEditorWidget.java @@ -43,7 +43,12 @@ import static jexer.TKeypress.*; * TEditorWidget displays an editable text document. It is unaware of * scrolling behavior, but can respond to mouse and keyboard events. */ -public final class TEditorWidget extends TWidget { +public 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. *