From 0486dbed9d245dc0385fa9eddc6d1cc1fa0ff014 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Bajpai Date: Fri, 7 Aug 2026 11:41:53 +0530 Subject: [PATCH] fix: resolve 4 bugs in termui --- examples/rss-reader/src/index.tsx | 2 +- examples/todo-app/src/index.ts | 2 +- examples/widget-gallery/src/index.ts | 2 +- packages/ui/src/MultiSelect.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/rss-reader/src/index.tsx b/examples/rss-reader/src/index.tsx index 2b269cb81..5ff542b3f 100644 --- a/examples/rss-reader/src/index.tsx +++ b/examples/rss-reader/src/index.tsx @@ -27,7 +27,7 @@ function decodeEntities(value: string): string { return value.replace(/&(#x?[0-9a-fA-F]+|[a-zA-Z]+);/g, (match, entity: string) => { if (entity.startsWith('#x')) { - const codePoint = Number.parseInt(entity.slice(2), 16); + const codePoint = Number.parseInt(entity.slice(2, 10), 16); return Number.isFinite(codePoint) ? String.fromCodePoint(codePoint) : match; } diff --git a/examples/todo-app/src/index.ts b/examples/todo-app/src/index.ts index d26035d3c..d4cf9b550 100644 --- a/examples/todo-app/src/index.ts +++ b/examples/todo-app/src/index.ts @@ -104,7 +104,7 @@ class CustomMultiProgress extends (MultiProgressClass as any) { const value = Math.max(0, Math.min(1, item.value)); const filled = Math.round(barWidth * value); - const pct = Math.round(value * 100); + const pct = Math.round(value * 100 + Number.EPSILON); const percentStr = ` ${pct}% `; const showPct = barWidth >= percentStr.length; const labelStart = showPct ? Math.floor((barWidth - percentStr.length) / 2) : -1; diff --git a/examples/widget-gallery/src/index.ts b/examples/widget-gallery/src/index.ts index 57b141244..ec688a7fc 100644 --- a/examples/widget-gallery/src/index.ts +++ b/examples/widget-gallery/src/index.ts @@ -129,7 +129,7 @@ class WidgetGalleryApp extends Widget { } // Tab switching: 1-6 - const num = parseInt(event.key); + const num = parseInt(event.key, 10); if (num >= 1 && num <= 6) { this._switchTab(num - 1); return true; diff --git a/packages/ui/src/MultiSelect.ts b/packages/ui/src/MultiSelect.ts index b4116418f..327e1eee2 100644 --- a/packages/ui/src/MultiSelect.ts +++ b/packages/ui/src/MultiSelect.ts @@ -30,7 +30,7 @@ export class MultiSelect extends Widget { } get selectedOptions(): MultiSelectOption[] { - return [...this._checked].sort().map(i => this._options[i]); + return [...this._checked].sort((a, b) => a - b).map(i => this._options[i]); } selectNext(): void { if (this._options.length === 0) return; let n = this._cursorIndex + 1; while (n < this._options.length && this._options[n].disabled) n++; if (n < this._options.length) { this._cursorIndex = n; this.markDirty(); } } selectPrev(): void { if (this._options.length === 0) return; let n = this._cursorIndex - 1; while (n >= 0 && this._options[n].disabled) n--; if (n >= 0) { this._cursorIndex = n; this.markDirty(); } }