1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 07:22:54 +08:00

Ensure textbox always reverts to sane state on out-of-range failures

This commit is contained in:
Dean Herbert 2020-10-01 13:06:24 +09:00
parent 61e62929ee
commit e0a0902a15
2 changed files with 15 additions and 11 deletions

View File

@ -54,9 +54,12 @@ namespace osu.Game.Screens.Edit.Timing
}
catch
{
// will restore the previous text value on failure.
Current.TriggerChange();
// TriggerChange below will restore the previous text value on failure.
}
// This is run regardless of parsing success as the parsed number may not actually trigger a change
// due to bindable clamping. Even in such a case we want to update the textbox to a sane visual state.
Current.TriggerChange();
};
Current.BindValueChanged(val =>

View File

@ -65,18 +65,19 @@ namespace osu.Game.Screens.Edit.Timing
{
if (!isNew) return;
if (double.TryParse(Current.Value, out double doubleVal))
try
{
try
{
if (double.TryParse(Current.Value, out double doubleVal) && doubleVal > 0)
beatLengthBindable.Value = beatLengthToBpm(doubleVal);
}
catch
{
// will restore the previous text value on failure.
beatLengthBindable.TriggerChange();
}
}
catch
{
// TriggerChange below will restore the previous text value on failure.
}
// This is run regardless of parsing success as the parsed number may not actually trigger a change
// due to bindable clamping. Even in such a case we want to update the textbox to a sane visual state.
beatLengthBindable.TriggerChange();
};
beatLengthBindable.BindValueChanged(val =>