mirror of
https://github.com/eugeny/tabby
synced 2026-09-25 14:36:01 +00:00
feat(serial): add support top placement of free-input options in the selector
This commit is contained in:
@@ -5,6 +5,7 @@ export interface SelectorOption<T> {
|
||||
result?: T
|
||||
icon?: string
|
||||
freeInputPattern?: string
|
||||
freeInputPlacement?: 'top'|'bottom'
|
||||
freeInputEquivalent?: string
|
||||
color?: string
|
||||
weight?: number
|
||||
|
||||
@@ -89,7 +89,18 @@ export class SelectorModalComponent<T> {
|
||||
{ sort: true },
|
||||
).search(f)
|
||||
|
||||
this.options.filter(x => x.freeInputPattern).sort(firstBy<SelectorOption<T>, number>(x => x.weight ?? 0)).forEach(freeOption => {
|
||||
const freeOptions = this.options
|
||||
.filter(x => x.freeInputPattern)
|
||||
.sort(firstBy<SelectorOption<T>, number>(x => x.weight ?? 0))
|
||||
|
||||
// Keep free-input options discoverable during filtering.
|
||||
const topFreeOptions = freeOptions.filter(x => x.freeInputPlacement === 'top')
|
||||
const bottomFreeOptions = freeOptions.filter(x => x.freeInputPlacement !== 'top')
|
||||
|
||||
this.filteredOptions = this.filteredOptions.filter(x => !topFreeOptions.includes(x))
|
||||
this.filteredOptions = [...topFreeOptions, ...this.filteredOptions]
|
||||
|
||||
bottomFreeOptions.forEach(freeOption => {
|
||||
if (!this.filteredOptions.includes(freeOption)) {
|
||||
this.filteredOptions.push(freeOption)
|
||||
}
|
||||
|
||||
@@ -101,7 +101,8 @@ export class SerialTabComponent extends ConnectableTerminalTabComponent<SerialPr
|
||||
{
|
||||
name: this.translate.instant(_('Custom baud rate')),
|
||||
freeInputPattern: this.translate.instant(_('%s')),
|
||||
weight: Number.MAX_SAFE_INTEGER,
|
||||
freeInputPlacement: 'top',
|
||||
weight: -1,
|
||||
callback: query => {
|
||||
const parsed = Number.parseInt((query ?? '').trim(), 10)
|
||||
if (Number.isInteger(parsed) && parsed > 0) {
|
||||
|
||||
@@ -97,7 +97,8 @@ export class SerialProfilesService extends ConnectableProfileProvider<SerialProf
|
||||
{
|
||||
name: this.translate.instant('Custom baud rate'),
|
||||
freeInputPattern: this.translate.instant('%s'),
|
||||
weight: Number.MAX_SAFE_INTEGER,
|
||||
freeInputPlacement: 'top',
|
||||
weight: -1,
|
||||
callback: query => {
|
||||
const parsed = Number.parseInt((query ?? '').trim(), 10)
|
||||
if (Number.isInteger(parsed) && parsed > 0) {
|
||||
|
||||
Reference in New Issue
Block a user