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

Method SetBuffer

texteditor/editor.go:326–351  ·  view source on GitHub ↗

SetBuffer sets the [Buffer] that this is an editor of, and interconnects their events.

(buf *Buffer)

Source from the content-addressed store, hash-verified

324
325// SetBuffer sets the [Buffer] that this is an editor of, and interconnects their events.
326func (ed *Editor) SetBuffer(buf *Buffer) *Editor {
327 if ed == nil || buf != nil && ed.Buffer == buf {
328 return ed
329 }
330 // had := false
331 if ed.Buffer != nil {
332 // had = true
333 ed.Buffer.deleteEditor(ed)
334 }
335 ed.Buffer = buf
336 ed.resetState()
337 if buf != nil {
338 buf.addEditor(ed)
339 bhl := len(buf.posHistory)
340 if bhl > 0 {
341 cp := buf.posHistory[bhl-1]
342 ed.posHistoryIndex = bhl - 1
343 ed.SetCursorShow(cp)
344 } else {
345 ed.SetCursorShow(lexer.Pos{})
346 }
347 }
348 ed.layoutAllLines()
349 ed.NeedsLayout()
350 return ed
351}
352
353// linesInserted inserts new lines of text and reformats them
354func (ed *Editor) linesInserted(tbe *text.Edit) {

Callers 5

InitMethod · 0.95
bufferSignalMethod · 0.95
InitMethod · 0.45
InitMethod · 0.45
TestEditorMultiFunction · 0.45

Calls 6

resetStateMethod · 0.95
SetCursorShowMethod · 0.95
layoutAllLinesMethod · 0.95
NeedsLayoutMethod · 0.95
deleteEditorMethod · 0.80
addEditorMethod · 0.80

Tested by 1

TestEditorMultiFunction · 0.36