Skip to content

Commit f9c3057

Browse files
committed
Script Interpreter: keep a record of a 'current command'
The 'current command' is the command that is not yet in the history. It is very convenient to be able to go back in history, just to have a look, before continuing to craft the current command (and it would be annoying if it was lost when going back in history). Of course, if the user decides to execute a different command from the history instead, the edits to the 'current command' are lost. This behavior is most in line with the Unix shell behavior power users might be used to. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent b91b703 commit f9c3057

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/main/java/org/scijava/script/History.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class History {
4949
private final PrefService prefs;
5050
private final String name;
5151
private final LastRecentlyUsed<String> entries = new LastRecentlyUsed<String>(MAX_ENTRIES);
52+
private String currentCommand = "";
5253
private int position = -1;
5354

5455
/**
@@ -88,10 +89,14 @@ public void write() {
8889
public void add(final String command) {
8990
entries.add(command);
9091
position = -1;
92+
currentCommand = "";
9193
}
9294

9395
public boolean replace(final String currentCommand) {
94-
if (position < 0) return false;
96+
if (position < 0) {
97+
this.currentCommand = currentCommand;
98+
return false;
99+
}
95100
return entries.replace(position, currentCommand);
96101
}
97102

@@ -106,7 +111,7 @@ public boolean replace(final String currentCommand) {
106111
*/
107112
public String next() {
108113
position = entries.next(position);
109-
return position < 0 ? null : entries.get(position);
114+
return position < 0 ? currentCommand : entries.get(position);
110115
}
111116

112117
/**
@@ -120,7 +125,7 @@ public String next() {
120125
*/
121126
public String previous() {
122127
position = entries.previous(position);
123-
return position < 0 ? null : entries.get(position);
128+
return position < 0 ? currentCommand : entries.get(position);
124129
}
125130

126131
@Override

0 commit comments

Comments
 (0)