package axinput import ( "fmt" "sync" ) type clipboardSnapshot struct { text string hasText bool } type clipboardState struct { mu sync.Mutex nextID uint64 entries map[string]clipboardEntry } type clipboardEntry struct { fallbackText string restore clipboardSnapshot } func (s *clipboardState) remember(fallbackText string, restore clipboardSnapshot) string { s.mu.Lock() defer s.mu.Unlock() if s.entries == nil { s.entries = make(map[string]clipboardEntry) } s.nextID++ token := fmt.Sprintf("ax-output-%d", s.nextID) s.entries[token] = clipboardEntry{fallbackText: fallbackText, restore: restore} return token } func (s *clipboardState) take(token string) (clipboardEntry, bool) { s.mu.Lock() defer s.mu.Unlock() if s.entries == nil { return clipboardEntry{}, false } entry, ok := s.entries[token] if ok { delete(s.entries, token) } return entry, ok } func shouldRestoreClipboard(current clipboardSnapshot, expectedText string) bool { return current.hasText && current.text == expectedText }