Fix crashing when you type in %8, then press left, then press backspace. (Thanks 123DMWM)

This commit is contained in:
UnknownShadow200 2016-05-21 23:58:31 +10:00
parent 1ea806a38f
commit aebeefc1ed

View file

@ -37,8 +37,8 @@ namespace ClassicalSharp.Gui {
else if( key == Key.End ) EndKey();
else if( game.Network.ServerSupportsFullCP437 &&
key == game.InputHandler.Keys[KeyBinding.ExtendedInput] )
altText.SetActive( !altText.Active );
else if( clipboardDown && !OtherKey( key ) ) return false;
altText.SetActive( !altText.Active );
else if( clipboardDown && !OtherKey( key ) ) return false;
return true;
}
@ -113,22 +113,22 @@ namespace ClassicalSharp.Gui {
Dispose();
Init();
} else if( !buffer.Empty && caretPos != 0 ) {
DeleteChar();
BackspaceColourCode();
if( !BackspaceColourCode())
DeleteChar();
Dispose();
Init();
}
}
void BackspaceColourCode() {
bool BackspaceColourCode() {
// If text is XYZ%eH, backspaces to XYZ.
int index = caretPos == -1 ? buffer.Length - 1 : caretPos;
if( index <= 0 ) return;
if( index <= 1 ) return false;
if( index == 0 || buffer.value[index - 1] != '%'
|| !game.Drawer2D.ValidColour( buffer.value[index] ) )
return;
if( buffer.value[index - 1] != '%' || !game.Drawer2D.ValidColour( buffer.value[index] ) )
return false;
DeleteChar(); DeleteChar();
return true;
}
void DeleteChar() {