1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-23 11:32:20 +03:00
kakoune/src/selection.hh

79 lines
2.0 KiB
C++
Raw Normal View History

#ifndef selection_hh_INCLUDED
#define selection_hh_INCLUDED
#include "buffer.hh"
namespace Kakoune
{
// An oriented, inclusive buffer range
struct Range
{
public:
Range(const BufferIterator& first, const BufferIterator& last)
: m_first{first}, m_last{last} {}
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-02-28 00:01:59 +04:00
// returns min(first, last)
BufferIterator begin() const;
2012-02-28 00:01:59 +04:00
// returns max(first, last) + 1
BufferIterator end() const;
private:
BufferIterator m_first;
BufferIterator m_last;
};
inline bool overlaps(const Range& lhs, const Range& rhs)
{
return (lhs.first() <= rhs.first() and lhs.last() >= rhs.first()) or
(lhs.first() <= rhs.last() and lhs.last() >= rhs.last());
}
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);
void avoid_eol();
CaptureList& captures() { return m_captures; }
const CaptureList& captures() const { return m_captures; }
private:
2012-09-04 02:17:41 +04:00
void on_insert(const BufferIterator& begin,
const BufferIterator& end) override;
void on_erase(const BufferIterator& begin,
const BufferIterator& end) override;
void check_invariant() const;
void register_with_buffer();
void unregister_with_buffer();
CaptureList m_captures;
};
using SelectionList = std::vector<Selection>;
}
#endif // selection_hh_INCLUDED