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

@ -41,6 +41,15 @@ class Translations;
(((unsigned int)(x) >= 0x20) && \ (((unsigned int)(x) >= 0x20) && \
( (unsigned int)(x) <= 0x7e)) ( (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 // Checks whether a byte is an inner byte for an utf-8 multibyte sequence
#define IS_UTF8_MULTB_INNER(x) \ #define IS_UTF8_MULTB_INNER(x) \
(((unsigned char)(x) >= 0x80) && \ (((unsigned char)(x) >= 0x80) && \