X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTEditorWidget.java;h=3d8d57e16569c4d89dbcc8ae3867cb7e00f6a1ff;hb=3eacc236973b94764d86b67ce836ae72e05c0687;hp=8d2a0104b4c598aec5de23f06a4e879e4871171a;hpb=df602ccf5e32585c26dc618dd3b4a759b6820943;p=fanfix.git diff --git a/src/jexer/TEditorWidget.java b/src/jexer/TEditorWidget.java index 8d2a010..3d8d57e 100644 --- a/src/jexer/TEditorWidget.java +++ b/src/jexer/TEditorWidget.java @@ -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; } @@ -183,8 +192,13 @@ public final class TEditorWidget extends TWidget { // Need to move topLine to bring document back into view. if (topLineIsTop) { topLine = line - (getHeight() - 1); + if (topLine < 0) { + topLine = 0; + } + assert (topLine >= 0); } else { topLine = line; + assert (topLine >= 0); } } @@ -193,6 +207,7 @@ public final class TEditorWidget extends TWidget { */ // Document is in view, let's set cursorY + assert (line >= topLine); setCursorY(line - topLine); alignCursor(); } @@ -370,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. * @@ -385,7 +422,11 @@ public final class TEditorWidget extends TWidget { * @param row the new editing row number. Row 1 is the first row. */ public void setEditingRowNumber(final int row) { - document.setLineNumber(row - 1); + assert (row > 0); + if ((row > 0) && (row < document.getLineCount())) { + document.setLineNumber(row - 1); + alignTopLine(true); + } } /** @@ -404,7 +445,10 @@ public final class TEditorWidget extends TWidget { * column. */ public void setEditingColumnNumber(final int column) { - document.setCursor(column - 1); + if ((column > 0) && (column < document.getLineLength())) { + document.setCursor(column - 1); + alignCursor(); + } } /**