Skip to content

Commit

Permalink
JBIDE-18179: Implement CursorDown
Browse files Browse the repository at this point in the history
  • Loading branch information
koentsje committed Oct 10, 2014
1 parent a77e9ba commit 93b37de
Showing 1 changed file with 21 additions and 2 deletions.
Expand Up @@ -6,15 +6,34 @@
*/
package org.jboss.tools.aesh.core.internal.ansi;


import org.jboss.tools.aesh.core.document.Document;

public class CursorDown extends AbstractCommand {

public CursorDown(String arguments) {}
private int amount = 1;

public CursorDown(String arguments) {
if (!"".equals(arguments)) {
amount = Integer.valueOf(arguments);
}
}

@Override
public CommandType getType() {
return CommandType.CURSOR_DOWN;
}

public void handle(Document document) {
int currentOffset = document.getCursorOffset();
int currentLine = document.getLineOfOffset(currentOffset);
int newLine = currentLine + amount;
int lastLine = document.getLineOfOffset(document.getLength());
if (newLine <= lastLine) {
int currentColumn = Math.min(
currentOffset - document.getLineOffset(currentLine),
document.getLineLength(newLine));
int newOffset = document.getLineOffset(newLine) + currentColumn;
document.moveCursorTo(newOffset);
}
}
}

0 comments on commit 93b37de

Please sign in to comment.