(tbe *Edit)
| 1021 | } |
| 1022 | |
| 1023 | func (ls *Lines) insertTextRectImpl(tbe *Edit) *Edit { |
| 1024 | st := tbe.Reg.Start |
| 1025 | ed := tbe.Reg.End |
| 1026 | nlns := (ed.Ln - st.Ln) + 1 |
| 1027 | if nlns <= 0 { |
| 1028 | return nil |
| 1029 | } |
| 1030 | ls.changed = true |
| 1031 | // make sure there are enough lines -- add as needed |
| 1032 | cln := ls.numLines() |
| 1033 | if cln <= ed.Ln { |
| 1034 | nln := (1 + ed.Ln) - cln |
| 1035 | tmp := make([][]rune, nln) |
| 1036 | ls.lines = append(ls.lines, tmp...) |
| 1037 | ie := &Edit{} |
| 1038 | ie.Reg.Start.Ln = cln - 1 |
| 1039 | ie.Reg.End.Ln = ed.Ln |
| 1040 | ls.linesInserted(ie) |
| 1041 | } |
| 1042 | nch := (ed.Ch - st.Ch) |
| 1043 | for i := 0; i < nlns; i++ { |
| 1044 | ln := st.Ln + i |
| 1045 | lr := ls.lines[ln] |
| 1046 | ir := tbe.Text[i] |
| 1047 | if len(lr) < st.Ch { |
| 1048 | lr = append(lr, runes.Repeat([]rune(" "), st.Ch-len(lr))...) |
| 1049 | } |
| 1050 | nt := append(lr, ir...) // first append to end to extend capacity |
| 1051 | copy(nt[st.Ch+nch:], nt[st.Ch:]) // move stuff to end |
| 1052 | copy(nt[st.Ch:], ir) // copy into position |
| 1053 | ls.lines[ln] = nt |
| 1054 | } |
| 1055 | re := tbe.Clone() |
| 1056 | re.Delete = false |
| 1057 | re.Reg.TimeNow() |
| 1058 | ls.linesEdited(re) |
| 1059 | return re |
| 1060 | } |
| 1061 | |
| 1062 | // ReplaceText does DeleteText for given region, and then InsertText at given position |
| 1063 | // (typically same as delSt but not necessarily). |
no test coverage detected