InsertAtCursor inserts given text at current cursor position
(txt []byte)
| 357 | |
| 358 | // InsertAtCursor inserts given text at current cursor position |
| 359 | func (ed *Editor) InsertAtCursor(txt []byte) { |
| 360 | if ed.HasSelection() { |
| 361 | tbe := ed.deleteSelection() |
| 362 | ed.CursorPos = tbe.AdjustPos(ed.CursorPos, text.AdjustPosDelStart) // move to start if in reg |
| 363 | } |
| 364 | tbe := ed.Buffer.insertText(ed.CursorPos, txt, EditSignal) |
| 365 | if tbe == nil { |
| 366 | return |
| 367 | } |
| 368 | pos := tbe.Reg.End |
| 369 | if len(txt) == 1 && txt[0] == '\n' { |
| 370 | pos.Ch = 0 // sometimes it doesn't go to the start.. |
| 371 | } |
| 372 | ed.SetCursorShow(pos) |
| 373 | ed.setCursorColumn(ed.CursorPos) |
| 374 | ed.NeedsRender() |
| 375 | } |
| 376 | |
| 377 | /////////////////////////////////////////////////////////// |
| 378 | // Rectangular regions |
no test coverage detected