aboutsummaryrefslogtreecommitdiff
path: root/src/osx
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-11-15 17:19:09 +0800
committercrupest <crupest@outlook.com>2021-11-15 17:19:09 +0800
commite78a49111f454a8cdee180f5089e138d94416597 (patch)
tree94fe4fbfdebc54c37941a17e32c0f04799108d66 /src/osx
parent4ac58d91bac0cebe2bdf5e11b9d63b9c41e6b39e (diff)
downloadcru-e78a49111f454a8cdee180f5089e138d94416597.tar.gz
cru-e78a49111f454a8cdee180f5089e138d94416597.tar.bz2
cru-e78a49111f454a8cdee180f5089e138d94416597.zip
...
Diffstat (limited to 'src/osx')
-rw-r--r--src/osx/gui/Keyboard.mm2
-rw-r--r--src/osx/gui/Window.mm26
2 files changed, 22 insertions, 6 deletions
diff --git a/src/osx/gui/Keyboard.mm b/src/osx/gui/Keyboard.mm
index 8e14ec83..ff2f110b 100644
--- a/src/osx/gui/Keyboard.mm
+++ b/src/osx/gui/Keyboard.mm
@@ -87,6 +87,7 @@ KeyCode KeyCodeFromOsxToCru(unsigned short n) {
CRU_DEFINE_KEYCODE_MAP(kVK_ANSI_Keypad7, KeyCode::NumPad7)
CRU_DEFINE_KEYCODE_MAP(kVK_ANSI_Keypad8, KeyCode::NumPad8)
CRU_DEFINE_KEYCODE_MAP(kVK_ANSI_Keypad9, KeyCode::NumPad9)
+ CRU_DEFINE_KEYCODE_MAP(kVK_Space, KeyCode::Space)
default:
return KeyCode::Unknown;
}
@@ -177,6 +178,7 @@ unsigned short KeyCodeFromCruToOsx(KeyCode k) {
CRU_DEFINE_KEYCODE_MAP(KeyCode::NumPad7, kVK_ANSI_Keypad7)
CRU_DEFINE_KEYCODE_MAP(KeyCode::NumPad8, kVK_ANSI_Keypad8)
CRU_DEFINE_KEYCODE_MAP(KeyCode::NumPad9, kVK_ANSI_Keypad9)
+ CRU_DEFINE_KEYCODE_MAP(KeyCode::Space, kVK_Space)
default:
return 0;
}
diff --git a/src/osx/gui/Window.mm b/src/osx/gui/Window.mm
index 356c6be6..04ec4bce 100644
--- a/src/osx/gui/Window.mm
+++ b/src/osx/gui/Window.mm
@@ -432,9 +432,10 @@ cru::platform::gui::KeyModifier GetKeyModifier(NSEvent* event) {
namespace {
using cru::platform::gui::KeyCode;
-const std::unordered_set<KeyCode> bypass_codes{
- KeyCode::Backspace, KeyCode::Delete, KeyCode::Left, KeyCode::Right, KeyCode::Up,
- KeyCode::Down, KeyCode::Home, KeyCode::End, KeyCode::PageUp, KeyCode::PageDown};
+const std::unordered_set<KeyCode> bypass_codes{KeyCode::Return, KeyCode::Space, KeyCode::Backspace,
+ KeyCode::Delete, KeyCode::Left, KeyCode::Right,
+ KeyCode::Up, KeyCode::Down, KeyCode::Home,
+ KeyCode::End, KeyCode::PageUp, KeyCode::PageDown};
}
- (void)keyDown:(NSEvent*)event {
@@ -448,9 +449,22 @@ const std::unordered_set<KeyCode> bypass_codes{
auto c = cru::platform::gui::osx::KeyCodeFromOsxToCru(event.keyCode);
- if (!(input_context->GetCompositionText().text.empty() && bypass_codes.count(c)) &&
- input_context->IsEnabled()) {
- handled = [[self inputContext] handleEvent:event];
+ if (input_context->IsEnabled()) {
+ if (bypass_codes.count(c)) {
+ if (!(input_context->GetCompositionText().text.empty())) {
+ handled = [[self inputContext] handleEvent:event];
+ } else {
+ if (c == KeyCode::Return) {
+ _input_context_p->RaiseTextEvent(u"\n");
+ handled = true;
+ } else if (c == KeyCode::Space) {
+ _input_context_p->RaiseTextEvent(u" ");
+ handled = true;
+ }
+ }
+ } else {
+ handled = [[self inputContext] handleEvent:event];
+ }
}
if (!handled) {