Skip to content

Commit 2c00b9a

Browse files
committed
fixed profile order in the selector dialog - fixes Eugeny#5537
1 parent fc4bbfc commit 2c00b9a

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
lines changed

tabby-core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"ngx-perfect-scrollbar": "^10.1.0",
2828
"ngx-translate-messageformat-compiler": "^4.11.0",
2929
"readable-stream": "3.6.0",
30+
"thenby": "^1.3.4",
3031
"uuid": "^8.0.0"
3132
},
3233
"peerDependencies": {

tabby-core/src/api/selector.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ export interface SelectorOption<T> {
66
icon?: string
77
freeInputPattern?: string
88
color?: string
9+
weight?: number
910
callback?: (string?) => void
1011
}

tabby-core/src/components/selectorModal.component.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { firstBy } from 'thenby'
12
import { Component, Input, HostListener, ViewChildren, QueryList, ElementRef } from '@angular/core' // eslint-disable-line @typescript-eslint/no-unused-vars
23
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
34
import { SelectorOption } from '../api/selector'
@@ -52,8 +53,11 @@ export class SelectorModalComponent<T> {
5253
onFilterChange (): void {
5354
const f = this.filter.trim().toLowerCase()
5455
if (!f) {
55-
this.filteredOptions = this.options.slice()
56-
.sort((a, b) => a.group?.localeCompare(b.group ?? '') ?? 0)
56+
this.filteredOptions = this.options.slice().sort(
57+
firstBy<SelectorOption<T>, number>(x => x.weight ?? 0)
58+
.thenBy<SelectorOption<T>, string>(x => x.group ?? '')
59+
.thenBy<SelectorOption<T>, string>(x => x.name)
60+
)
5761
.filter(x => !x.freeInputPattern)
5862
} else {
5963
const terms = f.split(' ')

tabby-core/src/services/profiles.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export class ProfilesService {
112112
group: this.translate.instant('Recent'),
113113
icon: 'fas fa-history',
114114
color: p.color,
115+
weight: -1,
115116
callback: async () => {
116117
if (p.id) {
117118
p = (await this.getProfiles()).find(x => x.id === p.id) ?? p
@@ -124,6 +125,7 @@ export class ProfilesService {
124125
name: this.translate.instant('Clear recent profiles'),
125126
group: this.translate.instant('Recent'),
126127
icon: 'fas fa-eraser',
128+
weight: -1,
127129
callback: async () => {
128130
window.localStorage.removeItem('recentProfiles')
129131
this.config.save()
@@ -142,6 +144,7 @@ export class ProfilesService {
142144

143145
options = [...options, ...profiles.map((p): SelectorOption<void> => ({
144146
...this.selectorOptionForProfile(p),
147+
weight: p.isBuiltin ? 2 : 1,
145148
callback: () => resolve(p),
146149
}))]
147150

@@ -150,6 +153,7 @@ export class ProfilesService {
150153
options.push({
151154
name: this.translate.instant('Manage profiles'),
152155
icon: 'fas fa-window-restore',
156+
weight: 10,
153157
callback: () => {
154158
this.app.openNewTabRaw({
155159
type: SettingsTabComponent,

tabby-core/yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ string_decoder@^1.1.1:
161161
dependencies:
162162
safe-buffer "~5.2.0"
163163

164+
thenby@^1.3.4:
165+
version "1.3.4"
166+
resolved "https://registry.yarnpkg.com/thenby/-/thenby-1.3.4.tgz#81581f6e1bb324c6dedeae9bfc28e59b1a2201cc"
167+
integrity sha512-89Gi5raiWA3QZ4b2ePcEwswC3me9JIg+ToSgtE0JWeCynLnLxNr/f9G+xfo9K+Oj4AFdom8YNJjibIARTJmapQ==
168+
164169
tslib@^1.10.0:
165170
version "1.14.1"
166171
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"

0 commit comments

Comments
 (0)