Assuming that s is the prefix of a string in self.completions, return the longest string which is a prefix of all the strings which s is a prefix of them. If s is not a prefix of a string, return s.
(self, s)
| 89 | return min(i, len(self.completions)-1) |
| 90 | |
| 91 | def _complete_string(self, s): |
| 92 | """Assuming that s is the prefix of a string in self.completions, |
| 93 | return the longest string which is a prefix of all the strings which |
| 94 | s is a prefix of them. If s is not a prefix of a string, return s. |
| 95 | """ |
| 96 | first = self._binary_search(s) |
| 97 | if self.completions[first][:len(s)] != s: |
| 98 | # There is not even one completion which s is a prefix of. |
| 99 | return s |
| 100 | # Find the end of the range of completions where s is a prefix of. |
| 101 | i = first + 1 |
| 102 | j = len(self.completions) |
| 103 | while j > i: |
| 104 | m = (i + j) // 2 |
| 105 | if self.completions[m][:len(s)] != s: |
| 106 | j = m |
| 107 | else: |
| 108 | i = m + 1 |
| 109 | last = i-1 |
| 110 | |
| 111 | if first == last: # only one possible completion |
| 112 | return self.completions[first] |
| 113 | |
| 114 | # We should return the maximum prefix of first and last |
| 115 | first_comp = self.completions[first] |
| 116 | last_comp = self.completions[last] |
| 117 | min_len = min(len(first_comp), len(last_comp)) |
| 118 | i = len(s) |
| 119 | while i < min_len and first_comp[i] == last_comp[i]: |
| 120 | i += 1 |
| 121 | return first_comp[:i] |
| 122 | |
| 123 | def _selection_changed(self): |
| 124 | """Call when the selection of the Listbox has changed. |
no test coverage detected