Clear selection when setting completion pattern.

It doesn't make sense to have an active selection while you are
filtering by entering text. You should be in one of two states:

1. Tabbing through completions (valid selection)
2. Entering a filter pattern (invalid selection)

Fixes #2843, where a crash would occur after the following:

1. tab to an item other than the first
2. <backspace>
3. re-type last character
4. <ctrl-d>

This would try to delete an out of range index.
This commit is contained in:
Ryan Roden-Corrent 2017-07-22 18:06:16 -04:00
parent bc21904fef
commit b61691684e
2 changed files with 2 additions and 0 deletions

View File

@ -297,6 +297,7 @@ class CompletionView(QTreeView):
self.pattern = pattern
with debug.log_time(log.completion, 'Set pattern {}'.format(pattern)):
self.model().set_pattern(pattern)
self.selectionModel().clear()
self._maybe_update_geometry()
self._maybe_show()

View File

@ -87,6 +87,7 @@ def test_set_pattern(completionview):
completionview.set_model(model)
completionview.set_pattern('foo')
model.set_pattern.assert_called_with('foo')
assert not completionview.selectionModel().currentIndex().isValid()
def test_set_pattern_no_model(completionview):