Skip to content

Commit bbac0d9

Browse files
committed
DefaultScriptInterpreter: fix newline accumulation
From @skalarproduktraum: "Before when walking the history, a trailing \n got appended to the submitted command. Unfortunately, these accumulated over time." Fixes scijava/scijava-ui-swing#21.
1 parent b42fe55 commit bbac0d9

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,22 +186,23 @@ public Object interpret(final String line) throws ScriptException {
186186
if (!shouldEvaluatePendingInput(true)) return MORE_INPUT_PENDING;
187187
}
188188

189+
if (pendingLineCount > 0) buffer.append("\n");
189190
pendingLineCount++;
190191
buffer.append(line);
191-
buffer.append("\n");
192+
final String command = buffer.toString();
192193

193194
if (!(engine instanceof Compilable)) {
194195
// Not a compilable language.
195196
// Evaluate directly, with no multi-line statements possible.
196197
try {
197-
return eval(buffer.toString());
198+
return eval(command);
198199
}
199200
finally {
200201
reset();
201202
}
202203
}
203204

204-
final CompiledScript cs = tryCompiling(buffer.toString(),
205+
final CompiledScript cs = tryCompiling(command, //
205206
getPendingLineCount(), line.length());
206207

207208
if (cs == null) {
@@ -215,7 +216,7 @@ public Object interpret(final String line) throws ScriptException {
215216
}
216217
// Command is complete; evaluate the compiled script.
217218
try {
218-
addToHistory(buffer.toString());
219+
addToHistory(command);
219220
return cs.eval();
220221
}
221222
finally {

0 commit comments

Comments
 (0)