github.com/jmigpin/editor@v1.6.0/core/internalcmds/gotoline.go (about)

     1  package internalcmds
     2  
     3  import (
     4  	"fmt"
     5  	"strconv"
     6  
     7  	"github.com/jmigpin/editor/core"
     8  	"github.com/jmigpin/editor/util/parseutil"
     9  )
    10  
    11  func GotoLine(args0 *core.InternalCmdArgs) error {
    12  	erow := args0.ERow
    13  	part := args0.Part
    14  
    15  	args := part.Args[1:]
    16  	if len(args) != 1 {
    17  		return fmt.Errorf("expecting 1 argument")
    18  	}
    19  
    20  	line0, err := strconv.ParseUint(args[0].String(), 10, 64)
    21  	if err != nil {
    22  		return err
    23  	}
    24  	line := int(line0)
    25  
    26  	ta := erow.Row.TextArea
    27  	index, err := parseutil.LineColumnIndex(ta.RW(), line, 0)
    28  	if err != nil {
    29  		return err
    30  	}
    31  
    32  	// goto index
    33  	ta.Cursor().SetIndexSelectionOff(index)
    34  
    35  	erow.MakeIndexVisibleAndFlash(index)
    36  
    37  	return nil
    38  }