[tor-commits] [arm/release] fix: tab completion could truncated results

atagar at torproject.org atagar at torproject.org
Sun Sep 25 21:38:30 UTC 2011


commit 48e955db099c5295edcee19508844fbd812b5948
Author: Damian Johnson <atagar at torproject.org>
Date:   Mon Sep 19 08:10:12 2011 -0700

    fix: tab completion could truncated results
    
    When the tab completion matches had prefixes with multiple cases (for instance
    "MAPADDRESS" and "MapAddress") then tab completion would crop input to the
    common portion (just "M"). Instead picking the prefix with the largest set of
    results. This isn't perfect since it could hide some results but seems like the
    best option for getting around this stupid behavior.
---
 src/util/torInterpretor.py |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/src/util/torInterpretor.py b/src/util/torInterpretor.py
index d5abb88..593f29c 100644
--- a/src/util/torInterpretor.py
+++ b/src/util/torInterpretor.py
@@ -348,6 +348,30 @@ class TorControlCompleter:
     if text != self._prefix:
       self._prefix = text
       self._prefixMatches = self.getMatches(text)
+      
+      # Tab completion fills in the first common prefix which can be
+      # problematic if they don't all match. For instance completing "Map" will
+      # result in ["MAPADDRESS", "MapAddress"], which gets truncated to the
+      # common prefix of just "M" when the user presses tab.
+      
+      if len(self._prefixMatches) > 1:
+        prefixToResult = {}
+        
+        for match in self._prefixMatches:
+          prefix = match[:len(text)]
+          
+          if prefix in prefixToResult:
+            prefixToResult[prefix].append(match)
+          else:
+            prefixToResult[prefix] = [match]
+        
+        if len(prefixToResult) > 1:
+          # we have multiple prefixes, pick the one with the most results
+          self._prefixMatches = None
+          
+          for matchSet in prefixToResult.values():
+            if not self._prefixMatches or len(self._prefixMatches) < len(matchSet):
+              self._prefixMatches = matchSet
     
     if state < len(self._prefixMatches):
       return self._prefixMatches[state]





More information about the tor-commits mailing list