( text: string, direction: 'prepend' | 'append' = 'append', )
| 24 | let lastActionWasYank = false |
| 25 | |
| 26 | export function pushToKillRing( |
| 27 | text: string, |
| 28 | direction: 'prepend' | 'append' = 'append', |
| 29 | ): void { |
| 30 | if (text.length > 0) { |
| 31 | if (lastActionWasKill && killRing.length > 0) { |
| 32 | // Accumulate with the most recent kill |
| 33 | if (direction === 'prepend') { |
| 34 | killRing[0] = text + killRing[0] |
| 35 | } else { |
| 36 | killRing[0] = killRing[0] + text |
| 37 | } |
| 38 | } else { |
| 39 | // Add new entry to front of ring |
| 40 | killRing.unshift(text) |
| 41 | if (killRing.length > KILL_RING_MAX_SIZE) { |
| 42 | killRing.pop() |
| 43 | } |
| 44 | } |
| 45 | lastActionWasKill = true |
| 46 | // Reset yank state when killing new text |
| 47 | lastActionWasYank = false |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | export function getLastKill(): string { |
| 52 | return killRing[0] ?? '' |
no test coverage detected