HexTextBox - try to preserve the current value when changing the hex size. This kind of thing is super annoying, revert it immediately if there's a problem. Fixes #525

This commit is contained in:
zeromus 2015-10-20 01:57:47 -05:00
parent 7e0996b44b
commit 3dd0ab2008
1 changed files with 18 additions and 2 deletions

View File

@ -30,11 +30,27 @@ namespace BizHawk.Client.EmuHawk
public void SetHexProperties(long domainSize)
{
bool wasMaxSizeSet = _maxSize.HasValue;
int currMaxLength = MaxLength;
_maxSize = domainSize - 1;
MaxLength = _maxSize.Value.NumHexDigits();
_addressFormatStr = "{0:X" + MaxLength + "}";
ResetText();
//try to preserve the old value, as best we can
if(!wasMaxSizeSet)
ResetText();
else if(_nullable)
Text = "";
else if (MaxLength != currMaxLength)
{
long? value = ToLong();
if (value.HasValue)
value = value.Value & ((1L << (MaxLength * 4)) - 1);
else value = 0;
Text = string.Format(_addressFormatStr, value.Value);
}
}
public long GetMax()