#pragma once #include #include #include #include "lumacs/buffer.hpp" // For Position and Range namespace lumacs { /// @brief Implements an Emacs-like kill ring (clipboard history). /// The kill ring stores killed (cut) text in a circular buffer. class KillRingManager { public: explicit KillRingManager(size_t max_size = 60); /// @brief Pushes text onto the kill ring. If the last entry was also a kill /// (not a yank), it appends to that entry. Otherwise, it creates a new entry. /// @param text The text to push. void push(const std::string& text); /// @brief Retrieves the current (most recently pushed) entry in the kill ring. /// @return The current entry. Returns empty string if ring is empty. [[nodiscard]] std::string current() const; /// @brief Rotates the kill ring and retrieves the previous entry. /// Used for `yank-pop`. /// @return The previous entry. Returns empty string if ring is empty. [[nodiscard]] std::string previous(); /// @brief Checks if the kill ring is empty. [[nodiscard]] bool empty() const { return ring_.empty(); } /// @brief Clears the kill ring. void clear() { ring_.clear(); } private: std::deque ring_; size_t max_size_; bool last_action_was_kill_ = false; // Tracks if the last push was a kill or append }; } // namespace lumacs