feat(serial): add support top placement of free-input options in the selector

This commit is contained in:
bluekani
2026-06-02 00:26:05 +09:00
parent 5307d2e5ef
commit f5d6ed0b40
4 changed files with 17 additions and 3 deletions
+1
View File
@@ -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) {
+2 -1
View File
@@ -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) {