Parcourir la source

feat(testing): Add BufferManager unit tests and fix InputPipeline tests

Bernardo Magri il y a 1 mois
Parent
commit
a97c14f3e4
5 fichiers modifiés avec 56 ajouts et 2 suppressions
  1. 1 1
      documentation/PLAN.md
  2. 37 0
      include/lumacs/layout_node.hpp
  3. 6 0
      src/buffer_manager.cpp
  4. 11 1
      src/keybinding.cpp
  5. 1 0
      tests/CMakeLists.txt

+ 1 - 1
documentation/PLAN.md

@@ -211,7 +211,7 @@ This phase aimed to enhance the Command System to support robust, type-safe, and
 - **Focus Stability**: GTK frontend caches active_window_ during redraw cycles to prevent race conditions in multi-window async rendering
 - **GTK Popup**: `GtkCompletionPopup` logic is stubbed to fix build; needs full GTK4 migration (Popover).
 - **TUI ISearch**: ISearch highlighting temporarily disabled in TUI.
-- **Backspace Bug**: Backspace functionality is currently buggy, leading to the cursor staying in place after deletion, and requires further investigation.
+- **Backspace Bug**: ✅ Fixed. Was a logical error in Lua's `lumacs_backward_delete_char` function regarding position calculation for `erase_char` and cursor update.
 
 ## General Instructions for the LLM Executor
 

+ 37 - 0
include/lumacs/layout_node.hpp

@@ -0,0 +1,37 @@
+#pragma once
+
+#include <memory>
+#include <vector>
+#include "lumacs/window.hpp" // For Window class
+#include "lumacs/buffer.hpp" // For shared_ptr<Buffer> (indirectly via Window)
+
+namespace lumacs {
+
+// Forward declaration
+class Window;
+
+/// @brief Represents a node in the window layout tree.
+/// Can be a leaf node (holding a Window) or an internal node (representing a split).
+struct LayoutNode {
+    enum class Type {
+        Leaf,
+        HorizontalSplit, // Children are top/bottom
+        VerticalSplit    // Children are left/right
+    };
+
+    Type type;
+    std::shared_ptr<Window> window; // Valid if type is Leaf
+    std::shared_ptr<LayoutNode> child1; // Valid if type is Horizontal/VerticalSplit
+    std::shared_ptr<LayoutNode> child2; // Valid if type is Horizontal/VerticalSplit
+    double ratio = 0.5; // Ratio for split (e.g., 0.5 for a 50/50 split)
+
+    // Constructor for leaf nodes (a window)
+    explicit LayoutNode(std::shared_ptr<Window> win)
+        : type(Type::Leaf), window(std::move(win)) {}
+
+    // Constructor for internal nodes (a split)
+    LayoutNode(Type t, std::shared_ptr<LayoutNode> c1, std::shared_ptr<LayoutNode> c2)
+        : type(t), child1(std::move(c1)), child2(std::move(c2)) {}
+};
+
+} // namespace lumacs

+ 6 - 0
src/buffer_manager.cpp

@@ -9,6 +9,12 @@ BufferManager::BufferManager(EditorCore& core) : core_(core) {
 }
 
 std::shared_ptr<Buffer> BufferManager::create_buffer_no_window(std::string name) {
+    // Check if a buffer with this name already exists
+    auto existing_buf = get_buffer_by_name(name);
+    if (existing_buf) {
+        return existing_buf;
+    }
+
     auto new_buf = std::make_shared<Buffer>(std::move(name));
     buffers_.push_back(new_buf);
     return new_buf;

+ 11 - 1
src/keybinding.cpp

@@ -3,6 +3,7 @@
 #include <sstream>
 #include <algorithm>
 #include <cctype>
+#include <iostream> // For std::cerr debugging
 
 namespace lumacs {
 
@@ -42,9 +43,18 @@ namespace {
         if (s == "/") return BaseKey::Slash;
         if (s == "`") return BaseKey::Backtick;
         if (s == "[") return BaseKey::LeftBracket;
-        if (s == "\\") return BaseKey::Backslash; // Fixed escaping
+        if (s == "\\") return BaseKey::Backslash;
         if (s == "]") return BaseKey::RightBracket;
         if (s == "'") return BaseKey::Quote;
+        
+        // Handle F-keys
+        if (s.length() > 1 && s[0] == 'F' && std::isdigit(s[1])) {
+            int f_num = std::stoi(s.substr(1));
+            if (f_num >= 1 && f_num <= 12) {
+                return static_cast<BaseKey>(static_cast<int>(BaseKey::F1) + (f_num - 1));
+            }
+        }
+
         // Add more keys as needed
         return BaseKey::Unknown;
     }

+ 1 - 0
tests/CMakeLists.txt

@@ -16,6 +16,7 @@ add_executable(test_runner
     test_buffer.cpp
     test_editor_core.cpp
     test_input_pipeline.cpp
+    test_buffer_manager.cpp
 )
 
 target_link_libraries(test_runner PRIVATE