Verify selectedIndex to prevent NSRangeException

This commit is contained in:
Kevin Sawicki 2017-03-10 10:09:14 -08:00
parent 3b2faf7b89
commit 3349e32196
2 changed files with 5 additions and 3 deletions

View file

@ -465,7 +465,8 @@ static NSTouchBarItemIdentifier SegmentedControlIdentifier = @"com.electron.touc
int selectedIndex = 0;
settings.Get("selectedIndex", &selectedIndex);
control.selectedSegment = selectedIndex;
if (selectedIndex >= 0 && selectedIndex < control.segmentCount)
control.selectedSegment = selectedIndex;
}
@end

View file

@ -45,8 +45,9 @@ describe('TouchBar module', function () {
new TouchBarSegmentedControl({
segmentStyle: 'capsule',
segments: [{label: 'baz', enabled: false}],
selectedIndex: 0
})
selectedIndex: 5
}),
new TouchBarSegmentedControl({segments: []})
])
window.setTouchBar(touchBar)
label.label = 'baz'