Handle num lock in chat (#12984)

This commit is contained in:
Jude Melton-Houghton 2022-11-30 10:43:12 -05:00 committed by GitHub
parent 3ff8adf599
commit 055fc69c11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 83 additions and 51 deletions

@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "log.h"
#include "gettext.h"
#include "irrlicht_changes/CGUITTFont.h"
#include "util/string.h"
#include <string>
inline u32 clamp_u8(s32 value)
@ -436,6 +437,10 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
return true;
}
// Mac OS sends private use characters along with some keys.
bool has_char = event.KeyInput.Char && !event.KeyInput.Control &&
!iswcntrl(event.KeyInput.Char) && !IS_PRIVATE_USE_CHAR(event.KeyInput.Char);
if (event.KeyInput.Key == KEY_ESCAPE) {
closeConsoleAtOnce();
m_close_on_enter = false;
@ -445,14 +450,18 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
}
else if(event.KeyInput.Key == KEY_PRIOR)
{
if (!has_char) { // no num lock
m_chat_backend->scrollPageUp();
return true;
}
}
else if(event.KeyInput.Key == KEY_NEXT)
{
if (!has_char) { // no num lock
m_chat_backend->scrollPageDown();
return true;
}
}
else if(event.KeyInput.Key == KEY_RETURN)
{
prompt.addToHistory(prompt.getLine());
@ -466,20 +475,25 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
}
else if(event.KeyInput.Key == KEY_UP)
{
if (!has_char) { // no num lock
// Up pressed
// Move back in history
prompt.historyPrev();
return true;
}
}
else if(event.KeyInput.Key == KEY_DOWN)
{
if (!has_char) { // no num lock
// Down pressed
// Move forward in history
prompt.historyNext();
return true;
}
}
else if(event.KeyInput.Key == KEY_LEFT || event.KeyInput.Key == KEY_RIGHT)
{
if (!has_char) { // no num lock
// Left/right pressed
// Move/select character/word to the left depending on control and shift keys
ChatPrompt::CursorOp op = event.KeyInput.Shift ?
@ -494,8 +508,10 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
prompt.cursorOperation(op, dir, scope);
return true;
}
}
else if(event.KeyInput.Key == KEY_HOME)
{
if (!has_char) { // no num lock
// Home pressed
// move to beginning of line
prompt.cursorOperation(
@ -504,8 +520,10 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
ChatPrompt::CURSOROP_SCOPE_LINE);
return true;
}
}
else if(event.KeyInput.Key == KEY_END)
{
if (!has_char) { // no num lock
// End pressed
// move to end of line
prompt.cursorOperation(
@ -514,6 +532,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
ChatPrompt::CURSOROP_SCOPE_LINE);
return true;
}
}
else if(event.KeyInput.Key == KEY_BACK)
{
// Backspace or Ctrl-Backspace pressed
@ -530,6 +549,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
}
else if(event.KeyInput.Key == KEY_DELETE)
{
if (!has_char) { // no num lock
// Delete or Ctrl-Delete pressed
// delete character / word to the right
ChatPrompt::CursorOpScope scope =
@ -542,6 +562,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
scope);
return true;
}
}
else if(event.KeyInput.Key == KEY_KEY_A && event.KeyInput.Control)
{
// Ctrl-A pressed
@ -624,7 +645,9 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
bool backwards = event.KeyInput.Shift;
prompt.nickCompletion(names, backwards);
return true;
} else if (!iswcntrl(event.KeyInput.Char) && !event.KeyInput.Control) {
}
if (has_char) {
prompt.input(event.KeyInput.Char);
return true;
}

@ -41,6 +41,15 @@ class Translations;
(((unsigned int)(x) >= 0x20) && \
( (unsigned int)(x) <= 0x7e))
// Checks whether a value is in a Unicode private use area
#define IS_PRIVATE_USE_CHAR(x) \
(((wchar_t)(x) >= 0xE000 && \
(wchar_t)(x) <= 0xF8FF) || \
((wchar_t)(x) >= 0xF0000 && \
(wchar_t)(x) <= 0xFFFFD) || \
((wchar_t)(x) >= 0x100000 && \
(wchar_t)(x) <= 0x10FFFD)) \
// Checks whether a byte is an inner byte for an utf-8 multibyte sequence
#define IS_UTF8_MULTB_INNER(x) \
(((unsigned char)(x) >= 0x80) && \