Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ public InputResult execute() {
List<Candidate> matches = new ArrayList<>();
KeyMap<Operation> keyMap = new KeyMap<>();
bindKeys(keyMap);
StringBuilder displayBuffer = new StringBuilder();
StringBuilder buffer = new StringBuilder();
CompletionMatcher completionMatcher = new CompletionMatcherImpl();
boolean tabCompletion = completer != null && reader != null;
Expand All @@ -596,7 +597,7 @@ public InputResult execute() {
refreshDisplay(
firstItemRow - 1,
column,
buffer.toString(),
displayBuffer.toString(),
row,
startColumn,
displayCandidates ? matches : new ArrayList<>());
Expand All @@ -608,48 +609,67 @@ public InputResult execute() {
}
break;
case RIGHT:
if (column < startColumn + buffer.length()) {
if (column < startColumn + displayBuffer.length()) {
column++;
}
break;
case INSERT:
buffer.insert(column - startColumn, mask == null ? bindingReader.getLastBinding() : mask);
displayBuffer.insert(
column - startColumn, mask == null ? bindingReader.getLastBinding() : mask);
buffer.insert(column - startColumn, bindingReader.getLastBinding());
column++;
break;
case BACKSPACE:
if (column > startColumn) {
displayBuffer.deleteCharAt(column - startColumn - 1);
buffer.deleteCharAt(column - startColumn - 1);
column--;
}
break;
case DELETE:
if (column < startColumn + buffer.length() && column >= startColumn) {
if (column < startColumn + displayBuffer.length() && column >= startColumn) {
displayBuffer.deleteCharAt(column - startColumn);
buffer.deleteCharAt(column - startColumn);
}
break;
case BEGINNING_OF_LINE:
column = startColumn;
break;
case END_OF_LINE:
column = startColumn + buffer.length();
column = startColumn + displayBuffer.length();
break;
case SELECT_CANDIDATE:
if (tabCompletion && matches.size() < ReaderUtils.getInt(reader, LineReader.LIST_MAX, 50)) {
String selected =
selectCandidate(firstItemRow - 1, buffer.toString(), row + 1, startColumn, matches);
resetHeader();
if (selected != null) {
buffer.delete(0, buffer.length());
displayBuffer.delete(0, displayBuffer.length());
if (mask == null) {
displayBuffer.append(selected);
} else {
for (int i = 0; i < selected.length(); i++) {
displayBuffer.append(mask);
}
}
buffer.delete(0, displayBuffer.length());
buffer.append(selected);
column = startColumn + buffer.length();
column = startColumn + displayBuffer.length();
}
}
break;
case EXIT:
if (buffer.toString().isEmpty()) {
if (displayBuffer.toString().isEmpty()) {
if (mask == null) {
displayBuffer.append(defaultValue);
} else {
for (int i = 0; i < defaultValue.length(); i++) {
displayBuffer.append(mask);
}
}
buffer.append(defaultValue);
}
return new InputResult(buffer.toString());
return new InputResult(buffer.toString(), displayBuffer.toString());
case CANCEL:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public Map<String, PromptResultItemIF> prompt(
}
}
}
String resp = result.getResult();
String resp = result.getDisplayResult();
if (result instanceof ConfirmResult) {
ConfirmResult cr = (ConfirmResult) result;
if (cr.getConfirmed() == ConfirmChoice.ConfirmationValue.YES) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@

public class InputResult implements PromptResultItemIF {
private final String input;
private final String displayInput;

public InputResult(String input) {
public InputResult(String input, String displayInput) {
this.input = input;
this.displayInput = displayInput;
}

public String getInput() {
return input;
public String getDisplayResult() {
return displayInput;
}

public String getResult() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@

public interface PromptResultItemIF {
String getResult();

default String getDisplayResult() {
return getResult();
}
}
Loading