FELIX-2053: Completion does not reprint previous characters in some circumstances
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@907694 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/karaf/shell/console/src/main/java/org/apache/felix/karaf/shell/console/completer/SessionScopeCompleter.java b/karaf/shell/console/src/main/java/org/apache/felix/karaf/shell/console/completer/SessionScopeCompleter.java
index 34ba244..dd99f38 100644
--- a/karaf/shell/console/src/main/java/org/apache/felix/karaf/shell/console/completer/SessionScopeCompleter.java
+++ b/karaf/shell/console/src/main/java/org/apache/felix/karaf/shell/console/completer/SessionScopeCompleter.java
@@ -60,8 +60,8 @@
int max = -1;
for( String segment : segments )
{
- Completion completion = new Completion( candidates );
- completion.complete( completer, segment + ":" + buffer, ( segment + ":" ).length() + cursor );
+ Completion completion = new Completion( segment, candidates );
+ completion.complete( completer, buffer, cursor );
// Compute the max cursor position
max = Math.max( max, completion.cursor );
@@ -91,24 +91,39 @@
private class Completion
{
+ public final String scope;
+
public final List<String> candidates;
public int cursor;
- public Completion( final List candidates )
+ public Completion( final String scope, final List candidates )
{
+ assert scope != null;
assert candidates != null;
+ this.scope = scope;
// noinspection unchecked
this.candidates = new LinkedList<String>( candidates );
}
- public void complete( final Completer completer, final String buffer, final int cursor )
+ public void complete( Completer completer, String buffer, int cursor )
{
assert completer != null;
+ buffer = scope + ":" + buffer;
+ cursor += (scope + ":").length();
+
this.cursor = completer.complete( buffer, cursor, candidates );
+
+ cursor -= (scope + ":").length();
+ for (int i = 0; i < candidates.size(); i++) {
+ String s = candidates.get(i);
+ s = s.substring((scope + ":").length());
+ candidates.set(i, s);
+ }
}
+
}
}
\ No newline at end of file