Commit 28e488f 1 parent 3e2f8b2 commit 28e488f Copy full SHA for 28e488f
File tree 2 files changed +18
-1
lines changed
common/src/main/java/revxrsal/commands
2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -143,6 +143,17 @@ public interface AutoCompleter {
143
143
*/
144
144
List <String > complete (@ NotNull CommandActor actor , @ NotNull String buffer );
145
145
146
+ /**
147
+ * Sets whether should this auto-completer filter suggestions
148
+ * to include only the closest suggestions to the user input.
149
+ * <p>
150
+ * By default, this is true.
151
+ *
152
+ * @param filterToClosestInput Whether should suggestions be
153
+ * filtered to the closest input
154
+ */
155
+ void filterToClosestInput (boolean filterToClosestInput );
156
+
146
157
/**
147
158
* Returns the containing {@link CommandHandler} of this auto completer.
148
159
* This will allow for writing fluent and readable code.
Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ final class BaseAutoCompleter implements AutoCompleter {
46
46
private final BaseCommandHandler handler ;
47
47
final Map <String , SuggestionProvider > suggestionKeys = new HashMap <>();
48
48
final List <SuggestionProviderFactory > factories = new ArrayList <>();
49
+ private boolean filterToClosestInput = true ;
49
50
50
51
public BaseAutoCompleter (BaseCommandHandler handler ) {
51
52
this .handler = handler ;
@@ -148,6 +149,11 @@ public SuggestionProvider getProvider(CommandParameter parameter) {
148
149
return complete (actor , ArgumentStack .parseForAutoCompletion (buffer ));
149
150
}
150
151
152
+ @ Override
153
+ public void filterToClosestInput (boolean filterToClosestInput ) {
154
+ this .filterToClosestInput = filterToClosestInput ;
155
+ }
156
+
151
157
private ExecutableCommand searchForCommand (CommandPath path , CommandActor actor ) {
152
158
ExecutableCommand found = handler .getCommand (path );
153
159
if (found != null && !found .isSecret () && found .getPermission ().canExecute (actor )) return found ;
@@ -223,7 +229,7 @@ private CommandCategory getLastCategory(CommandPath path) {
223
229
@ NotNull private List <String > getParamCompletions (Collection <String > provider , ArgumentStack args ) {
224
230
return provider
225
231
.stream ()
226
- .filter (c -> c .toLowerCase ().startsWith (args .getLast ().toLowerCase ()))
232
+ .filter (c -> ! filterToClosestInput || c .toLowerCase ().startsWith (args .getLast ().toLowerCase ()))
227
233
.sorted (String .CASE_INSENSITIVE_ORDER )
228
234
.distinct ()
229
235
.collect (Collectors .toList ());
You can’t perform that action at this time.
0 commit comments