Kaynağa Gözat

fix(raylib): unified input processing loop

Refactored  to handle keys and characters in a single loop, resolving issues with modifier keys and ensuring consistent keybinding execution.
Bernardo Magri 1 hafta önce
ebeveyn
işleme
2e95afa9a7
1 değiştirilmiş dosya ile 15 ekleme ve 25 silme
  1. 15 25
      src/raylib_editor.cpp

+ 15 - 25
src/raylib_editor.cpp

@@ -200,40 +200,30 @@ void RaylibEditor::process_input() {
     int key = GetKeyPressed();
     while (key != 0) {
         std::string lumacs_key = resolve_raylib_key(key, ctrl, alt, shift);
-        bool is_printable = (key >= 32 && key <= 126); 
-        bool is_special = !is_printable || (key == KEY_SPACE);
-        bool should_handle = (ctrl || alt || is_special);
+        
+        spdlog::debug("Raylib Key: {} -> {}", key, lumacs_key);
 
-        if (should_handle && !lumacs_key.empty()) {
+        if (!lumacs_key.empty()) {
             bool handled_by_minibuffer = core_->minibuffer_manager().handle_key_event(lumacs_key);
             if (!handled_by_minibuffer) {
                 KeyProcessingResult result = core_->keybinding_manager().process_key(lumacs_key);
                 if (result.type == KeyResult::Unbound) {
-                    if (lumacs_key == "Return") core_->command_system().execute("newline", {});
-                    else if (lumacs_key == "Backspace") core_->command_system().execute("delete-backward-char", {});
-                    else if (lumacs_key == "Delete") core_->command_system().execute("delete-char", {});
-                    else if (lumacs_key == "Tab") core_->command_system().execute("self-insert-command", {"\t"});
-                }
-            }
-        }
-        key = GetKeyPressed();
-    }
-
-    if (!ctrl && !alt) {
-        int char_code = GetCharPressed();
-        while (char_code != 0) {
-            if (char_code >= 32 && char_code <= 126) {
-                std::string text(1, (char)char_code);
-                bool handled_by_minibuffer = core_->minibuffer_manager().handle_key_event(text);
-                if (!handled_by_minibuffer) {
-                    KeyProcessingResult result = core_->keybinding_manager().process_key(text);
-                    if (result.type == KeyResult::Unbound) {
-                        core_->command_system().execute("self-insert-command", {text});
+                     // Basic fallback for unbound keys (especially simple typing)
+                    if (lumacs_key.length() == 1 && !ctrl && !alt) {
+                        core_->command_system().execute("self-insert-command", {lumacs_key});
+                    } else if (lumacs_key == "Return") {
+                        core_->command_system().execute("newline", {});
+                    } else if (lumacs_key == "Backspace") {
+                         core_->command_system().execute("delete-backward-char", {});
+                    } else if (lumacs_key == "Delete") {
+                         core_->command_system().execute("delete-char", {});
+                    } else if (lumacs_key == "Tab") {
+                         core_->command_system().execute("self-insert-command", {"\t"});
                     }
                 }
             }
-            char_code = GetCharPressed();
         }
+        key = GetKeyPressed();
     }
 }