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

Method ToBytes

texteditor/text/edit.go:38–61  ·  view source on GitHub ↗

ToBytes returns the Text of this edit record to a byte string, with newlines at end of each line -- nil if Text is empty

()

Source from the content-addressed store, hash-verified

36// ToBytes returns the Text of this edit record to a byte string, with
37// newlines at end of each line -- nil if Text is empty
38func (te *Edit) ToBytes() []byte {
39 if te == nil {
40 return nil
41 }
42 sz := len(te.Text)
43 if sz == 0 {
44 return nil
45 }
46 if sz == 1 {
47 return []byte(string(te.Text[0]))
48 }
49 tsz := 0
50 for i := range te.Text {
51 tsz += len(te.Text[i]) + 10 // don't bother converting to runes, just extra slack
52 }
53 b := make([]byte, 0, tsz)
54 for i := range te.Text {
55 b = append(b, []byte(string(te.Text[i]))...)
56 if i < sz-1 {
57 b = append(b, '\n')
58 }
59 }
60 return b
61}
62
63// AdjustPosDel determines what to do with positions within deleted region
64type AdjustPosDel int

Callers 15

QReplacePromptMethod · 0.80
offerCompleteMethod · 0.80
LookupMethod · 0.80
spellCheckMethod · 0.80
offerCorrectMethod · 0.80
applyDiffMethod · 0.80
completeTextMethod · 0.80
CutMethod · 0.80
CopyMethod · 0.80
CutRectMethod · 0.80
CopyRectMethod · 0.80
ReCaseSelectionMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected