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-02-27 21:01:59 +01:00
|
|
|
// returns min(first, last)
|
2012-01-31 20:12:06 +01:00
|
|
|
BufferIterator begin() const;
|
2012-02-27 21:01:59 +01:00
|
|
|
// returns max(first, last) + 1
|
2012-01-31 20:12:06 +01:00
|
|
|
BufferIterator end() const;
|
|
|
|
|
2012-11-30 18:32:49 +01:00
|
|
|
private:
|
|
|
|
BufferIterator m_first;
|
|
|
|
BufferIterator m_last;
|
|
|
|
};
|
2012-01-31 20:12:06 +01:00
|
|
|
|
2012-11-30 18:32:49 +01:00
|
|
|
using CaptureList = std::vector<String>;
|
|
|
|
|
|
|
|
// A selection is a Range, associated with a CaptureList
|
|
|
|
// that updates itself when the buffer it points to gets modified.
|
|
|
|
struct Selection : public Range, public BufferChangeListener
|
|
|
|
{
|
|
|
|
Selection(const BufferIterator& first, const BufferIterator& last,
|
|
|
|
CaptureList captures = {});
|
|
|
|
Selection(Selection&& other);
|
|
|
|
Selection(const Selection& other);
|
|
|
|
~Selection();
|
|
|
|
|
|
|
|
Selection& operator=(const Selection& other);
|
|
|
|
Selection& operator=(Selection&& other);
|
2012-11-19 14:19:31 +01:00
|
|
|
|
2012-08-15 18:20:02 +02:00
|
|
|
void avoid_eol();
|
2012-01-31 20:12:06 +01:00
|
|
|
|
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-09-04 00:17:41 +02:00
|
|
|
void on_insert(const BufferIterator& begin,
|
|
|
|
const BufferIterator& end) override;
|
|
|
|
void on_erase(const BufferIterator& begin,
|
|
|
|
const BufferIterator& end) override;
|
2012-07-16 21:51:37 +02:00
|
|
|
|
2012-10-08 14:26:57 +02:00
|
|
|
void check_invariant() const;
|
|
|
|
|
2012-01-31 20:12:06 +01:00
|
|
|
void register_with_buffer();
|
|
|
|
void unregister_with_buffer();
|
2012-02-10 00:47:55 +01:00
|
|
|
|
2012-11-30 18:32:49 +01:00
|
|
|
CaptureList m_captures;
|
2012-02-10 00:47:55 +01:00
|
|
|
};
|
2012-11-30 18:32:49 +01:00
|
|
|
using SelectionList = std::vector<Selection>;
|
2012-02-10 00:47:55 +01:00
|
|
|
|
2012-11-30 18:32:49 +01:00
|
|
|
inline bool overlaps(const Selection& lhs, const Selection& rhs)
|
2012-11-12 20:27:56 +01:00
|
|
|
{
|
|
|
|
return (lhs.first() <= rhs.first() and lhs.last() >= rhs.first()) or
|
|
|
|
(lhs.first() <= rhs.last() and lhs.last() >= rhs.last());
|
|
|
|
}
|
|
|
|
|
2012-01-31 20:12:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // selection_hh_INCLUDED
|
|
|
|
|