func (r *RegionSet) Regions() (ret []Region) {
	r.lock.Lock()
	defer r.lock.Unlock()
	ret = make([]Region, len(r.regions))
	copy(ret, r.regions)
	return
}
Regions returns a copy of the regions in the set
package text
import (
	"sync"
)
type RegionSet struct {
	regions           []Region
	onChangeCallbacks map[string]func()
	lock              sync.Mutex
}
func (r *RegionSet) Adjust(position, delta int) {
	r.lock.Lock()
	defer r.lock.Unlock()
	for i := range r.regions {
		r.regions[i].Adjust(position, delta)
	}
	r.flush()
}
func (r *RegionSet) overlaps(reference Region, start, end int) (ret []int) {
	for i := start; i < end; i++ {
		if reference == r.regions[i] || reference.Intersects(r.regions[i]) || reference.Covers(r.regions[i]) {
			ret = append(ret, i)
		}
	}
	return
}
func (r *RegionSet) merge(reference int, merge []int) {
	for _, j := range merge {
		r.regions[reference] = r.regions[reference].Cover(r.regions[j])
	}
	l := len(merge) - 1
	adj := 0
	for i, j1 := range merge {
		j2 := len(r.regions) - adj
		if i < l {
			j2 = merge[i+1] - 1
		}
		if j2 > 0 && j1+1 <= j2 {
			copy(r.regions[j1-adj:], r.regions[j1+1:j2])
		}
		adj++
	}
	r.regions = r.regions[:len(r.regions)-len(merge)]
}
func (r *RegionSet) flush() {
	for i := 1; i < len(r.regions); i++ {
		ov := r.overlaps(r.regions[i], 0, i)
		if len(ov) == 0 {
			continue
		}
		r.merge(ov[0], append(ov[1:], i))
	}
	r.lock.Unlock()
	defer r.lock.Lock()
	r.onChange()
}
func (r *RegionSet) Subtract(r2 Region) {
	r3 := r.Cut(r2)
	r.lock.Lock()
	r.regions = r3.regions
	r.lock.Unlock()
	r.onChange()
}
func (r *RegionSet) Add(r2 Region) {
	func() {
		r.lock.Lock()
		defer r.lock.Unlock()
		ov := r.overlaps(r2, 0, len(r.regions))
		r.regions = append(r.regions, r2)
		if len(ov) == 0 {
			return
		}
		ref := ov[0]
		ov = append(ov[1:], len(r.regions)-1)
		r.merge(ref, ov)
	}()
	r.onChange()
}
func (r *RegionSet) Clear() {
	r.lock.Lock()
	defer r.lock.Unlock()
	r.regions = r.regions[0:0]
	r.flush()
}
func (r *RegionSet) Get(i int) Region {
	r.lock.Lock()
	defer r.lock.Unlock()
	return r.regions[i]
}
func (r *RegionSet) Len() int {
	return len(r.regions)
}
func (r *RegionSet) AddAll(rs []Region) {
	r.lock.Lock()
	rr := RegionSet{regions: rs}
	rr.lock.Lock()
	rr.flush()
	rr.lock.Unlock()
	rs = rr.Regions()
	start := len(r.regions)
	r.regions = append(r.regions, rs...)
	for _, r2 := range rs {
		ov := r.overlaps(r2, 0, start)
		if len(ov) == 0 {
			continue
		}
		ref := ov[0]
		ov = append(ov[1:], len(r.regions)-1)
		r.merge(ref, ov)
		start -= len(ov)
	}
	r.lock.Unlock()
	r.onChange()
}
func (r *RegionSet) Contains(r2 Region) bool {
	r.lock.Lock()
	defer r.lock.Unlock()
	for i := range r.regions {
		if r.regions[i] == r2 || (r.regions[i].Contains(r2.Begin()) && r.regions[i].Contains(r2.End())) {
			return true
		}
	}
	return false
}