summaryrefslogtreecommitdiff
path: root/src/editor.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2012-02-10 13:58:29 +0000
committerMaxime Coste <frrrwww@gmail.com>2012-02-10 13:58:29 +0000
commit0352ad798386c856ba314c6d797b483adfe5b38d (patch)
treee6b348288ee37a5fd5df6f98125ec8868aa7f617 /src/editor.cc
parentd84d085cc268c4127a624d05063f64df5ffa361d (diff)
Editor: replace all captures if one capture is present
before, selecting with 2 captures after selecting with 3 captures would keep the third capture from the first selection.
Diffstat (limited to 'src/editor.cc')
-rw-r--r--src/editor.cc21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/editor.cc b/src/editor.cc
index 9516460f..2cd790b7 100644
--- a/src/editor.cc
+++ b/src/editor.cc
@@ -5,6 +5,8 @@
#include "register.hh"
#include "register_manager.hh"
+#include <array>
+
namespace Kakoune
{
@@ -144,8 +146,9 @@ void Editor::select(const Selector& selector, bool append)
{
check_invariant();
- std::vector<std::vector<String>> captures;
+ std::array<std::vector<String>, 10> captures;
+ size_t capture_count = -1;
for (auto& sel : m_selections.back())
{
SelectionAndCaptures res = selector(sel);
@@ -154,14 +157,14 @@ void Editor::select(const Selector& selector, bool append)
else
sel = std::move(res.selection);
- assert(captures.empty() or captures.size() == res.captures.size());
- captures.resize(res.captures.size());
+ assert(capture_count == -1 or capture_count == res.captures.size());
+ capture_count = res.captures.size();
for (size_t i = 0; i < res.captures.size(); ++i)
captures[i].push_back(res.captures[i]);
}
- if (not captures.empty())
+ if (not captures[0].empty())
{
for (size_t i = 0; i < captures.size(); ++i)
RegisterManager::instance()['0' + i] = std::move(captures[i]);
@@ -177,8 +180,9 @@ void Editor::multi_select(const MultiSelector& selector)
{
check_invariant();
- std::vector<std::vector<String>> captures;
+ std::array<std::vector<String>, 10> captures;
+ size_t capture_count = -1;
SelectionList new_selections;
for (auto& sel : m_selections.back())
{
@@ -187,8 +191,9 @@ void Editor::multi_select(const MultiSelector& selector)
{
new_selections.push_back(sel_and_cap.selection);
- assert(captures.empty() or captures.size() == sel_and_cap.captures.size());
- captures.resize(sel_and_cap.captures.size());
+ assert(capture_count == -1 or
+ capture_count == sel_and_cap.captures.size());
+ capture_count = sel_and_cap.captures.size();
for (size_t i = 0; i < sel_and_cap.captures.size(); ++i)
captures[i].push_back(sel_and_cap.captures[i]);
@@ -199,7 +204,7 @@ void Editor::multi_select(const MultiSelector& selector)
m_selections.back() = std::move(new_selections);
- if (not captures.empty())
+ if (not captures[0].empty())
{
for (size_t i = 0; i < captures.size(); ++i)
RegisterManager::instance()['0' + i] = std::move(captures[i]);