/** Scroll the text area to show the line of the cursor * */ void showCursor () { updateCurrentLine(); if (cursorLine != firstLineShowing) { int step = cursorLine >= firstLineShowing ? 1 : -1; while (firstLineShowing > cursorLine || firstLineShowing + linesShowing - 1 < cursorLine) { firstLineShowing += step; } } }
@Override public void setSelection (int selectionStart, int selectionEnd) { super.setSelection(selectionStart, selectionEnd); updateCurrentLine(); }
@Override protected void moveCursor (boolean forward, boolean jump) { int count = forward ? 1 : -1; int index = (cursorLine * 2) + count; if (index >= 0 && index + 1 < linesBreak.size && linesBreak.items[index] == cursor && linesBreak.items[index + 1] == cursor) { cursorLine += count; if (jump) { super.moveCursor(forward, jump); } showCursor(); } else { super.moveCursor(forward, jump); } updateCurrentLine(); }
@Override protected void setCursorPosition (float x, float y) { moveOffset = -1; Drawable background = style.background; BitmapFont font = style.font; float height = getHeight(); if (background != null) { height -= background.getTopHeight(); x -= background.getLeftWidth(); } x = Math.max(0, x); if (background != null) { y -= background.getTopHeight(); } cursorLine = (int) Math.floor((height - y) / font.getLineHeight()) + firstLineShowing; cursorLine = Math.max(0, Math.min(cursorLine, getLines() - 1)); super.setCursorPosition(x, y); updateCurrentLine(); }