fix: open existing project doesn't highlight current key signature

This commit is contained in:
Xiaohan-Tian
2026-05-23 13:41:18 -07:00
parent 247c76237d
commit 1e816596e4
2 changed files with 24 additions and 17 deletions
+6 -5
View File
@@ -145,16 +145,17 @@
font-size: 11px; font-size: 11px;
} }
.key-signature-picker-button.selected {
text-decoration: underline;
text-underline-offset: 3px;
}
.key-signature-picker-label { .key-signature-picker-label {
display: inline-flex; display: inline-flex;
align-items: flex-start; align-items: flex-start;
} }
.key-signature-picker-label.selected {
text-decoration: underline;
text-underline-offset: 3px;
text-decoration-thickness: 1px;
}
.key-signature-picker-accidental { .key-signature-picker-accidental {
font-size: 0.58em; font-size: 0.58em;
line-height: 1; line-height: 1;
+14 -8
View File
@@ -34,21 +34,21 @@ function splitAccidental(label: string): { base: string; accidental: string | nu
return { base: label, accidental: null }; return { base: label, accidental: null };
} }
const KeyLabel: React.FC<{ label: string }> = ({ label }) => { const KeyLabel: React.FC<{ label: string; selected?: boolean }> = ({ label, selected = false }) => {
const { base, accidental } = splitAccidental(label); const { base, accidental } = splitAccidental(label);
return ( return (
<span className="key-signature-picker-label"> <span className={`key-signature-picker-label ${selected ? 'selected' : ''}`.trim()}>
<span>{base}</span> <span>{base}</span>
{accidental && <sup className="key-signature-picker-accidental">{accidental}</sup>} {accidental && <sup className="key-signature-picker-accidental">{accidental}</sup>}
</span> </span>
); );
}; };
const CombinedKeyLabel: React.FC<{ labels: string[] }> = ({ labels }) => ( const CombinedKeyLabel: React.FC<{ labels: string[]; selectedIndex?: number }> = ({ labels, selectedIndex = -1 }) => (
<span className="key-signature-picker-label"> <span className="key-signature-picker-label">
{labels.map((label, index) => ( {labels.map((label, index) => (
<React.Fragment key={label}> <React.Fragment key={label}>
<KeyLabel label={label} /> <KeyLabel label={label} selected={index === selectedIndex} />
{index < labels.length - 1 && <span className="key-signature-picker-divider">/</span>} {index < labels.length - 1 && <span className="key-signature-picker-divider">/</span>}
</React.Fragment> </React.Fragment>
))} ))}
@@ -97,7 +97,10 @@ const KeySignaturePickerPopup: React.FC<KeySignaturePickerPopupProps> = ({ value
aria-label={`Select ${slot.outerItems.map(item => item.keySignature).join(' or ')}`} aria-label={`Select ${slot.outerItems.map(item => item.keySignature).join(' or ')}`}
title={slot.outerItems.map(item => item.keySignature).join(' / ')} title={slot.outerItems.map(item => item.keySignature).join(' / ')}
> >
<CombinedKeyLabel labels={slot.outerItems.map(item => item.label)} /> <CombinedKeyLabel
labels={slot.outerItems.map(item => item.label)}
selectedIndex={slot.outerItems.findIndex(item => item.keySignature === value)}
/>
</button> </button>
) : ( ) : (
<div className="key-signature-picker-item-stack"> <div className="key-signature-picker-item-stack">
@@ -109,7 +112,7 @@ const KeySignaturePickerPopup: React.FC<KeySignaturePickerPopupProps> = ({ value
onClick={() => onChange(item.keySignature)} onClick={() => onChange(item.keySignature)}
aria-label={`Select ${item.keySignature}`} aria-label={`Select ${item.keySignature}`}
> >
<KeyLabel label={item.label} /> <KeyLabel label={item.label} selected={value === item.keySignature} />
</button> </button>
</div> </div>
))} ))}
@@ -128,7 +131,10 @@ const KeySignaturePickerPopup: React.FC<KeySignaturePickerPopupProps> = ({ value
aria-label={`Select ${slot.innerItems.map(item => item.keySignature).join(' or ')}`} aria-label={`Select ${slot.innerItems.map(item => item.keySignature).join(' or ')}`}
title={slot.innerItems.map(item => item.keySignature).join(' / ')} title={slot.innerItems.map(item => item.keySignature).join(' / ')}
> >
<CombinedKeyLabel labels={slot.innerItems.map(item => item.label)} /> <CombinedKeyLabel
labels={slot.innerItems.map(item => item.label)}
selectedIndex={slot.innerItems.findIndex(item => item.keySignature === value)}
/>
</button> </button>
) : ( ) : (
<div className="key-signature-picker-item-stack"> <div className="key-signature-picker-item-stack">
@@ -140,7 +146,7 @@ const KeySignaturePickerPopup: React.FC<KeySignaturePickerPopupProps> = ({ value
onClick={() => onChange(item.keySignature)} onClick={() => onChange(item.keySignature)}
aria-label={`Select ${item.keySignature}`} aria-label={`Select ${item.keySignature}`}
> >
<KeyLabel label={item.label} /> <KeyLabel label={item.label} selected={value === item.keySignature} />
</button> </button>
))} ))}
</div> </div>