insertChip splices a chip label in at the cursor, recording the new span at the right ORDER position so the following reconcile() walks the labels left-to-right correctly. reconcile re-derives every span's start/end from the updated value, so the offsets on the inserted literal are placeholders it o
(content string)
| 254 | // updated value, so the offsets on the inserted literal are placeholders it |
| 255 | // overwrites: only the insertion index matters here. |
| 256 | func (p *promptInput) insertChip(content string) { |
| 257 | lines := countLines(content) |
| 258 | id := p.nextID |
| 259 | p.nextID++ |
| 260 | p.store[id] = chipContent{content: content, lines: lines} |
| 261 | |
| 262 | label := chipLabel(lines) |
| 263 | labelLen := utf8.RuneCountInString(label) |
| 264 | // Snap out of any chip the cursor is parked inside before choosing the |
| 265 | // insertion point, so a paste can't splice a new label into the interior of |
| 266 | // an existing one: reconcile would then fail to re-find the broken label |
| 267 | // and silently drop a chip, sending the wrong (or no) paste to the LLM. |
| 268 | insertAt := p.snapCursorOutOfChip() |
| 269 | |
| 270 | insertIdx := 0 |
| 271 | for i, s := range p.spans { |
| 272 | if s.start < insertAt { |
| 273 | insertIdx = i + 1 |
| 274 | } else { |
| 275 | break |
| 276 | } |
| 277 | } |
| 278 | p.spans = slices.Insert(p.spans, insertIdx, |
| 279 | chipSpan{id: id, start: insertAt, end: insertAt + labelLen}) |
| 280 | |
| 281 | p.ta.InsertString(label) |
| 282 | p.reconcile() |
| 283 | } |
| 284 | |
| 285 | // deleteSpan removes the chip's label from the value and drops it from spans |
| 286 | // and store. Cursor lands at the vacated start; reconcile re-validates later |
no test coverage detected