Make sure GetClipboardText's null returns are handled properly

This commit is contained in:
def 2015-08-26 16:40:59 +02:00
parent bd2b61f0e5
commit a1403ef457
3 changed files with 56 additions and 47 deletions

View file

@ -116,31 +116,34 @@ bool CChat::OnInput(IInput::CEvent Event)
if(Input()->KeyPressed(KEY_LCTRL) && Input()->KeyDown(KEY_V)) if(Input()->KeyPressed(KEY_LCTRL) && Input()->KeyDown(KEY_V))
{ {
const char *text = Input()->GetClipboardText(); const char *Text = Input()->GetClipboardText();
if(Text)
{
// if the text has more than one line, we send all lines except the last one // if the text has more than one line, we send all lines except the last one
// the last one is set as in the text field // the last one is set as in the text field
char Line[256]; char Line[256];
int i, Begin = 0; int i, Begin = 0;
for(i = 0; i < str_length(text); i++) for(i = 0; i < str_length(Text); i++)
{ {
if(text[i] == '\n') if(Text[i] == '\n')
{ {
int max = i - Begin + 1; int max = i - Begin + 1;
if(max > (int)sizeof(Line)) if(max > (int)sizeof(Line))
max = sizeof(Line); max = sizeof(Line);
str_copy(Line, text + Begin, max); str_copy(Line, Text + Begin, max);
Begin = i+1; Begin = i+1;
SayChat(Line); SayChat(Line);
while(text[i] == '\n') i++; while(Text[i] == '\n') i++;
} }
} }
int max = i - Begin + 1; int max = i - Begin + 1;
if(max > (int)sizeof(Line)) if(max > (int)sizeof(Line))
max = sizeof(Line); max = sizeof(Line);
str_copy(Line, text + Begin, max); str_copy(Line, Text + Begin, max);
Begin = i+1; Begin = i+1;
m_Input.Add(Line); m_Input.Add(Line);
} }
}
if(Input()->KeyPressed(KEY_LCTRL) && Input()->KeyDown(KEY_C)) if(Input()->KeyPressed(KEY_LCTRL) && Input()->KeyDown(KEY_C))
{ {

View file

@ -95,6 +95,8 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event)
if(m_pGameConsole->Input()->KeyPressed(KEY_LCTRL) && m_pGameConsole->Input()->KeyDown(KEY_V)) if(m_pGameConsole->Input()->KeyPressed(KEY_LCTRL) && m_pGameConsole->Input()->KeyDown(KEY_V))
{ {
const char *Text = m_pGameConsole->Input()->GetClipboardText(); const char *Text = m_pGameConsole->Input()->GetClipboardText();
if(Text)
{
char Line[256]; char Line[256];
int i, Begin = 0; int i, Begin = 0;
for(i = 0; i < str_length(Text); i++) for(i = 0; i < str_length(Text); i++)
@ -121,6 +123,7 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event)
Begin = i+1; Begin = i+1;
m_Input.Add(Line); m_Input.Add(Line);
} }
}
if(m_pGameConsole->Input()->KeyPressed(KEY_LCTRL) && m_pGameConsole->Input()->KeyDown(KEY_C)) if(m_pGameConsole->Input()->KeyPressed(KEY_LCTRL) && m_pGameConsole->Input()->KeyDown(KEY_C))
{ {

View file

@ -241,6 +241,8 @@ int CMenus::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrS
if(Input()->KeyPressed(KEY_LCTRL) && Input()->KeyDown(KEY_V)) if(Input()->KeyPressed(KEY_LCTRL) && Input()->KeyDown(KEY_V))
{ {
const char *Text = Input()->GetClipboardText(); const char *Text = Input()->GetClipboardText();
if(Text)
{
int CharsLeft = StrSize - str_length(pStr); int CharsLeft = StrSize - str_length(pStr);
int Offset = str_length(pStr); int Offset = str_length(pStr);
for(int i = 0; i < str_length(Text) && i <= CharsLeft; i++) for(int i = 0; i < str_length(Text) && i <= CharsLeft; i++)
@ -252,6 +254,7 @@ int CMenus::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrS
} }
s_AtIndex = str_length(pStr); s_AtIndex = str_length(pStr);
} }
}
if(Input()->KeyPressed(KEY_LCTRL) && Input()->KeyDown(KEY_C)) if(Input()->KeyPressed(KEY_LCTRL) && Input()->KeyDown(KEY_C))
{ {