SetBuffer sets the [Buffer] that this is an editor of, and interconnects their events.
(buf *Buffer)
| 324 | |
| 325 | // SetBuffer sets the [Buffer] that this is an editor of, and interconnects their events. |
| 326 | func (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 |
| 354 | func (ed *Editor) linesInserted(tbe *text.Edit) { |