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)
| 957 | // setCompleter sets completion functions so that completions will |
| 958 | // automatically be offered as the user types |
| 959 | func (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 | |
| 988 | func (tb *Buffer) deleteCompleter() { |
| 989 | if tb.Complete == nil { |
no test coverage detected