From bd25cb0cc66c5ff23fa7cc66cf0893513ac4b2bc 2016-05-05 21:33:11 From: Matthias Bussonnier Date: 2016-05-05 21:33:11 Subject: [PATCH] Fix completions for PTK 1.0 --- diff --git a/IPython/core/completer.py b/IPython/core/completer.py index 8e3ecc7..1f612d5 100644 --- a/IPython/core/completer.py +++ b/IPython/core/completer.py @@ -803,10 +803,13 @@ class IPCompleter(Completer): def trim_start(completion): """completions need to start with `text`, trim the beginning until it does""" - if text in completion and not (completion.startswith(text)): - start_index = completion.index(text) + ltext = text.lower() + lcomp = completion.lower() + if ltext in lcomp and not (lcomp.startswith(ltext)): + start_index = lcomp.index(ltext) if cursor_pos: - assert start_index < cursor_pos + if start_index >= cursor_pos: + start_index = min(start_index, cursor_pos) return completion[start_index:] return completion diff --git a/IPython/core/tests/test_completer.py b/IPython/core/tests/test_completer.py index b0f90ec..1ef7d3f 100644 --- a/IPython/core/tests/test_completer.py +++ b/IPython/core/tests/test_completer.py @@ -800,6 +800,6 @@ def test_import_module_completer(): def test_from_module_completer(): ip = get_ipython() - _, matches = ip.complete('B', 'from io import B') + _, matches = ip.complete('B', 'from io import B', 16) nt.assert_in('BytesIO', matches) nt.assert_not_in('BaseException', matches)