Skip to content

Commit f4daa81

Browse files
committed
Ensure we prevent Input.Changed *around* the call to apply_completion, so that users dont have to
1 parent a173411 commit f4daa81

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

textual_autocomplete/_autocomplete.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ def _complete(self, option_index: int) -> None:
270270
highlighted = option_index
271271
option = cast(DropdownItem, option_list.get_option_at_index(highlighted))
272272
highlighted_value = option.value
273-
self.apply_completion(highlighted_value, self._get_target_state())
273+
with self.prevent(Input.Changed):
274+
self.apply_completion(highlighted_value, self._get_target_state())
274275
self.post_completion()
275276

276277
def post_completion(self) -> None:
@@ -284,18 +285,17 @@ def apply_completion(self, value: str, state: TargetState) -> None:
284285
the value the user has chosen from the dropdown list.
285286
"""
286287
target = self.target
287-
with self.prevent(Input.Changed):
288-
target.value = ""
289-
target.insert_text_at_cursor(value)
290-
291-
# We need to rebuild here because we've prevented the Changed events
292-
# from being sent to the target widget, meaning AutoComplete won't spot
293-
# intercept that message, and would not trigger a rebuild like it normally
294-
# does when a Changed event is received.
295-
new_target_state = self._get_target_state()
296-
self._rebuild_options(
297-
new_target_state, self.get_search_string(new_target_state)
298-
)
288+
target.value = ""
289+
target.insert_text_at_cursor(value)
290+
291+
# We need to rebuild here because we've prevented the Changed events
292+
# from being sent to the target widget, meaning AutoComplete won't spot
293+
# intercept that message, and would not trigger a rebuild like it normally
294+
# does when a Changed event is received.
295+
new_target_state = self._get_target_state()
296+
self._rebuild_options(
297+
new_target_state, self.get_search_string(new_target_state)
298+
)
299299

300300
@property
301301
def target(self) -> Input:

0 commit comments

Comments
 (0)