Merge pull request #474 from Henningstone/pr-ddnet-chat-input-jump

Jump to special characters with CTRL+arrowkeys in chat input
This commit is contained in:
heinrich5991 2016-05-09 18:07:41 +02:00
commit fe3e05cee5

View file

@ -150,6 +150,35 @@ bool CChat::OnInput(IInput::CEvent Event)
Input()->SetClipboardText(m_Input.GetString());
}
if(Input()->KeyIsPressed(KEY_LCTRL)) // jump to spaces and special ASCII characters
{
int SearchDirection = 0;
if(Input()->KeyPress(KEY_LEFT))
SearchDirection = -1;
else if(Input()->KeyPress(KEY_RIGHT))
SearchDirection = 1;
if(SearchDirection != 0)
{
int FoundAt = SearchDirection > 0 ? m_Input.GetLength()-1 : 0;
for(int i = m_Input.GetCursorOffset()+SearchDirection; SearchDirection > 0 ? i < m_Input.GetLength()-1 : i > 0; i+=SearchDirection)
{
int next = i+SearchDirection;
if( (m_Input.GetString()[next] == ' ') ||
(m_Input.GetString()[next] >= 32 && m_Input.GetString()[next] <= 47) ||
(m_Input.GetString()[next] >= 58 && m_Input.GetString()[next] <= 64) ||
(m_Input.GetString()[next] >= 91 && m_Input.GetString()[next] <= 96) )
{
FoundAt = i;
if(SearchDirection < 0)
FoundAt++;
break;
}
}
m_Input.SetCursorOffset(FoundAt);
}
}
if(Event.m_Flags&IInput::FLAG_PRESS && Event.m_Key == KEY_ESCAPE)
{
m_Mode = MODE_NONE;