From 543dc82d717fcf1ab5c72ecf88948ed421721bc2 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 4 Jul 2010 21:47:19 +0200 Subject: [PATCH] Improved completion --- zathura.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/zathura.c b/zathura.c index 6f5668a..0e60fc1 100644 --- a/zathura.c +++ b/zathura.c @@ -2421,9 +2421,32 @@ isc_completion(Argument* argument) * the current command does not differ from the previous one * the current command has an completion function */ - if( (previous_command) && (current_parameter) && !strcmp(current_command, previous_command) ) + if(strchr(input, ' ')) { - if(previous_id < 0 || !commands[previous_id].completion) + gboolean search_matching_command = FALSE; + + int i; + for(i = 0; i < LENGTH(commands); i++) + { + int abbr_length = commands[i].abbr ? strlen(commands[i].abbr) : 0; + int cmd_length = commands[i].command ? strlen(commands[i].command) : 0; + + if( ((current_command_length <= cmd_length) && !strncmp(current_command, commands[i].command, current_command_length)) || + ((current_command_length <= abbr_length) && !strncmp(current_command, commands[i].abbr, current_command_length)) + ) + { + if(commands[i].completion) + { + previous_command = current_command; + previous_id = i; + search_matching_command = TRUE; + } + else + return; + } + } + + if(!search_matching_command) return; Completion *result = commands[previous_id].completion(current_parameter);