From 52b8abfe023133aa1d30e15c02d9f5d22065c005 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 16 Nov 2011 19:23:09 +0000 Subject: [PATCH] Selections: add captures field Selections now can have associated captures, for backreferences when selections are created from a regex search --- src/window.cc | 7 +++++++ src/window.hh | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/window.cc b/src/window.cc index 6fd4c541..80a70f05 100644 --- a/src/window.cc +++ b/src/window.cc @@ -28,6 +28,13 @@ void Selection::merge_with(const Selection& selection) m_last = selection.m_last; } +BufferString Selection::capture(size_t index) const +{ + if (index < m_captures.size()) + return m_captures[index]; + return ""; +} + struct scoped_undo_group { scoped_undo_group(Buffer& buffer) diff --git a/src/window.hh b/src/window.hh index a3d1c4ab..c84bf8c7 100644 --- a/src/window.hh +++ b/src/window.hh @@ -14,8 +14,15 @@ namespace Kakoune struct Selection { - Selection(const BufferIterator& first, const BufferIterator& last) - : m_first(first), m_last(last) {} + typedef std::vector CaptureList; + + Selection(const BufferIterator& first, const BufferIterator& last, + const CaptureList& captures = CaptureList()) + : m_first(first), m_last(last), m_captures(captures) {} + + Selection(const BufferIterator& first, const BufferIterator& last, + CaptureList&& captures) + : m_first(first), m_last(last), m_captures(captures) {} BufferIterator begin() const; BufferIterator end() const; @@ -25,9 +32,14 @@ struct Selection void merge_with(const Selection& selection); + BufferString capture(size_t index) const; + const CaptureList& captures() const { return m_captures; } + private: DynamicBufferIterator m_first; DynamicBufferIterator m_last; + + CaptureList m_captures; }; typedef std::vector SelectionList;