Skip to content

Commit 9393380

Browse files
committed
Still hammering out adding an opening quote
1 parent 5786a96 commit 9393380

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

cmd2.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,26 +2078,28 @@ def complete(self, text, state):
20782078
# If self.display_matches is empty, then set it to self.completion_matches
20792079
# before we alter them. That way the suggestions will reflect how we parsed
20802080
# the token being completed and not how readline did.
2081+
display_matches_delimited = True
20812082
if not self.display_matches:
2083+
display_matches_delimited = False
20822084
self.display_matches = copy.copy(self.completion_matches)
20832085

20842086
# Check if we need to add an opening quote
20852087
if not unclosed_quote:
20862088

2087-
# Get the common prefix of the matches. This is the actual tab completion.
2088-
# Use display_matches instead of completion_matches to support cases of delimited
2089-
# match strings since only the final part of those matches matter in these checks.
2090-
common_prefix = os.path.commonprefix(self.display_matches)
2089+
common_prefix = os.path.commonprefix(self.completion_matches)
20912090

2092-
# Join all matches into 1 string for ease of searching
2093-
all_matches_str = ''.join(self.display_matches)
2094-
2095-
# If there is a tab completion and any of the matches have a space,
2096-
# then we will add an opening quote to the completion matches.
2097-
if common_prefix and ' ' in all_matches_str:
2091+
add_quote = False
2092+
if display_matches_delimited:
2093+
display_prefix = os.path.commonprefix(self.display_matches)
2094+
if (' ' in common_prefix) or (display_prefix and ' ' in ''.join(self.display_matches)):
2095+
add_quote = True
2096+
else:
2097+
if common_prefix and ' ' in ''.join(self.completion_matches):
2098+
add_quote = True
20982099

2100+
if add_quote:
20992101
# Figure out what kind of quote to add and save it as the unclosed_quote
2100-
if '"' in all_matches_str:
2102+
if '"' in ''.join(self.completion_matches):
21012103
unclosed_quote = "'"
21022104
else:
21032105
unclosed_quote = '"'

0 commit comments

Comments
 (0)