Skip to content

Commit

Permalink
nano: refactoring...
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Jul 30, 2019
1 parent 2a8493d commit 9667327
Showing 1 changed file with 5 additions and 32 deletions.
37 changes: 5 additions & 32 deletions builtins/src/main/java/org/jline/builtins/Nano.java
Original file line number Diff line number Diff line change
Expand Up @@ -556,36 +556,7 @@ void ensureCursorVisible() {
}

while (true) {
int cursor = header.size() * size.getColumns() + (printLineNumbers ? 8 : 0);
int cur = firstLineToDisplay;
int off = offsetInLineToDisplay;
while (true) {
if (cur < line || off < offsetInLine) {
if (!wrapping) {
cursor += rwidth;
cur++;
} else {
cursor += rwidth;
Optional<Integer> next = nextLineOffset(cur, off);
if (next.isPresent()) {
off = next.get();
} else {
cur++;
off = 0;
}
}
} else if (cur == line) {
if (!wrapping && column > firstColumnToDisplay + width()) {
while (column > firstColumnToDisplay + width()) {
firstColumnToDisplay += width();
}
}
cursor += column - firstColumnToDisplay + (firstColumnToDisplay > 0 ? 1 : 0);
break;
} else {
throw new IllegalStateException();
}
}
int cursor = computeCursorPosition(header.size() * size.getColumns() + (printLineNumbers ? 8 : 0), rwidth);
if (cursor >= (height + header.size()) * rwidth) {
moveDisplayDown(smoothScrolling ? 1 : height / 2);
} else {
Expand Down Expand Up @@ -835,8 +806,10 @@ public void gotoLine(int x, int y) {
}

public int getDisplayedCursor() {
int rwidth = size.getColumns() + 1;
int cursor = (printLineNumbers ? 8 : 0);
return computeCursorPosition(printLineNumbers ? 8 : 0, size.getColumns() + 1);
}

private int computeCursorPosition(int cursor, int rwidth) {
int cur = firstLineToDisplay;
int off = offsetInLineToDisplay;
while (true) {
Expand Down

0 comments on commit 9667327

Please sign in to comment.