MCPcopy Create free account
hub / github.com/cogentcore/core / setCompleter

Method setCompleter

texteditor/buffer.go:959–986  ·  view source on GitHub ↗

Complete and Spell setCompleter sets completion functions so that completions will automatically be offered as the user types

(data any, matchFun complete.MatchFunc, editFun complete.EditFunc,
	lookupFun complete.LookupFunc)

Source from the content-addressed store, hash-verified

957// setCompleter sets completion functions so that completions will
958// automatically be offered as the user types
959func (tb *Buffer) setCompleter(data any, matchFun complete.MatchFunc, editFun complete.EditFunc,
960 lookupFun complete.LookupFunc) {
961 if tb.Complete != nil {
962 if tb.Complete.Context == data {
963 tb.Complete.MatchFunc = matchFun
964 tb.Complete.EditFunc = editFun
965 tb.Complete.LookupFunc = lookupFun
966 return
967 }
968 tb.deleteCompleter()
969 }
970 tb.Complete = core.NewComplete().SetContext(data).SetMatchFunc(matchFun).
971 SetEditFunc(editFun).SetLookupFunc(lookupFun)
972 tb.Complete.OnSelect(func(e events.Event) {
973 tb.completeText(tb.Complete.Completion)
974 })
975 // todo: what about CompleteExtend event type?
976 // TODO(kai/complete): clean this up and figure out what to do about Extend and only connecting once
977 // note: only need to connect once..
978 // tb.Complete.CompleteSig.ConnectOnly(func(dlg *core.Dialog) {
979 // tbf, _ := recv.Embed(TypeBuf).(*Buf)
980 // if sig == int64(core.CompleteSelect) {
981 // tbf.CompleteText(data.(string)) // always use data
982 // } else if sig == int64(core.CompleteExtend) {
983 // tbf.CompleteExtend(data.(string)) // always use data
984 // }
985 // })
986}
987
988func (tb *Buffer) deleteCompleter() {
989 if tb.Complete == nil {

Callers 1

ConfigKnownMethod · 0.95

Calls 8

deleteCompleterMethod · 0.95
completeTextMethod · 0.95
NewCompleteFunction · 0.92
SetLookupFuncMethod · 0.80
SetEditFuncMethod · 0.80
SetMatchFuncMethod · 0.80
SetContextMethod · 0.45
OnSelectMethod · 0.45

Tested by

no test coverage detected