ExecuteTextEvent runs a text event
(t *TextEvent, buf *SharedBuffer)
| 114 | |
| 115 | // ExecuteTextEvent runs a text event |
| 116 | func ExecuteTextEvent(t *TextEvent, buf *SharedBuffer) { |
| 117 | if t.EventType == TextEventInsert { |
| 118 | for _, d := range t.Deltas { |
| 119 | buf.insert(d.Start, d.Text) |
| 120 | } |
| 121 | } else if t.EventType == TextEventRemove { |
| 122 | for i, d := range t.Deltas { |
| 123 | t.Deltas[i].Text = buf.remove(d.Start, d.End) |
| 124 | } |
| 125 | } else if t.EventType == TextEventReplace { |
| 126 | for i, d := range t.Deltas { |
| 127 | t.Deltas[i].Text = buf.remove(d.Start, d.End) |
| 128 | buf.insert(d.Start, d.Text) |
| 129 | t.Deltas[i].Start = d.Start |
| 130 | t.Deltas[i].End = Loc{d.Start.X + util.CharacterCount(d.Text), d.Start.Y} |
| 131 | } |
| 132 | for i, j := 0, len(t.Deltas)-1; i < j; i, j = i+1, j-1 { |
| 133 | t.Deltas[i], t.Deltas[j] = t.Deltas[j], t.Deltas[i] |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | // UndoTextEvent undoes a text event |
| 139 | func (eh *EventHandler) UndoTextEvent(t *TextEvent) { |
no test coverage detected