diff --git a/tabby-core/package.json b/tabby-core/package.json index a420ff80..89bed148 100644 --- a/tabby-core/package.json +++ b/tabby-core/package.json @@ -27,6 +27,7 @@ "ngx-perfect-scrollbar": "^10.1.0", "ngx-translate-messageformat-compiler": "^4.11.0", "readable-stream": "3.6.0", + "thenby": "^1.3.4", "uuid": "^8.0.0" }, "peerDependencies": { diff --git a/tabby-core/src/api/selector.ts b/tabby-core/src/api/selector.ts index 12c69020..2b5d5412 100644 --- a/tabby-core/src/api/selector.ts +++ b/tabby-core/src/api/selector.ts @@ -6,5 +6,6 @@ export interface SelectorOption { icon?: string freeInputPattern?: string color?: string + weight?: number callback?: (string?) => void } diff --git a/tabby-core/src/components/selectorModal.component.ts b/tabby-core/src/components/selectorModal.component.ts index a50d4284..4a614099 100644 --- a/tabby-core/src/components/selectorModal.component.ts +++ b/tabby-core/src/components/selectorModal.component.ts @@ -1,3 +1,4 @@ +import { firstBy } from 'thenby' import { Component, Input, HostListener, ViewChildren, QueryList, ElementRef } from '@angular/core' // eslint-disable-line @typescript-eslint/no-unused-vars import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap' import { SelectorOption } from '../api/selector' @@ -52,8 +53,11 @@ export class SelectorModalComponent { onFilterChange (): void { const f = this.filter.trim().toLowerCase() if (!f) { - this.filteredOptions = this.options.slice() - .sort((a, b) => a.group?.localeCompare(b.group ?? '') ?? 0) + this.filteredOptions = this.options.slice().sort( + firstBy, number>(x => x.weight ?? 0) + .thenBy, string>(x => x.group ?? '') + .thenBy, string>(x => x.name) + ) .filter(x => !x.freeInputPattern) } else { const terms = f.split(' ') diff --git a/tabby-core/src/services/profiles.service.ts b/tabby-core/src/services/profiles.service.ts index 7c287038..055e011e 100644 --- a/tabby-core/src/services/profiles.service.ts +++ b/tabby-core/src/services/profiles.service.ts @@ -112,6 +112,7 @@ export class ProfilesService { group: this.translate.instant('Recent'), icon: 'fas fa-history', color: p.color, + weight: -1, callback: async () => { if (p.id) { p = (await this.getProfiles()).find(x => x.id === p.id) ?? p @@ -124,6 +125,7 @@ export class ProfilesService { name: this.translate.instant('Clear recent profiles'), group: this.translate.instant('Recent'), icon: 'fas fa-eraser', + weight: -1, callback: async () => { window.localStorage.removeItem('recentProfiles') this.config.save() @@ -142,6 +144,7 @@ export class ProfilesService { options = [...options, ...profiles.map((p): SelectorOption => ({ ...this.selectorOptionForProfile(p), + weight: p.isBuiltin ? 2 : 1, callback: () => resolve(p), }))] @@ -150,6 +153,7 @@ export class ProfilesService { options.push({ name: this.translate.instant('Manage profiles'), icon: 'fas fa-window-restore', + weight: 10, callback: () => { this.app.openNewTabRaw({ type: SettingsTabComponent, diff --git a/tabby-core/yarn.lock b/tabby-core/yarn.lock index 89251ae3..2d7c0b07 100644 --- a/tabby-core/yarn.lock +++ b/tabby-core/yarn.lock @@ -161,6 +161,11 @@ string_decoder@^1.1.1: dependencies: safe-buffer "~5.2.0" +thenby@^1.3.4: + version "1.3.4" + resolved "https://registry.yarnpkg.com/thenby/-/thenby-1.3.4.tgz#81581f6e1bb324c6dedeae9bfc28e59b1a2201cc" + integrity sha512-89Gi5raiWA3QZ4b2ePcEwswC3me9JIg+ToSgtE0JWeCynLnLxNr/f9G+xfo9K+Oj4AFdom8YNJjibIARTJmapQ== + tslib@^1.10.0: version "1.14.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"