diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/AutoComplete.cxx | 43 | 
1 files changed, 38 insertions, 5 deletions
| diff --git a/src/AutoComplete.cxx b/src/AutoComplete.cxx index 676a4124d..ce151aff7 100644 --- a/src/AutoComplete.cxx +++ b/src/AutoComplete.cxx @@ -7,9 +7,11 @@  #include <stdlib.h>  #include <string.h> +#include <stdio.h>  #include "Platform.h" +#include "PropSet.h"  #include "AutoComplete.h"  AutoComplete::AutoComplete() :  @@ -88,7 +90,7 @@ void AutoComplete::SetList(const char *list) {  		}  		delete []words;  	} -	lb.Sort(); +	//lb.Sort();  }  void AutoComplete::Show() { @@ -116,11 +118,42 @@ void AutoComplete::Move(int delta) {  }  void AutoComplete::Select(const char *word) { -	int pos = lb.Find(word); -	//Platform::DebugPrintf("Autocompleting at <%s> %d\n", wordCurrent, pos); -	if (pos == -1 && autoHide) +	int lenWord = strlen(word); +	int location = -1; +	const int maxItemLen=1000; +	char item[maxItemLen]; +	int start = 0; // lower bound of the api array block to search +	int end = lb.Length() - 1; // upper bound of the api array block to search +	while ((start <= end) && (location == -1)) { // Binary searching loop +		int pivot = (start + end) / 2; +		lb.GetValue(pivot, item, maxItemLen); +		int cond = 0; +		if (ignoreCase) +			cond = CompareNCaseInsensitive(word, item, lenWord); +		else +			cond = strncmp(word, item, lenWord); +		if (!cond) { +			// Find first match +			while (pivot > start) { +				lb.GetValue(pivot-1, item, maxItemLen); +				if (ignoreCase) +					cond = CompareNCaseInsensitive(word, item, lenWord); +				else +					cond = strncmp(word, item, lenWord); +				if (0 != cond) +					break; +				--pivot; +			} +			location = pivot; +		} else if (cond < 0) { +			end = pivot - 1; +		} else if (cond > 0) { +			start = pivot + 1; +		} +	} +	if (location == -1 && autoHide)  		Cancel();  	else -		lb.Select(pos); +		lb.Select(location);  } | 
