diff --git a/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/JLineConsoleCompleter.java b/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/JLineConsoleCompleter.java index 9f44951bda9a89d4496c48924730f8310aee2461..fda22b405416aa3136489b710166e0ae9224db9f 100644 --- a/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/JLineConsoleCompleter.java +++ b/com.oracle.truffle.r.launcher/src/com/oracle/truffle/r/launcher/JLineConsoleCompleter.java @@ -111,14 +111,10 @@ public class JLineConsoleCompleter implements Completer { start = lastIdxOf(buffer, opt, "function.suffix", start, cursor); } - // are we just after a ',' or ' ' - if (cursor > 0 && cursor <= buffer.length() && (buffer.charAt(cursor - 1) == ',' || buffer.charAt(cursor - 1) == ' ')) { - return cursor; - } - - // is there any next closest ',' or ' '? - int idx = cursor >= buffer.length() ? buffer.length() - 1 : cursor; - while (idx >= start && (buffer.charAt(idx) != ',' && buffer.charAt(idx) != ' ')) { + // is there any preceeding ',' or ' ' - lets start from there + String precBuffer = buffer.length() > cursor ? buffer.substring(0, cursor) : buffer; + int idx = cursor >= precBuffer.length() ? precBuffer.length() - 1 : cursor - 1; + while (idx >= start && precBuffer.charAt(idx) != ',' && precBuffer.charAt(idx) != ' ') { --idx; } if (idx > -1) { diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/engine/shell/TestJLineConsoleCompleter.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/engine/shell/TestJLineConsoleCompleter.java index f197deb07718fbc92a4783fe34a67ff966a679de..c8817f4c9f18350e1d5f5b54dcac1d764a1e403b 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/engine/shell/TestJLineConsoleCompleter.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/engine/shell/TestJLineConsoleCompleter.java @@ -92,6 +92,11 @@ public class TestJLineConsoleCompleter { assertCompl("strtoi", 4, "strtoi", "strtrim"); assertCompl("strto ", 6); assertCompl("strto,", 6); + assertCompl("strt blabla", 4, "strtoi", "strtrim"); + assertCompl("strt blabla", 4, "strtoi", "strtrim"); + assertCompl("strt,,blabla", 4, "strtoi", "strtrim"); + assertCompl("strt, blabla", 4, "strtoi", "strtrim"); + assertCompl("strto blabla", 4, "strtoi", "strtrim"); assertCompl("blabla,strt", 11, "strtoi", "strtrim"); assertCompl("blabla strt", 11, "strtoi", "strtrim"); assertCompl("blabla,,strt", 12, "strtoi", "strtrim");