diff --git a/package.json b/package.json index 979e58733..35825f449 100644 --- a/package.json +++ b/package.json @@ -436,11 +436,13 @@ "default": "usage", "enum": [ "usage", - "name" + "name", + "config" ], "enumDescriptions": [ "Sort actions by most recently used", - "Sort actions alphabetically by name" + "Sort actions alphabetically by name", + "Sort actions in the order they are defined in the configuration, regardless of their origin" ], "description": "Determine how actions should be sorted in the action selection menu" }, diff --git a/src/ui/actions.ts b/src/ui/actions.ts index 777f05b22..4e73f3c70 100644 --- a/src/ui/actions.ts +++ b/src/ui/actions.ts @@ -670,25 +670,26 @@ export async function getAllAvailableActions(targets: ActionTarget[], scheme: st }); // Get the sort preference from settings - const sortBy = IBMi.connectionManager.get(`sortActionsBy`) || `usage`; + const sortBy = IBMi.connectionManager.get<'name'|'usage'|'config'>(`sortActionsBy`) || `usage`; // Then we get all the available Actions for the current context - const availableActions: AvailableAction[] = allActions.filter(action => action.type === scheme) + const contextActions = allActions.filter(action => action.type === scheme) .filter(action => !action.extensions || action.extensions.every(e => !e) || targets.every(t => action.extensions!.includes(t.extension) || action.extensions!.includes(t.fragment)) || action.extensions.includes(`GLOBAL`)) - .filter(action => action.runOnProtected || !targets.some(t => t.protected)) - .sort((a, b) => { - if (sortBy === `name`) { - // Sort alphabetically by name - return a.name.localeCompare(b.name); - } else { - // Sort by most recently used (default behavior) - return (actionUsed.get(b.name) || 0) - (actionUsed.get(a.name) || 0); - } - }) - .map(action => ({ - label: action.name, - action - })); + .filter(action => action.runOnProtected || !targets.some(t => t.protected)); + + if (sortBy === `name`) { + // Sort alphabetically by name + contextActions.sort((a, b) => a.name.localeCompare(b.name)); + } else if (sortBy === `usage`) { + // Sort by most recently used (default behavior). + // `config` keeps actions in the order they are defined, regardless of their origin. + contextActions.sort((a, b) => (actionUsed.get(b.name) || 0) - (actionUsed.get(a.name) || 0)); + } + + const availableActions: AvailableAction[] = contextActions.map(action => ({ + label: action.name, + action + })); return availableActions; }