Skip to content

Commit 89b5c20

Browse files
committed
Small refactors to tab completion function
1 parent 35311ce commit 89b5c20

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

cmd2/cmd2.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,18 +1519,19 @@ def _complete_worker(self, text: str, state: int) -> Optional[str]:
15191519
# Check if any portion of the display matches appears in the tab completion
15201520
display_prefix = os.path.commonprefix(self.display_matches)
15211521

1522-
# For delimited matches, we check what appears before the display
1523-
# matches (common_prefix) as well as the display matches themselves.
1524-
if (' ' in common_prefix) or (display_prefix and ' ' in ''.join(self.display_matches)):
1522+
# For delimited matches, we check for a space in what appears before the display
1523+
# matches (common_prefix) as well as in the display matches themselves.
1524+
if (' ' in common_prefix) or (display_prefix and
1525+
any(' ' in match for match in self.display_matches)):
15251526
add_quote = True
15261527

15271528
# If there is a tab completion and any match has a space, then add an opening quote
1528-
elif common_prefix and ' ' in ''.join(self.completion_matches):
1529+
elif common_prefix and any(' ' in match for match in self.completion_matches):
15291530
add_quote = True
15301531

15311532
if add_quote:
15321533
# Figure out what kind of quote to add and save it as the unclosed_quote
1533-
if '"' in ''.join(self.completion_matches):
1534+
if any('"' in match for match in self.completion_matches):
15341535
unclosed_quote = "'"
15351536
else:
15361537
unclosed_quote = '"'
@@ -1540,7 +1541,7 @@ def _complete_worker(self, text: str, state: int) -> Optional[str]:
15401541
# Check if we need to remove text from the beginning of tab completions
15411542
elif text_to_remove:
15421543
self.completion_matches = \
1543-
[m.replace(text_to_remove, '', 1) for m in self.completion_matches]
1544+
[match.replace(text_to_remove, '', 1) for match in self.completion_matches]
15441545

15451546
# Check if we need to restore a shortcut in the tab completions
15461547
# so it doesn't get erased from the command line

0 commit comments

Comments
 (0)