def _on_space(self, instance: AdvancedTextInput) -> bool: """Private function to start completion mode by entering from space. This function is fired when self.commandText._on_space is called. [ensures]: (when this is the first space after a user-input word) self.from_space (otherwise, do nothing) [calls]: (when this is the first space after a user-input word) self.controller.auto_complete (otherwise, do nothing) """ if instance.completion_mode: cursor = instance.cursor self._stop_completion(instance) instance.cursor = cursor return True if not self.space_completion: return True c_index = instance.cursor_index(instance.cursor) - 1 if instance.last_row_start + instance.protected_len != c_index\ and instance.text[c_index - 1] != " ": string = instance.text[instance.last_row_start + instance.protected_len:] self.from_space = True self.controller.auto_complete(string) return True
def _on_reduce_option(self, instance: AdvancedTextInput) -> bool: """Private function to reduce options based on user input. This function is fired when self.commandText.on_reduce_option is called. [requires]: instance.completion_mode [ensures]: self.option = [opt for all opt in $self.option if opt.lower().startswith( instance.text[self.completion_start:end].lower() )] [calls]: self._stop_completion """ if not asserts(instance.completion_mode, "Not in completion mode"): return True copy = list() instance.do_cursor_movement("cursor_end", control=False) end = instance.cursor_index(instance.cursor) word_truc = instance.text[self.completion_start:end] copy = [ opt for opt in self.option if opt.lower().startswith(word_truc.lower()) ] self._stop_completion(instance) self.option = copy