MCPcopy
hub / github.com/micro-editor/micro / ExecuteTextEvent

Function ExecuteTextEvent

internal/buffer/eventhandler.go:116–136  ·  view source on GitHub ↗

ExecuteTextEvent runs a text event

(t *TextEvent, buf *SharedBuffer)

Source from the content-addressed store, hash-verified

114
115// ExecuteTextEvent runs a text event
116func 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
139func (eh *EventHandler) UndoTextEvent(t *TextEvent) {

Callers 2

DoTextEventMethod · 0.85
ExecuteMethod · 0.85

Calls 3

CharacterCountFunction · 0.92
insertMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected