completeText edits the text using the string chosen from the completion menu
(s string)
| 994 | |
| 995 | // completeText edits the text using the string chosen from the completion menu |
| 996 | func (tb *Buffer) completeText(s string) { |
| 997 | if s == "" { |
| 998 | return |
| 999 | } |
| 1000 | // give the completer a chance to edit the completion before insert, |
| 1001 | // also it return a number of runes past the cursor to delete |
| 1002 | st := lexer.Pos{tb.Complete.SrcLn, 0} |
| 1003 | en := lexer.Pos{tb.Complete.SrcLn, tb.LineLen(tb.Complete.SrcLn)} |
| 1004 | var tbes string |
| 1005 | tbe := tb.Region(st, en) |
| 1006 | if tbe != nil { |
| 1007 | tbes = string(tbe.ToBytes()) |
| 1008 | } |
| 1009 | c := tb.Complete.GetCompletion(s) |
| 1010 | pos := lexer.Pos{tb.Complete.SrcLn, tb.Complete.SrcCh} |
| 1011 | ed := tb.Complete.EditFunc(tb.Complete.Context, tbes, tb.Complete.SrcCh, c, tb.Complete.Seed) |
| 1012 | if ed.ForwardDelete > 0 { |
| 1013 | delEn := lexer.Pos{tb.Complete.SrcLn, tb.Complete.SrcCh + ed.ForwardDelete} |
| 1014 | tb.DeleteText(pos, delEn, EditNoSignal) |
| 1015 | } |
| 1016 | // now the normal completion insertion |
| 1017 | st = pos |
| 1018 | st.Ch -= len(tb.Complete.Seed) |
| 1019 | tb.ReplaceText(st, pos, st, ed.NewText, EditSignal, ReplaceNoMatchCase) |
| 1020 | if tb.currentEditor != nil { |
| 1021 | ep := st |
| 1022 | ep.Ch += len(ed.NewText) + ed.CursorAdjust |
| 1023 | tb.currentEditor.SetCursorShow(ep) |
| 1024 | tb.currentEditor = nil |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | // isSpellEnabled returns true if spelling correction is enabled, |
| 1029 | // taking into account given position in text if it is relevant for cases |
no test coverage detected