createAlgorithmAutocomplete creates an autocomplete function for algorithm input fields
(suggestions []string)
| 855 | |
| 856 | // createAlgorithmAutocomplete creates an autocomplete function for algorithm input fields |
| 857 | func (sf *ServerForm) createAlgorithmAutocomplete(suggestions []string) func(string) []string { |
| 858 | return func(currentText string) []string { |
| 859 | if currentText == "" { |
| 860 | // Return nil when empty to disable autocomplete, allowing Tab to navigate |
| 861 | return nil |
| 862 | } |
| 863 | |
| 864 | // Find the current word being typed |
| 865 | words := strings.Split(currentText, ",") |
| 866 | lastWord := strings.TrimSpace(words[len(words)-1]) |
| 867 | |
| 868 | // If the last word is empty (after a comma), return nil to allow Tab navigation |
| 869 | if lastWord == "" { |
| 870 | return nil |
| 871 | } |
| 872 | |
| 873 | // Handle prefix characters |
| 874 | prefix := "" |
| 875 | searchTerm := lastWord |
| 876 | if lastWord[0] == '+' || lastWord[0] == '-' || lastWord[0] == '^' { |
| 877 | prefix = string(lastWord[0]) |
| 878 | if len(lastWord) > 1 { |
| 879 | searchTerm = lastWord[1:] |
| 880 | } else { |
| 881 | // Just a prefix character, show all suggestions |
| 882 | searchTerm = "" |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | // Filter suggestions - check if all characters appear in sequence |
| 887 | var filtered []string |
| 888 | for _, s := range suggestions { |
| 889 | if searchTerm == "" || matchesSequence(strings.ToLower(s), strings.ToLower(searchTerm)) { |
| 890 | // Build the complete text with the suggestion |
| 891 | newWords := make([]string, len(words)-1) |
| 892 | copy(newWords, words[:len(words)-1]) |
| 893 | newWords = append(newWords, prefix+s) |
| 894 | filtered = append(filtered, strings.Join(newWords, ",")) |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | // If no matches found, return nil to allow Tab navigation |
| 899 | if len(filtered) == 0 { |
| 900 | return nil |
| 901 | } |
| 902 | |
| 903 | return filtered |
| 904 | } |
| 905 | } |
| 906 | |
| 907 | // validateField validates a single field and updates the validation state |
| 908 | func (sf *ServerForm) validateField(fieldName, value string) string { |
no test coverage detected