This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Improve initial sorting of items #87
Open
jarle
wants to merge
9
commits into
atom:master
Choose a base branch
from
jarle:initial-item-sorting
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ryanolsonx
reviewed
Jun 20, 2018
@@ -69,6 +70,14 @@ export default class CommandPaletteView { | |||
}, | |||
didConfirmSelection: (keyBinding) => { | |||
this.hide() | |||
const elementName = keyBinding.name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could use a better name. elementName
makes it seem as though it's referring to the DOM.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the Change
This PR implements some of the functionality proposed in #18, namely a more friendly initial sorting of items in the command palette(only when no query has been entered yet).
The change introduces three new settings for the command-palette package: "order by frequency", "order by recently launched", and "order alphabetically".
This sorting is applied when no query is entered into the command palette, presenting more useful item choices to the user than the previous default alphabetic sorting.
The items that do not have a score(not yet visited) will be listed alphabetically after the items that has been given a score.
The user can choose between these two sorting methods in the command-palette settings view.
Any time a command is lanched with the command palette, the timestamp of that launch is pushed to an array of launch timestamps associated with that command. This array is accessed through an object where the command names are the keys(for example
application:about
is a key).This object is serialized in order to persist the command launch history between application launches.
The length of the array is used to sort by frequency, and the last timestamp in the array is used to sort by recentness. Any items coming after these two sorting methods are sorted alphabetically using localeCompare.
Alternate Designs
An alternative would be to only sort by frequency, which would make the persistence of the scores more compact.
The proposed version was selected in order to keep enough data to have "most recent" items. It is also extensible to more advanced sorting algorithms, such as weighting results by recentness and frequency together.
Benefits
The user will have faster access to frequently used commands. This will also hopefully save you from those moments when you open the command palette and just can't remember what to enter 🙂
Possible Drawbacks
The changes introduces serialization of the command palette in order to persist the command scores between sessions.
Because the scores are identified by the unique command issued, for example
application:about
, any changes to these command identifiers will affect the palette. For example, if a package is uninstalled, the command will be unavailable, but not removed from the scores. This could be solved by periodically looping through the scored commands and making sure that they are still reachable.Applicable Issues
Fixes #18