|
|
@@ -1,7 +1,6 @@
|
|
|
#include "lumacs/rectangle_manager.hpp"
|
|
|
#include "lumacs/editor_core.hpp" // For EditorCore access
|
|
|
#include <algorithm>
|
|
|
-#include <iostream> // TODO: Replace with proper logging
|
|
|
|
|
|
namespace lumacs {
|
|
|
|
|
|
@@ -71,6 +70,18 @@ void RectangleManager::kill_rectangle() {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // Push the killed rectangle content to the global kill ring as a single string
|
|
|
+ std::string killed_text_combined;
|
|
|
+ for (size_t i = 0; i < rectangle_kill_ring_.size(); ++i) {
|
|
|
+ killed_text_combined += rectangle_kill_ring_[i];
|
|
|
+ if (i < rectangle_kill_ring_.size() - 1) {
|
|
|
+ killed_text_combined += '\n';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!killed_text_combined.empty()) {
|
|
|
+ core_.kill_ring_manager().push(killed_text_combined);
|
|
|
+ }
|
|
|
|
|
|
buf.deactivate_mark();
|
|
|
core_.emit_event(EditorEvent::BufferModified);
|
|
|
@@ -87,12 +98,6 @@ void RectangleManager::yank_rectangle() {
|
|
|
auto& buf = core_.buffer();
|
|
|
Position cursor = core_.active_window()->cursor();
|
|
|
|
|
|
- // Determine the width of the rectangle from the first line of the killed content
|
|
|
- size_t rect_width = 0;
|
|
|
- if (!rectangle_kill_ring_.empty()) {
|
|
|
- rect_width = rectangle_kill_ring_[0].length();
|
|
|
- }
|
|
|
-
|
|
|
// Insert rectangle starting at cursor position
|
|
|
for (size_t i = 0; i < rectangle_kill_ring_.size(); ++i) {
|
|
|
Position insert_pos{cursor.line + i, cursor.column};
|
|
|
@@ -103,26 +108,13 @@ void RectangleManager::yank_rectangle() {
|
|
|
buf.insert_newline(Position{buf.line_count() - 1, buf.line(buf.line_count() - 1).size()});
|
|
|
}
|
|
|
|
|
|
- // Get the current line content where we want to insert/replace
|
|
|
+ // Get the current line content where we want to insert
|
|
|
std::string current_line_text = buf.line(insert_pos.line);
|
|
|
|
|
|
// Pad line with spaces if the insertion point is beyond current line length
|
|
|
if (current_line_text.size() < insert_pos.column) {
|
|
|
std::string padding(insert_pos.column - current_line_text.size(), ' ');
|
|
|
buf.insert(Position{insert_pos.line, current_line_text.size()}, padding);
|
|
|
- current_line_text = buf.line(insert_pos.line); // Refresh line after padding
|
|
|
- }
|
|
|
-
|
|
|
- // Calculate the range to replace or insert
|
|
|
- // size_t effective_end_col = insert_pos.column + rect_width; // Removed unused variable
|
|
|
- size_t existing_text_len_in_rect = 0;
|
|
|
- if (current_line_text.size() > insert_pos.column) {
|
|
|
- existing_text_len_in_rect = std::min(rect_width, current_line_text.size() - insert_pos.column);
|
|
|
- }
|
|
|
-
|
|
|
- // Erase existing text within the rectangular region if any
|
|
|
- if (existing_text_len_in_rect > 0) {
|
|
|
- buf.erase(Range{insert_pos, Position{insert_pos.line, insert_pos.column + existing_text_len_in_rect}});
|
|
|
}
|
|
|
|
|
|
// Insert the killed rectangle content for the current line
|
|
|
@@ -130,7 +122,6 @@ void RectangleManager::yank_rectangle() {
|
|
|
}
|
|
|
|
|
|
core_.emit_event(EditorEvent::BufferModified);
|
|
|
- core_.set_message(std::string("Rectangle yanked (") + std::to_string(rectangle_kill_ring_.size()) + " lines)");
|
|
|
}
|
|
|
|
|
|
void RectangleManager::string_rectangle(const std::string& text) {
|