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

     1  package internalcmds
     2  
     3  import (
     4  	"os"
     5  	"path"
     6  
     7  	"github.com/jmigpin/editor/core"
     8  )
     9  
    10  func NewRow(args *core.InternalCmdArgs) error {
    11  	ed := args.Ed
    12  
    13  	p, err := os.Getwd()
    14  	if err != nil {
    15  		return err
    16  	}
    17  
    18  	rowPos := ed.GoodRowPos()
    19  
    20  	aerow, ok := ed.ActiveERow()
    21  	if ok {
    22  		// stick with directory if exists, otherwise get base dir
    23  		p2 := aerow.Info.Name()
    24  		if aerow.Info.IsDir() {
    25  			p = p2
    26  		} else {
    27  			p = path.Dir(p2)
    28  		}
    29  
    30  		// position after active row
    31  		rowPos = aerow.Row.PosBelow()
    32  	}
    33  
    34  	info := ed.ReadERowInfo(p)
    35  
    36  	erow, err := core.NewLoadedERow(info, rowPos)
    37  	if err != nil {
    38  		return err
    39  	}
    40  	erow.Flash()
    41  
    42  	return nil
    43  }