Skip to content

Sort order of CompletionItems display #1154

Answered by kmvanbrunt
wsande asked this question in Q&A
Discussion options

You must be logged in to vote

First sort the results how you want them to display. Then set self.matches_sorted = True before returning them.

Here is a description of matches_sorted from cmd2.py. This value gets reset to False each time tab completion runs, so you don't need to reset it manually.

# Set to True before returning matches to complete() in cases where matches have already been sorted.
# If False, then complete() will sort the matches using self.default_sort_key before they are displayed.
# This does not affect self.formatted_completions.
self.matches_sorted = False

One thing to note is that CompletionItem inherits from string. Therefore the IDs are being converted to strings when you create each Completion…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@wsande
Comment options

Answer selected by wsande
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants