Explorar el Código

Pass word to be completed to intelligent completion handlers

Fixes issue 3874

Change-Id: I364a558f1bf3deeea51edcc254dc0895d948b27b
Reviewed-on: http://gerrit.dmdirc.com/993
Reviewed-by: Gregory Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
tags/0.6.4rc1
Chris Smith hace 14 años
padre
commit
6cc9fdde1a

+ 15
- 1
src/com/dmdirc/commandparser/commands/IntelligentCommand.java Ver fichero

@@ -47,16 +47,21 @@ public interface IntelligentCommand {
47 47
         /** The previously supplied arguments, if any. */
48 48
         private final List<String> previousArgs;
49 49
 
50
+        /** The partially typed word, if any. */
51
+        private final String partial;
52
+
50 53
         /**
51 54
          * Creates a new context with the specified arguments.
52 55
          *
53 56
          * @param window The window the command is being entered in
54 57
          * @param previousArgs The previously supplied arguments, if any
58
+         * @param partial The partially-typed word being completed
55 59
          */
56 60
         public IntelligentCommandContext(final InputWindow window,
57
-                final List<String> previousArgs) {
61
+                final List<String> previousArgs, final String partial) {
58 62
             this.window = window;
59 63
             this.previousArgs = previousArgs;
64
+            this.partial = partial;
60 65
         }
61 66
 
62 67
         /**
@@ -77,6 +82,15 @@ public interface IntelligentCommand {
77 82
             return previousArgs;
78 83
         }
79 84
 
85
+        /**
86
+         * Retrieves the partially typed word which is being completed.
87
+         *
88
+         * @return The partial word being completed
89
+         */
90
+        public String getPartial() {
91
+            return partial;
92
+        }
93
+
80 94
     }
81 95
 
82 96
     /**

+ 2
- 1
src/com/dmdirc/ui/input/InputHandler.java Ver fichero

@@ -459,7 +459,8 @@ public abstract class InputHandler implements ConfigChangeListener {
459 459
     private void doCommandTabCompletion(final String text, final int start,
460 460
             final int end, final boolean shiftPressed) {
461 461
         doNormalTabCompletion(text, start, end, shiftPressed,
462
-                TabCompleter.getIntelligentResults(parentWindow, text.substring(0, start)));
462
+                TabCompleter.getIntelligentResults(parentWindow,
463
+                text.substring(0, start), text.substring(start, end)));
463 464
     }
464 465
 
465 466
     /**

+ 7
- 5
src/com/dmdirc/ui/input/TabCompleter.java Ver fichero

@@ -221,7 +221,7 @@ public class TabCompleter {
221 221
         } else {
222 222
             return getIntelligentResults(context.getWindow(),
223 223
                     new CommandArguments(context.getPreviousArgs().subList(offset,
224
-                    context.getPreviousArgs().size())));
224
+                    context.getPreviousArgs().size())), context.getPartial());
225 225
         }        
226 226
     }
227 227
     
@@ -231,11 +231,12 @@ public class TabCompleter {
231 231
      *
232 232
      * @param window The input window the results are required for
233 233
      * @param args The input arguments
234
+     * @param partial The partially-typed word being completed (if any)
234 235
      * @return Additional tab targets for the text, or null if none are available
235 236
      * @since 0.6.4
236 237
      */
237 238
     private static AdditionalTabTargets getIntelligentResults(final InputWindow window,
238
-            final CommandArguments args) {
239
+            final CommandArguments args, final String partial) {
239 240
         if (!args.isCommand()) {
240 241
             return null;
241 242
         }
@@ -250,7 +251,7 @@ public class TabCompleter {
250 251
                 targets = ((IntelligentCommand) command.getValue())
251 252
                         .getSuggestions(args.getArguments().length,
252 253
                         new IntelligentCommandContext(window,
253
-                        Arrays.asList(args.getArguments())));
254
+                        Arrays.asList(args.getArguments()), partial));
254 255
             }
255 256
 
256 257
             if (command.getValue() instanceof ChannelCommand) {
@@ -270,11 +271,12 @@ public class TabCompleter {
270 271
      *
271 272
      * @param window The input window the results are required for
272 273
      * @param text The text that is being completed
274
+     * @param partial The partially-typed word being completed (if any)
273 275
      * @return Additional tab targets for the text, or null if none are available
274 276
      * @since 0.6.4
275 277
      */
276 278
     public static AdditionalTabTargets getIntelligentResults(final InputWindow window,
277
-            final String text) {
278
-        return getIntelligentResults(window, new CommandArguments(text));
279
+            final String text, final String partial) {
280
+        return getIntelligentResults(window, new CommandArguments(text), partial);
279 281
     }
280 282
 }

Loading…
Cancelar
Guardar