github.com/jmigpin/editor@v1.6.0/util/drawutil/drawer4/indexof.go (about)

     1  package drawer4
     2  
     3  type IndexOf struct {
     4  	d *Drawer
     5  }
     6  
     7  func (io *IndexOf) Init() {
     8  	io.d.st.indexOf.index = -1
     9  }
    10  
    11  func (io *IndexOf) Iter() {
    12  	if io.d.iters.runeR.isNormal() {
    13  		io.iter2()
    14  	}
    15  	if !io.d.iterNext() {
    16  		return
    17  	}
    18  }
    19  
    20  func (io *IndexOf) iter2() {
    21  	p := &io.d.st.indexOf.p
    22  	pb := io.d.iters.runeR.penBounds()
    23  	// before the start
    24  	if p.Y < pb.Min.Y {
    25  		io.d.iterStop()
    26  		return
    27  	}
    28  	// in the line
    29  	if p.Y < pb.Max.Y {
    30  		// keep closest in the line
    31  		io.d.st.indexOf.index = io.d.st.runeR.ri
    32  		// before the first rune of the line or in the rune
    33  		if p.X < pb.Max.X {
    34  			io.d.iterStop()
    35  			return
    36  		}
    37  	}
    38  }
    39  
    40  func (io *IndexOf) End() {
    41  	if io.d.st.indexOf.index < 0 {
    42  		io.d.st.indexOf.index = io.d.st.runeR.ri // possibly zero
    43  	}
    44  }