*/
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.
*/
@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;
}
// 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);
}
}
*/
// Document is in view, let's set cursorY
+ assert (line >= topLine);
setCursorY(line - topLine);
alignCursor();
}
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.
*
* @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);
+ }
}
/**
* column.
*/
public void setEditingColumnNumber(final int column) {
- document.setCursor(column - 1);
+ if ((column > 0) && (column < document.getLineLength())) {
+ document.setCursor(column - 1);
+ alignCursor();
+ }
}
/**