kakoune

Fork of kakoune, an acceptable text editor
git clone git://git.laack.co/kakoune.git
Log | Files | Refs

line_modification.hh (1401B)


      1 #ifndef line_change_watcher_hh_INCLUDED
      2 #define line_change_watcher_hh_INCLUDED
      3 
      4 #include "array_view.hh"
      5 #include "units.hh"
      6 #include "utils.hh"
      7 #include "range.hh"
      8 #include "vector.hh"
      9 
     10 namespace Kakoune
     11 {
     12 
     13 class Buffer;
     14 
     15 struct LineModification
     16 {
     17     LineCount old_line; // line position in the old buffer
     18     LineCount new_line; // new line position
     19     LineCount num_removed; // number of lines removed (including this one)
     20     LineCount num_added; // number of lines added (including this one)
     21 
     22     LineCount diff() const { return new_line - old_line + num_added - num_removed; }
     23 
     24     friend bool operator==(const LineModification& lhs, const LineModification& rhs) = default;
     25 };
     26 
     27 Vector<LineModification> compute_line_modifications(const Buffer& buffer, size_t timestamp);
     28 
     29 using LineRange = Range<LineCount>;
     30 
     31 struct LineRangeSet : private Vector<LineRange, MemoryDomain::Highlight>
     32 {
     33     using Base = Vector<LineRange, MemoryDomain::Highlight>;
     34     using Base::operator[];
     35     using Base::begin;
     36     using Base::end;
     37 
     38     ConstArrayView<LineRange> view() const { return {data(), data() + size()}; }
     39 
     40     void reset(LineRange range) { Base::operator=({range}); }
     41 
     42     void update(ConstArrayView<LineModification> modifs);
     43     void add_range(LineRange range, FunctionRef<void (LineRange)> on_new_range);
     44     void remove_range(LineRange range);
     45 };
     46 
     47 
     48 }
     49 
     50 #endif // line_change_watcher_hh_INCLUDED