MCPcopy Create free account
hub / github.com/ddnet/ddnet / ProcessInput

Method ProcessInput

src/game/client/lineinput.cpp:191–404  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189}
190
191bool CLineInput::ProcessInput(const IInput::CEvent &Event)
192{
193 // update derived attributes to handle external changes to the buffer
194 UpdateStrData();
195
196 const size_t OldCursorPos = m_CursorPos;
197 const bool Selecting = Input()->ShiftIsPressed();
198 const size_t SelectionLength = GetSelectionLength();
199 bool KeyHandled = false;
200
201 if(Event.m_Flags & IInput::FLAG_TEXT)
202 {
203 SetRange(Event.m_aText, m_SelectionStart, m_SelectionEnd);
204 KeyHandled = true;
205 }
206
207 if(Event.m_Flags & IInput::FLAG_PRESS)
208 {
209 const bool ModPressed = Input()->ModifierIsPressed();
210 const bool AltPressed = Input()->AltIsPressed();
211
212#ifdef CONF_PLATFORM_MACOSX
213 const bool MoveWord = AltPressed && !ModPressed;
214#else
215 const bool MoveWord = ModPressed && !AltPressed;
216#endif
217
218 if(Event.m_Key == KEY_BACKSPACE)
219 {
220 if(SelectionLength)
221 {
222 SetRange("", m_SelectionStart, m_SelectionEnd);
223 }
224 else
225 {
226 // If in MoveWord-mode, backspace will delete the word before the selection
227 if(SelectionLength)
228 m_SelectionEnd = m_CursorPos = m_SelectionStart;
229 if(m_CursorPos > 0)
230 {
231 size_t NewCursorPos = m_CursorPos;
232 MoveCursor(REWIND, MoveWord, m_pStr, m_Len, &NewCursorPos);
233 SetRange("", NewCursorPos, m_CursorPos);
234 }
235 m_SelectionStart = m_SelectionEnd = m_CursorPos;
236 }
237 KeyHandled = true;
238 }
239 else if(Event.m_Key == KEY_DELETE)
240 {
241 if(SelectionLength)
242 {
243 SetRange("", m_SelectionStart, m_SelectionEnd);
244 }
245 else
246 {
247 // If in MoveWord-mode, delete will delete the word after the selection
248 if(SelectionLength)

Callers 3

OnInputMethod · 0.80
OnInputMethod · 0.80
OnInputMethod · 0.80

Calls 7

InputFunction · 0.85
str_sanitize_ccFunction · 0.85
ShiftIsPressedMethod · 0.80
ModifierIsPressedMethod · 0.80
AltIsPressedMethod · 0.80
GetClipboardTextMethod · 0.80
SetClipboardTextMethod · 0.80

Tested by

no test coverage detected