From ed8a0b5eee8ed86ba53021e1799a3c40973f192c Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Sat, 1 Jun 2019 17:11:35 +0200 Subject: [PATCH] Add ctrl-u delete in client console Extends shortcuts from: https://github.com/ddnet/ddnet/commit/e9f8bd42b7dd6d6b2553c19d785b1bf6f71a455a --- src/game/client/components/console.cpp | 5 +++++ src/game/client/lineinput.cpp | 7 +++++++ src/game/client/lineinput.h | 1 + 3 files changed, 13 insertions(+) diff --git a/src/game/client/components/console.cpp b/src/game/client/components/console.cpp index 5a2b39010..f276ba625 100644 --- a/src/game/client/components/console.cpp +++ b/src/game/client/components/console.cpp @@ -149,6 +149,11 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event) { m_Input.SetCursorOffset(m_Input.GetLength()); } + else if(m_pGameConsole->Input()->KeyIsPressed(KEY_LCTRL) && m_pGameConsole->Input()->KeyPress(KEY_U)) + { + m_Input.DeleteFromCursor(); + Handled = true; + } if(Event.m_Flags&IInput::FLAG_PRESS) { diff --git a/src/game/client/lineinput.cpp b/src/game/client/lineinput.cpp index fdf48aa1d..d2ad44e9e 100644 --- a/src/game/client/lineinput.cpp +++ b/src/game/client/lineinput.cpp @@ -142,6 +142,13 @@ bool CLineInput::Manipulate(IInput::CEvent Event, char *pStr, int StrMaxSize, in return Changes; } +void CLineInput::DeleteFromCursor() +{ + char aBuf[MAX_SIZE]; + str_copy(aBuf, &m_Str[m_CursorPos], sizeof(aBuf)); + Set(aBuf); SetCursorOffset(0); +} + void CLineInput::ProcessInput(IInput::CEvent e) { Manipulate(e, m_Str, MAX_SIZE, MAX_CHARS, &m_Len, &m_CursorPos, &m_NumChars); diff --git a/src/game/client/lineinput.h b/src/game/client/lineinput.h index 8ffefb0d7..85aaffa37 100644 --- a/src/game/client/lineinput.h +++ b/src/game/client/lineinput.h @@ -41,6 +41,7 @@ public: int GetLength(bool Editing = false) const { return Editing ? m_FakeLen : m_Len; } int GetCursorOffset(bool Editing = false) const { return Editing ? m_FakeCursorPos : m_CursorPos; } void SetCursorOffset(int Offset) { m_CursorPos = Offset > m_Len ? m_Len : Offset < 0 ? 0 : Offset; } + void DeleteFromCursor(); }; #endif