summaryrefslogtreecommitdiff
path: root/src/line_modification.hh
blob: 75bacdbd6a3281205a00dad7d2fab36e23ec923b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef line_change_watcher_hh_INCLUDED
#define line_change_watcher_hh_INCLUDED

#include "array_view.hh"
#include "units.hh"
#include "utils.hh"
#include "range.hh"
#include "vector.hh"

namespace Kakoune
{

class Buffer;

struct LineModification
{
    LineCount old_line; // line position in the old buffer
    LineCount new_line; // new line position
    LineCount num_removed; // number of lines removed (including this one)
    LineCount num_added; // number of lines added (including this one)

    LineCount diff() const { return new_line - old_line + num_added - num_removed; }

    friend bool operator==(const LineModification& lhs, const LineModification& rhs) = default;
};

Vector<LineModification> compute_line_modifications(const Buffer& buffer, size_t timestamp);

using LineRange = Range<LineCount>;

struct LineRangeSet : private Vector<LineRange, MemoryDomain::Highlight>
{
    using Base = Vector<LineRange, MemoryDomain::Highlight>;
    using Base::operator[];
    using Base::begin;
    using Base::end;

    ConstArrayView<LineRange> view() const { return {data(), data() + size()}; }

    void reset(LineRange range) { Base::operator=({range}); }

    void update(ConstArrayView<LineModification> modifs);
    void add_range(LineRange range, FunctionRef<void (LineRange)> on_new_range);
    void remove_range(LineRange range);
};


}

#endif // line_change_watcher_hh_INCLUDED