diff --git a/everything.hpp b/everything.hpp index d0c188a..cfdd2ea 100644 --- a/everything.hpp +++ b/everything.hpp @@ -107,7 +107,7 @@ public: //// Selection class Selection { Treap *file; - Treap content; + vector content; template void apply_on_selection(position p, F func, G func2); diff --git a/selection.cpp b/selection.cpp index 84adcde..85d89b0 100644 --- a/selection.cpp +++ b/selection.cpp @@ -26,16 +26,24 @@ void Selection::apply_on_selection(position p, F func, G func2) { } // Copying selection void Selection::copy_selection(position p) { + // Insert in the wrong order apply_on_selection(p, - [](count_type r, Treap *file, Treap *sel){ sel->insert(0, file->get_line(r, false)); }, - [](count_type r, count_type start_c, count_type size, Treap *file, Treap *sel) { sel->insert(0, file->get_line(r, false).substr(start_c - file->get_tab_offset({r, start_c}), size)); } + [](count_type r, Treap *file, vector *sel){ sel->push_back(file->get_line(r, false)); }, + [](count_type r, count_type start_c, count_type size, Treap *file, vector *sel) { sel->push_back(file->get_line(r, false).substr(start_c - file->get_tab_offset({r, start_c}), size)); } ); + + // Reverse order of the vector + for(count_type i = 0; i < content.size()/2; ++i) { + string tmp = content[content.size()-1 - i]; + content[content.size()-1 - i] = content[i]; + content[i] = tmp; + } } // Removing selection count_type Selection::remove_selection(position p) { apply_on_selection(p, - [](count_type r, Treap *file, Treap *sel){ file->remove(r); }, - [](count_type r, count_type start_c, count_type size, Treap *file, Treap *sel) { file->remove({r, start_c-file->get_tab_offset({r, start_c})}, size); } + [](count_type r, Treap *file, vector *sel){ file->remove(r); }, + [](count_type r, count_type start_c, count_type size, Treap *file, vector *sel) { file->remove({r, start_c-file->get_tab_offset({r, start_c})}, size); } ); count_type min = p.r, max = pos.r; @@ -54,17 +62,17 @@ count_type Selection::paste_selection(position p) { if(content.size() == 0) return 0; // Insert last line inside of this - file->insert(p, content.get_line(content.size()-1, false)); + file->insert(p, content.back()); if(content.size() == 1) return 1; // Insert first line in front and split file->split_line(p, false); - file->insert(p, content.get_line(0, false)); + file->insert(p, content.front()); if(content.size() == 2) return 4; // Insert lines for(count_type i = content.size()-2; i > 0; --i) - file->insert(p.r+1, content.get_line(i, false)); + file->insert(p.r+1, content[i]); return content.size()+2; }