2012-01-31 20:12:06 +01:00
|
|
|
#ifndef selection_hh_INCLUDED
|
|
|
|
#define selection_hh_INCLUDED
|
|
|
|
|
|
|
|
#include "buffer.hh"
|
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2012-11-30 18:32:49 +01:00
|
|
|
// An oriented, inclusive buffer range
|
|
|
|
struct Range
|
2012-01-31 20:12:06 +01:00
|
|
|
{
|
2012-11-30 18:32:49 +01:00
|
|
|
public:
|
|
|
|
Range(const BufferIterator& first, const BufferIterator& last)
|
|
|
|
: m_first{first}, m_last{last} {}
|
2012-01-31 20:12:06 +01:00
|
|
|
|
2012-11-30 18:32:49 +01:00
|
|
|
void merge_with(const Range& range);
|
|
|
|
|
|
|
|
BufferIterator& first() { return m_first; }
|
|
|
|
BufferIterator& last() { return m_last; }
|
|
|
|
|
|
|
|
const BufferIterator& first() const { return m_first; }
|
|
|
|
const BufferIterator& last() const { return m_last; }
|
2012-01-31 20:12:06 +01:00
|
|
|
|
2012-12-11 19:51:59 +01:00
|
|
|
bool operator== (const Range& other) const
|
|
|
|
{
|
|
|
|
return m_first == other.m_first and m_last == other.m_last;
|
|
|
|
}
|
|
|
|
|
2013-05-24 14:25:50 +02:00
|
|
|
const BufferIterator& min() const { return std::min(m_first, m_last); }
|
|
|
|
const BufferIterator& max() const { return std::max(m_first, m_last); }
|
2012-01-31 20:12:06 +01:00
|
|
|
|
2012-11-30 18:32:49 +01:00
|
|
|
private:
|
|
|
|
BufferIterator m_first;
|
|
|
|
BufferIterator m_last;
|
|
|
|
};
|
2012-01-31 20:12:06 +01:00
|
|
|
|
2012-12-11 14:11:33 +01:00
|
|
|
inline bool overlaps(const Range& lhs, const Range& rhs)
|
|
|
|
{
|
2013-05-24 14:25:50 +02:00
|
|
|
return lhs.min() <= rhs.min() ? lhs.max() >= rhs.min()
|
|
|
|
: lhs.min() <= rhs.max();
|
2013-05-03 13:53:23 +02:00
|
|
|
}
|
|
|
|
|
2012-11-30 18:32:49 +01:00
|
|
|
using CaptureList = std::vector<String>;
|
|
|
|
|
|
|
|
// A selection is a Range, associated with a CaptureList
|
2012-12-11 19:51:59 +01:00
|
|
|
struct Selection : public Range
|
2012-11-30 18:32:49 +01:00
|
|
|
{
|
|
|
|
Selection(const BufferIterator& first, const BufferIterator& last,
|
2012-12-11 19:51:59 +01:00
|
|
|
CaptureList captures = {})
|
2013-01-04 18:39:13 +01:00
|
|
|
: Range(first, last), m_captures(std::move(captures)) {}
|
2012-11-19 14:19:31 +01:00
|
|
|
|
2013-04-22 14:18:49 +02:00
|
|
|
Selection(const Range& range)
|
|
|
|
: Range(range) {}
|
|
|
|
|
2012-11-30 18:32:49 +01:00
|
|
|
CaptureList& captures() { return m_captures; }
|
|
|
|
const CaptureList& captures() const { return m_captures; }
|
|
|
|
|
2012-09-26 20:33:47 +02:00
|
|
|
private:
|
2012-11-30 18:32:49 +01:00
|
|
|
CaptureList m_captures;
|
2012-02-10 00:47:55 +01:00
|
|
|
};
|
2013-05-02 19:04:59 +02:00
|
|
|
|
|
|
|
struct SelectionList : std::vector<Selection>
|
|
|
|
{
|
|
|
|
using std::vector<Selection>::vector;
|
|
|
|
|
|
|
|
void update_insert(const BufferCoord& begin, const BufferCoord& end);
|
|
|
|
void update_erase(const BufferCoord& begin, const BufferCoord& end);
|
2013-05-03 13:38:48 +02:00
|
|
|
|
|
|
|
void check_invariant() const;
|
2013-05-02 19:04:59 +02:00
|
|
|
};
|
2012-02-10 00:47:55 +01:00
|
|
|
|
2012-01-31 20:12:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // selection_hh_INCLUDED
|