Merge pull request #1246 from haoqixu/fix-settings-crash-with-small-width

fix(coding-agent): avoid crash of /settings with small width
This commit is contained in:
Mario Zechner 2026-02-04 12:12:12 +01:00 committed by GitHub
commit b23e6ea21e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 11 deletions

View file

@ -118,7 +118,7 @@ export class FooterComponent implements Component {
// Truncate path if too long to fit width // Truncate path if too long to fit width
if (pwd.length > width) { if (pwd.length > width) {
const half = Math.floor(width / 2) - 2; const half = Math.floor(width / 2) - 2;
if (half > 0) { if (half > 1) {
const start = pwd.slice(0, half); const start = pwd.slice(0, half);
const end = pwd.slice(-(half - 1)); const end = pwd.slice(-(half - 1));
pwd = `${start}...${end}`; pwd = `${start}...${end}`;

View file

@ -98,15 +98,15 @@ export class SettingsList implements Component {
if (this.items.length === 0) { if (this.items.length === 0) {
lines.push(this.theme.hint(" No settings available")); lines.push(this.theme.hint(" No settings available"));
if (this.searchEnabled) { if (this.searchEnabled) {
this.addHintLine(lines); this.addHintLine(lines, width);
} }
return lines; return lines;
} }
const displayItems = this.searchEnabled ? this.filteredItems : this.items; const displayItems = this.searchEnabled ? this.filteredItems : this.items;
if (displayItems.length === 0) { if (displayItems.length === 0) {
lines.push(this.theme.hint(" No matching settings")); lines.push(truncateToWidth(this.theme.hint(" No matching settings"), width));
this.addHintLine(lines); this.addHintLine(lines, width);
return lines; return lines;
} }
@ -140,7 +140,7 @@ export class SettingsList implements Component {
const valueText = this.theme.value(truncateToWidth(item.currentValue, valueMaxWidth, ""), isSelected); const valueText = this.theme.value(truncateToWidth(item.currentValue, valueMaxWidth, ""), isSelected);
lines.push(prefix + labelText + separator + valueText); lines.push(truncateToWidth(prefix + labelText + separator + valueText, width));
} }
// Add scroll indicator if needed // Add scroll indicator if needed
@ -160,7 +160,7 @@ export class SettingsList implements Component {
} }
// Add hint // Add hint
this.addHintLine(lines); this.addHintLine(lines, width);
return lines; return lines;
} }
@ -234,13 +234,16 @@ export class SettingsList implements Component {
this.selectedIndex = 0; this.selectedIndex = 0;
} }
private addHintLine(lines: string[]): void { private addHintLine(lines: string[], width: number): void {
lines.push(""); lines.push("");
lines.push( lines.push(
this.theme.hint( truncateToWidth(
this.searchEnabled this.theme.hint(
? " Type to search · Enter/Space to change · Esc to cancel" this.searchEnabled
: " Enter/Space to change · Esc to cancel", ? " Type to search · Enter/Space to change · Esc to cancel"
: " Enter/Space to change · Esc to cancel",
),
width,
), ),
); );
} }