Trim whitespace and newlines when pasting text from clipboard.

This commit is contained in:
UnknownShadow200 2016-06-16 10:12:49 +10:00
parent fc688b53d2
commit 4d4ca0adc6
4 changed files with 6 additions and 4 deletions

View File

@ -237,11 +237,12 @@ namespace ClassicalSharp.Gui {
CalculateCaretData();
}
static char[] trimChars = {'\r', '\n', '\v', '\f', ' ', '\t', '\0'};
bool OtherKey( Key key ) {
if( key == Key.V && buffer.Length < TotalChars ) {
string text = null;
try {
text = game.window.ClipboardText;
text = game.window.ClipboardText.Trim( trimChars );
} catch( Exception ex ) {
ErrorHandler.LogError( "Paste from clipboard", ex );
const string warning = "&cError while trying to paste from clipboard.";

View File

@ -86,7 +86,7 @@ namespace ClassicalSharp {
if ( OpenTK.Configuration.RunningOnMacOS )
return GetClipboardText();
else
return Clipboard.GetText();
return Clipboard.GetText();
}
set {
if ( OpenTK.Configuration.RunningOnMacOS )

View File

@ -169,7 +169,7 @@ namespace Launcher.Gui.Screens {
mppass = "(none)";
ClientStartData data = new ClientStartData( user, mppass, ip, port );
if( user.ToLowerInvariant() == "rand()" || user.ToLowerInvariant() == "random()") {
if( Utils.CaselessEquals( user, "rand()" ) || Utils.CaselessEquals( user, "random()" ) ) {
rnd.NextBytes( rndBytes );
data.Username = Convert.ToBase64String( rndBytes ).TrimEnd( '=' );
}

View File

@ -167,11 +167,12 @@ namespace Launcher.Gui.Widgets {
if( !String.IsNullOrEmpty( Text ) )
Clipboard.SetText( Text );
}
static char[] trimChars = {'\r', '\n', '\v', '\f', ' ', '\t', '\0'};
/// <summary> Sets the currently entered text to the contents of the system clipboard. </summary>
/// <returns> true if a redraw is necessary, false otherwise. </returns>
public bool CopyFromClipboard() {
string text = Clipboard.GetText();
string text = Clipboard.GetText().Trim( trimChars );
if( String.IsNullOrEmpty( text ) || Text.Length >= MaxTextLength ) return false;
if( ClipboardFilter != null )