From 18913cfbff30796118f2e08f53df8c5136b8007d Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 16 Nov 2011 19:24:37 +0000 Subject: [PATCH] IncrementalInserter: add insert_capture method bound to ^B --- src/main.cc | 6 ++++++ src/window.cc | 9 ++++++++- src/window.hh | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main.cc b/src/main.cc index 157b5ead..94ab9e45 100644 --- a/src/main.cc +++ b/src/main.cc @@ -284,6 +284,12 @@ void do_insert(Window& window, IncrementalInserter::Mode mode) case 27: return; + case 2: + c = getch(); + if (c >= '0' and c <= '9') + inserter.insert_capture(c - '0'); + break; + case 4: inserter.move_cursor({0, -1}); break; diff --git a/src/window.cc b/src/window.cc index 80a70f05..17d3904b 100644 --- a/src/window.cc +++ b/src/window.cc @@ -410,7 +410,7 @@ IncrementalInserter::IncrementalInserter(Window& window, Mode mode) ++pos; break; } - sel = Selection(pos, pos); + sel = Selection(pos, pos, sel.captures()); } } @@ -428,6 +428,13 @@ void IncrementalInserter::insert(const Window::String& string) m_window.insert_noundo(string); } +void IncrementalInserter::insert_capture(size_t index) +{ + for (auto& sel : m_window.m_selections) + m_window.m_buffer.insert(sel.begin(), sel.capture(index)); + m_window.scroll_to_keep_cursor_visible_ifn(); +} + void IncrementalInserter::erase() { move_cursor(DisplayCoord(0, -1)); diff --git a/src/window.hh b/src/window.hh index c84bf8c7..41556386 100644 --- a/src/window.hh +++ b/src/window.hh @@ -142,6 +142,7 @@ public: ~IncrementalInserter(); void insert(const Window::String& string); + void insert_capture(size_t index); void erase(); void move_cursor(const DisplayCoord& offset);