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