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

Method bufferSignal

texteditor/editor.go:394–436  ·  view source on GitHub ↗

bufferSignal receives a signal from the Buffer when the underlying text is changed.

(sig bufferSignals, tbe *text.Edit)

Source from the content-addressed store, hash-verified

392// bufferSignal receives a signal from the Buffer when the underlying text
393// is changed.
394func (ed *Editor) bufferSignal(sig bufferSignals, tbe *text.Edit) {
395 switch sig {
396 case bufferDone:
397 case bufferNew:
398 ed.resetState()
399 ed.SetCursorShow(ed.CursorPos)
400 ed.NeedsLayout()
401 case bufferMods:
402 ed.NeedsLayout()
403 case bufferInsert:
404 if ed == nil || ed.This == nil || !ed.IsVisible() {
405 return
406 }
407 ndup := ed.renders == nil
408 // fmt.Printf("ed %v got %v\n", ed.Nm, tbe.Reg.Start)
409 if tbe.Reg.Start.Ln != tbe.Reg.End.Ln {
410 // fmt.Printf("ed %v lines insert %v - %v\n", ed.Nm, tbe.Reg.Start, tbe.Reg.End)
411 ed.linesInserted(tbe) // triggers full layout
412 } else {
413 ed.layoutLine(tbe.Reg.Start.Ln) // triggers layout if line width exceeds
414 }
415 if ndup {
416 ed.Update()
417 }
418 case bufferDelete:
419 if ed == nil || ed.This == nil || !ed.IsVisible() {
420 return
421 }
422 ndup := ed.renders == nil
423 if tbe.Reg.Start.Ln != tbe.Reg.End.Ln {
424 ed.linesDeleted(tbe) // triggers full layout
425 } else {
426 ed.layoutLine(tbe.Reg.Start.Ln)
427 }
428 if ndup {
429 ed.Update()
430 }
431 case bufferMarkupUpdated:
432 ed.NeedsLayout() // comes from another goroutine
433 case bufferClosed:
434 ed.SetBuffer(nil)
435 }
436}
437
438///////////////////////////////////////////////////////////////////////////////
439// Undo / Redo

Callers 1

signalEditorsMethod · 0.80

Calls 9

resetStateMethod · 0.95
SetCursorShowMethod · 0.95
NeedsLayoutMethod · 0.95
linesInsertedMethod · 0.95
layoutLineMethod · 0.95
linesDeletedMethod · 0.95
SetBufferMethod · 0.95
IsVisibleMethod · 0.65
UpdateMethod · 0.65

Tested by

no test coverage detected