Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Improve initial sorting of items #87

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

jarle
Copy link
Contributor

@jarle jarle commented Sep 26, 2017

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.

  • "Order by frequency": orders by how frequently a command has been launched.
  • "Order by recently launched": orders by how recent the command was last launched.
  • "Order alphabetically": Orders alphabetically 😄 It is identical to the previous default sorting.

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

@jarle jarle changed the title Improve initial sorting of items [WiP] Improve initial sorting of items Sep 30, 2017
@@ -69,6 +70,14 @@ export default class CommandPaletteView {
},
didConfirmSelection: (keyBinding) => {
this.hide()
const elementName = keyBinding.name

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show recently used commands [enhancement]
4 participants