mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 18:18:18 +00:00
Make sure GetClipboardText's null returns are handled properly
This commit is contained in:
parent
bd2b61f0e5
commit
a1403ef457
|
@ -116,30 +116,33 @@ 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 the text has more than one line, we send all lines except the last one
|
if(Text)
|
||||||
// the last one is set as in the text field
|
|
||||||
char Line[256];
|
|
||||||
int i, Begin = 0;
|
|
||||||
for(i = 0; i < str_length(text); i++)
|
|
||||||
{
|
{
|
||||||
if(text[i] == '\n')
|
// 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
|
||||||
|
char Line[256];
|
||||||
|
int i, Begin = 0;
|
||||||
|
for(i = 0; i < str_length(Text); i++)
|
||||||
{
|
{
|
||||||
int max = i - Begin + 1;
|
if(Text[i] == '\n')
|
||||||
if(max > (int)sizeof(Line))
|
{
|
||||||
max = sizeof(Line);
|
int max = i - Begin + 1;
|
||||||
str_copy(Line, text + Begin, max);
|
if(max > (int)sizeof(Line))
|
||||||
Begin = i+1;
|
max = sizeof(Line);
|
||||||
SayChat(Line);
|
str_copy(Line, Text + Begin, max);
|
||||||
while(text[i] == '\n') i++;
|
Begin = i+1;
|
||||||
|
SayChat(Line);
|
||||||
|
while(Text[i] == '\n') i++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
int max = i - Begin + 1;
|
||||||
|
if(max > (int)sizeof(Line))
|
||||||
|
max = sizeof(Line);
|
||||||
|
str_copy(Line, Text + Begin, max);
|
||||||
|
Begin = i+1;
|
||||||
|
m_Input.Add(Line);
|
||||||
}
|
}
|
||||||
int max = i - Begin + 1;
|
|
||||||
if(max > (int)sizeof(Line))
|
|
||||||
max = sizeof(Line);
|
|
||||||
str_copy(Line, text + Begin, max);
|
|
||||||
Begin = i+1;
|
|
||||||
m_Input.Add(Line);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Input()->KeyPressed(KEY_LCTRL) && Input()->KeyDown(KEY_C))
|
if(Input()->KeyPressed(KEY_LCTRL) && Input()->KeyDown(KEY_C))
|
||||||
|
|
|
@ -95,31 +95,34 @@ 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();
|
||||||
char Line[256];
|
if(Text)
|
||||||
int i, Begin = 0;
|
|
||||||
for(i = 0; i < str_length(Text); i++)
|
|
||||||
{
|
{
|
||||||
if(Text[i] == '\n')
|
char Line[256];
|
||||||
|
int i, Begin = 0;
|
||||||
|
for(i = 0; i < str_length(Text); i++)
|
||||||
{
|
{
|
||||||
if(i == Begin)
|
if(Text[i] == '\n')
|
||||||
{
|
{
|
||||||
Begin++;
|
if(i == Begin)
|
||||||
continue;
|
{
|
||||||
|
Begin++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int max = i - Begin + 1;
|
||||||
|
if(max > (int)sizeof(Line))
|
||||||
|
max = sizeof(Line);
|
||||||
|
str_copy(Line, Text + Begin, max);
|
||||||
|
Begin = i+1;
|
||||||
|
ExecuteLine(Line);
|
||||||
}
|
}
|
||||||
int max = i - Begin + 1;
|
|
||||||
if(max > (int)sizeof(Line))
|
|
||||||
max = sizeof(Line);
|
|
||||||
str_copy(Line, Text + Begin, max);
|
|
||||||
Begin = i+1;
|
|
||||||
ExecuteLine(Line);
|
|
||||||
}
|
}
|
||||||
|
int max = i - Begin + 1;
|
||||||
|
if(max > (int)sizeof(Line))
|
||||||
|
max = sizeof(Line);
|
||||||
|
str_copy(Line, Text + Begin, max);
|
||||||
|
Begin = i+1;
|
||||||
|
m_Input.Add(Line);
|
||||||
}
|
}
|
||||||
int max = i - Begin + 1;
|
|
||||||
if(max > (int)sizeof(Line))
|
|
||||||
max = sizeof(Line);
|
|
||||||
str_copy(Line, Text + Begin, max);
|
|
||||||
Begin = i+1;
|
|
||||||
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))
|
||||||
|
|
|
@ -241,16 +241,19 @@ 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();
|
||||||
int CharsLeft = StrSize - str_length(pStr);
|
if(Text)
|
||||||
int Offset = str_length(pStr);
|
|
||||||
for(int i = 0; i < str_length(Text) && i <= CharsLeft; i++)
|
|
||||||
{
|
{
|
||||||
if(Text[i] == '\n')
|
int CharsLeft = StrSize - str_length(pStr);
|
||||||
pStr[i + Offset] = ' ';
|
int Offset = str_length(pStr);
|
||||||
else
|
for(int i = 0; i < str_length(Text) && i <= CharsLeft; i++)
|
||||||
pStr[i + Offset] = Text[i];
|
{
|
||||||
|
if(Text[i] == '\n')
|
||||||
|
pStr[i + Offset] = ' ';
|
||||||
|
else
|
||||||
|
pStr[i + Offset] = Text[i];
|
||||||
|
}
|
||||||
|
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))
|
||||||
|
|
Loading…
Reference in a new issue