summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKurt B. Kaiser <kbk@shore.net>2008-04-27 21:38:05 (GMT)
committerKurt B. Kaiser <kbk@shore.net>2008-04-27 21:38:05 (GMT)
commit9c5c0af804fa8dd6578569616d31847b878a2a66 (patch)
treee996a5a04447c03a52a9912a304e6f71f7870155
parent93cdae5f814292da17c38374d0cfa314b96fd3be (diff)
downloadcpython-9c5c0af804fa8dd6578569616d31847b878a2a66.zip
cpython-9c5c0af804fa8dd6578569616d31847b878a2a66.tar.gz
cpython-9c5c0af804fa8dd6578569616d31847b878a2a66.tar.bz2
Improved AutoCompleteWindow logic. Patch 2062 Tal Einat.
-rw-r--r--Lib/idlelib/AutoCompleteWindow.py19
-rw-r--r--Lib/idlelib/NEWS.txt2
2 files changed, 14 insertions, 7 deletions
diff --git a/Lib/idlelib/AutoCompleteWindow.py b/Lib/idlelib/AutoCompleteWindow.py
index f7bd423..635775d 100644
--- a/Lib/idlelib/AutoCompleteWindow.py
+++ b/Lib/idlelib/AutoCompleteWindow.py
@@ -54,9 +54,9 @@ class AutoCompleteWindow:
self.lastkey_was_tab = False
def _change_start(self, newstart):
+ min_len = min(len(self.start), len(newstart))
i = 0
- while i < len(self.start) and i < len(newstart) and \
- self.start[i] == newstart[i]:
+ while i < min_len and self.start[i] == newstart[i]:
i += 1
if i < len(self.start):
self.widget.delete("%s+%dc" % (self.startindex, i),
@@ -98,13 +98,17 @@ class AutoCompleteWindow:
i = m + 1
last = i-1
+ if first == last: # only one possible completion
+ return self.completions[first]
+
# We should return the maximum prefix of first and last
+ first_comp = self.completions[first]
+ last_comp = self.completions[last]
+ min_len = min(len(first_comp), len(last_comp))
i = len(s)
- while len(self.completions[first]) > i and \
- len(self.completions[last]) > i and \
- self.completions[first][i] == self.completions[last][i]:
+ while i < min_len and first_comp[i] == last_comp[i]:
i += 1
- return self.completions[first][:i]
+ return first_comp[:i]
def _selection_changed(self):
"""Should be called when the selection of the Listbox has changed.
@@ -118,8 +122,9 @@ class AutoCompleteWindow:
if self._binary_search(lts) == cursel:
newstart = lts
else:
+ min_len = min(len(lts), len(selstart))
i = 0
- while i < len(lts) and i < len(selstart) and lts[i] == selstart[i]:
+ while i < min_len and lts[i] == selstart[i]:
i += 1
newstart = selstart[:i]
self._change_start(newstart)
diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt
index c809cc3..c574d00 100644
--- a/Lib/idlelib/NEWS.txt
+++ b/Lib/idlelib/NEWS.txt
@@ -9,6 +9,8 @@ What's New in IDLE 2.6a3?
- Home / Control-A toggles between left margin and end of leading white
space. Patch 1196903 Jeff Shute.
+- Improved AutoCompleteWindow logic. Patch 2062 Tal Einat.
+
What's New in IDLE 2.6a1?
=========================