github.com/jmigpin/editor@v1.6.0/util/iout/iorw/rwedit/copypaste.go (about) 1 package rwedit 2 3 import ( 4 "fmt" 5 6 "github.com/jmigpin/editor/util/uiutil/event" 7 ) 8 9 func Copy(ctx *Ctx) error { 10 if b, ok := ctx.Selection(); ok { 11 ctx.Fns.SetClipboardData(event.CIClipboard, string(b)) 12 } 13 return nil 14 } 15 16 func Paste(ctx *Ctx, ci event.ClipboardIndex) { 17 ctx.Fns.GetClipboardData(ci, func(s string, err error) { 18 if err != nil { 19 ctx.Fns.Error(fmt.Errorf("rwedit.paste: %w", err)) 20 return 21 } 22 if err := InsertString(ctx, s); err != nil { 23 ctx.Fns.Error(fmt.Errorf("rwedit.paste: insertstring: %w", err)) 24 } 25 }) 26 }