Skip to content

Commit

Permalink
less command: added home and end key mappings & improved moveForward()
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Jul 22, 2019
1 parent 6e12b27 commit 032445a
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion builtins/src/main/java/org/jline/builtins/Less.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ else if (buffer.length() > 0 && (buffer.charAt(0) == '/' || buffer.charAt(0) ==
if (obj == Operation.CHAR) {
char c = bindingReader.getLastBinding().charAt(0);
// Enter option mode or pattern edit mode
if (c == '-' || c == '/' || c == '?') {
if (c == '-' || c == '/' || c == '?' || c == '&') {
buffer.setLength(0);
}
buffer.append(c);
Expand Down Expand Up @@ -298,6 +298,12 @@ else if (buffer.length() > 0 && (buffer.charAt(0) == '/' || buffer.charAt(0) ==
moveTo(lineNum);
}
break;
case HOME:
moveTo(0);
break;
case END:
moveForward(Integer.MAX_VALUE);
break;
case LEFT_ONE_HALF_SCREEN:
firstColumnToDisplay = Math.max(0, firstColumnToDisplay - size.getColumns() / 2);
break;
Expand Down Expand Up @@ -749,6 +755,15 @@ void moveForward(int lines) throws IOException {
int width = size.getColumns() - (printLineNumbers ? 8 : 0);
int height = size.getRows();
boolean doOffsets = firstColumnToDisplay == 0 && !chopLongLines;
if (lines == Integer.MAX_VALUE) {
Long allLines = sources.get(sourceIdx).lines();
if (allLines != null) {
firstLineToDisplay = (int)(long)allLines;
for (int l = 0; l < height - 1; l++) {
firstLineToDisplay = prevLine2display(firstLineToDisplay, dpCompiled).getU();
}
}
}
while (--lines >= 0) {
int lastLineToDisplay = firstLineToDisplay;
if (!doOffsets) {
Expand Down Expand Up @@ -1023,6 +1038,8 @@ private void bindKeys(KeyMap<Operation> map) {
map.bind(Operation.UNDO_SEARCH, alt('u'));
map.bind(Operation.GO_TO_FIRST_LINE_OR_N, "g", "<", alt('<'));
map.bind(Operation.GO_TO_LAST_LINE_OR_N, "G", ">", alt('>'));
map.bind(Operation.HOME, key(terminal, Capability.key_home));
map.bind(Operation.END, key(terminal, Capability.key_end));
map.bind(Operation.NEXT_FILE, ":n");
map.bind(Operation.PREV_FILE, ":p");
map.bind(Operation.GOTO_FILE, ":x");
Expand Down

0 comments on commit 032445a

Please sign in to comment.