code: func (edit *TextEditor) Edit(win *Window) EditEvents {
  	edit.init(win)
  	if edit.Maxlen > 0 {
  		if len(edit.Buffer) > edit.Maxlen {
  			edit.Buffer = edit.Buffer[:edit.Maxlen]
  		}
  	}
  
  	if edit.Flags&EditNoCursor != 0 {
  		edit.Cursor = len(edit.Buffer)
  	}
  	if edit.Flags&EditSelectable == 0 {
  		edit.SelectStart = edit.Cursor
  		edit.SelectEnd = edit.Cursor
  	}
  
  	var bounds rect.Rect
  
  	style := &edit.win.ctx.Style
  	widget_state, bounds, _ := edit.win.widget()
  	if !widget_state {
  		return 0
  	}
  	in := edit.win.inputMaybe(widget_state)
  
  	var cut, copy, paste bool
  
  	if w := win.ContextualOpen(0, image.Point{}, bounds, nil); w != nil {
  		w.Row(20).Dynamic(1)
  		visible := false
  		if edit.Flags&EditClipboard != 0 {
  			visible = true
  			if w.MenuItem(label.TA("Cut", "LC")) {
  				cut = true
  			}
  			if w.MenuItem(label.TA("Copy", "LC")) {
  				copy = true
  			}
  			if w.MenuItem(label.TA("Paste", "LC")) {
  				paste = true
  			}
  		}
  		if edit.Flags&EditMultiline != 0 {
  			visible = true
  			if w.MenuItem(label.TA("Find...", "LC")) {
  				edit.popupFind()
  			}
  		}
  		if !visible {
  			w.Close()
  		}
  	}
  
  	ev := edit.doEdit(bounds, &style.Edit, in, cut, copy, paste)
  	return ev
  }
docs: // Adds text editor edit to win.
  // Initial contents of the text editor will be set to text. If
  // alwaysSet is specified the contents of the editor will be reset
  // to text.