Closed
Description
Thanks to #17 that I now have the autocomplete setup for my program.
There are times that I would like to reenter the same input that I made in the past.
Is there an elegant way to program the Left and Right arrow keys to scroll backward and forward the input ?
I come up with this in SwingHandler
but fall short of what to do next ?
private static final String KEY_STROKE_LEFT = "pressed LEFT";
private static final String KEY_STROKE_RIGHT = "pressed RIGHT";
private String historyInput = "";
private int historyIndex = -1;
private String[] history = {};
public SwingHandler(SwingTextTerminal terminal) {
this.terminal = terminal;
terminal.registerHandler(KEY_STROKE_LEFT, t -> {
if (historyIndex >= 0) {
historyIndex--;
String text = (historyIndex < 0) ? historyInput : choices[historyIndex ];
t.replaceInput(text, false);
}
return new ReadHandlerData(ReadInterruptionStrategy.Action.CONTINUE);
});
Metadata
Metadata
Assignees
Labels
No labels