Edge-Drop is a clipboard shelf on the edge of your screen. Hover to open it. Drag files and images into any app, click to copy text and links. Free and open-source for Windows.
TypeScript clipboardclipboard-managerdesktop-appdrag-and-dropelectronopen-sourceproductivityproductivity-toolwindows
fix(clipboard): correct copy-indicator semantics and eliminate long-text self-duplication
Deepender25ff535371146d
diff --git a/electron/main/ipc.ts b/electron/main/ipc.tsindex 4e4a793..8227417 100644--- a/electron/main/ipc.ts+++ b/electron/main/ipc.ts@@ -306,9 +306,12 @@ export function registerIpc(): void {}console.log('[IPC] item:copy wrote to clipboard, kind=', item.data.kind)- // Promote the copied item to the top of the history stack- getStore().add(itemDataWithFullText, loadSettings().historyLimit)- pushState.items()+ // Promote: touch() bumps recency WITHOUT re-interpreting content.+ // Re-adding here duplicated long texts — their stored 300-char preview+ // signature differs from the full payload, so add() saw "new content"+ // and created a second entry.+ getStore().touch(id)+ pushState.items({ reason: 'usage' })// Unpause after a short delay to allow OS clipboard event to settle.// Respect the current incognito state when unpausing.@@ -343,11 +346,11 @@ export function registerIpc(): void {if (!wrote) return false- // Promote the parent item to the top of the history stack- const parentItem = getStore().get(req.id)- if (parentItem) {- getStore().add(parentItem.data, loadSettings().historyLimit)- pushState.items()+ // Promote the parent bundle to the top — touch() keeps content/signature+ // intact (re-add risked duplicate long-text entries, same as item:copy).+ if (getStore().get(req.id)) {+ getStore().touch(req.id)+ pushState.items({ reason: 'usage' })}const watcher = getWatcher()@@ -554,7 +557,9 @@ export function registerIpc(): void {}getStore().add(data, loadSettings().historyLimit)- pushState.items()+ // Manual drag-in import (text/URL/web image dropped onto the shelf):+ // bookkeeping, not a capture — suppress the copy indicator.+ pushState.items({ reason: 'usage' })return getStore().toDto()})@@ -744,7 +749,9 @@ export function registerSendListeners(): void {if (loadSettings().movePastedToTop !== false && getStore().get(req.id)) {getStore().touch(req.id)}- pushState.items()+ // 'usage' reason: this push is bookkeeping from a manual drag-out, so+ // the renderer must NOT flash the capture copy-indicator for it.+ pushState.items({ reason: 'usage' })}})diff --git a/electron/main/state.ts b/electron/main/state.tsindex e67ea58..710de17 100644--- a/electron/main/state.ts+++ b/electron/main/state.ts@@ -140,9 +140,14 @@ function send(channel: string, ...args: unknown[]): void {}export const pushState = {- items(): void {+ /**+ * Push the item list. `reason` labels WHY so the renderer can react+ * appropriately: 'usage' pushes (drag-out/copy recency bumps) must never+ * trigger the capture copy-indicator flare.+ */+ items(meta?: { reason?: 'usage' | 'capture' }): void {const dto: ClipboardItemDto[] = store.toDto()- send('state:items', dto)+ send('state:items', dto, meta)},settings(next: Settings): void {send('state:settings', next)@@ -196,6 +201,6 @@ export function addFiles(paths: string[]): AddFilesResult {stacksCreated++}- if (stacksCreated > 0) pushState.items()+ if (stacksCreated > 0) pushState.items({ reason: 'usage' }) // manual drag-in import: never a capturereturn { stacksCreated }}diff --git a/shared/bridge.ts b/shared/bridge.tsindex a62a102..ca84ed8 100644--- a/shared/bridge.ts+++ b/shared/bridge.ts@@ -59,7 +59,7 @@ export interface EdgeApi {broadcastTutorialStep: (step: number) => void/* Main -> Renderer */- onItems: (cb: (items: import('./types').ClipboardItemDto[]) => void) => () => void+ onItems: (cb: (items: import('./types').ClipboardItemDto[], meta?: { reason?: 'usage' | 'capture' }) => void) => () => voidonSettings: (cb: (settings: Settings) => void) => () => voidonToggle: (cb: (open?: boolean) => void) => () => voidonOpenSettings: (cb: () => void) => () => voiddiff --git a/shared/ipc.ts b/shared/ipc.tsindex 8912573..5e44724 100644--- a/shared/ipc.ts+++ b/shared/ipc.ts@@ -119,8 +119,11 @@ export interface InvokeMap {/* ------------------------------------------------------------------ */export interface EventMap {- /** Full new item list whenever the history changes. */- 'state:items': [items: ClipboardItemDto[]]+ /** Full new item list whenever the history changes. `reason` tells the+ * renderer WHY: 'usage' pushes come from manual drag gestures (drag-out+ * recency bumps and drag-in imports) and must never trigger the capture+ * copy-indicator. */+ 'state:items': [items: ClipboardItemDto[], meta?: { reason?: 'usage' | 'capture' }]/** Settings changed (e.g. from the tray menu). */'state:settings': [settings: Settings]/** Toggle the panel open/closed from the main process (e.g. tray). */diff --git a/src/App.tsx b/src/App.tsxindex 06d18ca..7849d29 100644--- a/src/App.tsx+++ b/src/App.tsx@@ -28,7 +28,7 @@ export default function App() {// Hydrate once + subscribe to pushed updates.useEffect(() => {void hydrate()- const offItems = edge.onItems((items) => setItems(items))+ const offItems = edge.onItems((items, meta) => setItems(items, meta))const offSettings = edge.onSettings((next) => setSettings(next))const offToast = edge.onToast((t) => pushToast(t))const offToggle = edge.onToggle((forceOpen) => {diff --git a/src/components/ClipboardItem.tsx b/src/components/ClipboardItem.tsxindex 28bc674..7c46315 100644--- a/src/components/ClipboardItem.tsx+++ b/src/components/ClipboardItem.tsx@@ -743,7 +743,7 @@ function BundleFluidPreview({<buttonclassName="act subitem-copy-btn"title={t('item.copyFilePath')}- onClick={(e) => { e.stopPropagation(); e.currentTarget.blur(); window.edge.copySubitem({ id: item.id, paths: [filePath] }); }}+ onClick={(e) => { e.stopPropagation(); e.currentTarget.blur(); useStore.getState().copySubitem({ id: item.id, paths: [filePath] }); }}><CopyIcon width={12} height={12} /></button>diff --git a/src/components/PreviewFlyout.tsx b/src/components/PreviewFlyout.tsxindex 2666cd0..7434435 100644--- a/src/components/PreviewFlyout.tsx+++ b/src/components/PreviewFlyout.tsx@@ -163,12 +163,12 @@ export function PreviewFlyout({ isRight }: { isRight: boolean }) {playButtonClickSound()const keys = Array.from(selectedKeys)if (item.data.kind === 'files') {- window.edge.copySubitem({ id: item.id, paths: keys })+ useStore.getState().copySubitem({ id: item.id, paths: keys })} else if (item.data.kind === 'image-collection') {if (keys.length === 1) {- window.edge.copySubitem({ id: item.id, imageId: keys[0] })+ useStore.getState().copySubitem({ id: item.id, imageId: keys[0] })} else {- window.edge.copyItem(item.id)+ useStore.getState().copy(item.id)}}}@@ -771,7 +771,7 @@ function PreviewContent({<QuickActionButtontitle={t('flyout.copyText')}icon={CopyIcon}- onClick={() => window.edge.copyItem(item.id)}+ onClick={() => useStore.getState().copy(item.id)}/></div><div style={{@@ -812,7 +812,7 @@ function PreviewContent({<QuickActionButtontitle={t('flyout.copyImage')}icon={CopyIcon}- onClick={() => window.edge.copyItem(item.id)}+ onClick={() => useStore.getState().copy(item.id)}solidDark={true}/></div>@@ -879,7 +879,7 @@ function PreviewContent({<QuickActionButtontitle={t('flyout.copyImage')}icon={CopyIcon}- onClick={() => window.edge.copySubitem({ id: item.id, imageId: img.imageId })}+ onClick={() => useStore.getState().copySubitem({ id: item.id, imageId: img.imageId })}solidDark={true}/></div>@@ -922,7 +922,7 @@ function PreviewContent({<QuickActionButtontitle={t('flyout.copyFile')}icon={CopyIcon}- onClick={() => window.edge.copyItem(item.id)}+ onClick={() => useStore.getState().copy(item.id)}solidDark={true}size={28}/>@@ -991,7 +991,7 @@ function PreviewContent({<QuickActionButtontitle={t('flyout.copyFile')}icon={CopyIcon}- onClick={() => window.edge.copyItem(item.id)}+ onClick={() => useStore.getState().copy(item.id)}size={28}/><ExplorerButton@@ -1103,7 +1103,7 @@ function PreviewContent({<QuickActionButtontitle={t('flyout.copyFile')}icon={CopyIcon}- onClick={() => window.edge.copySubitem({ id: item.id, paths: [p] })}+ onClick={() => useStore.getState().copySubitem({ id: item.id, paths: [p] })}solidDark={true}/><ExplorerButton@@ -1203,7 +1203,7 @@ function PreviewContent({<QuickActionButtontitle={t('flyout.copyFile')}icon={CopyIcon}- onClick={() => window.edge.copySubitem({ id: item.id, paths: [p] })}+ onClick={() => useStore.getState().copySubitem({ id: item.id, paths: [p] })}size={24}/><ExplorerButtondiff --git a/src/store/appStore.ts b/src/store/appStore.tsindex cd139e3..6050f07 100644--- a/src/store/appStore.ts+++ b/src/store/appStore.ts@@ -79,7 +79,7 @@ interface AppState {setUpdateDownloaded: (info: { version: string }) => voiddismissUpdate: () => voidinstallUpdate: () => Promise<void>- setItems: (items: ClipboardItemDto[]) => void+ setItems: (items: ClipboardItemDto[], meta?: { reason?: 'usage' | 'capture' }) => voidsetSettings: (next: Settings) => void/* UI */@@ -107,6 +107,7 @@ interface AppState {remove: (id: string) => Promise<void>clear: (ids?: string[]) => Promise<void>copy: (id: string) => Promise<void>+ copySubitem: (req: DragRequest) => Promise<void>paste: (id: string) => Promise<void>pasteSubitem: (req: DragRequest) => Promise<void>patchSettings: (patch: Partial<Settings>) => Promise<void>@@ -252,7 +253,7 @@ export const useStore = create<AppState>((set, get) => ({await edge.installUpdate()},- setItems: (items) => {+ setItems: (items, meta) => {const prevItems = get().itemsif (prevItems.length === items.length &&@@ -266,6 +267,10 @@ export const useStore = create<AppState>((set, get) => ({if (get().hydrated && newTop) {const isDifferentId = !prevTop || newTop.id !== prevTop.idconst isNewCapturedAt = prevTop && newTop.capturedAt !== prevTop.capturedAt+ // 'usage' meta = bookkeeping push from a manual drag-out (recency bump+ // after a successful external drop). The user is moving content, not+ // capturing it - the copy indicator must stay dark.+ const isUsageBookkeeping = meta?.reason === 'usage'// Suppress the flare while the mutation originated from this renderer// session itself:// - isInternalCopying: click copy/paste flows (main rewrites the OS@@ -276,7 +281,7 @@ export const useStore = create<AppState>((set, get) => ({// window — Panel.tsx only clears internalDragReq 150ms later. Without// this guard the usage bump would masquerade as a fresh capture and// flash the edge copy indicator on every drag-out.- if ((isDifferentId || isNewCapturedAt) && !get().isInternalCopying && !get().internalDragReq) {+ if ((isDifferentId || isNewCapturedAt) && !get().isInternalCopying && !get().internalDragReq && !isUsageBookkeeping) {get().triggerCopyFlare()}}@@ -418,9 +423,25 @@ export const useStore = create<AppState>((set, get) => ({},async copy(id) {+ // Copy IS a copy action: the indicator SHOULD fire. The flag only blocks+ // the heuristic double-fire from the promote push that follows.set({ isInternalCopying: true })- await edge.copyItem(id)- setTimeout(() => set({ isInternalCopying: false }), 400)+ try {+ const ok = await edge.copyItem(id)+ if (ok !== false) get().triggerCopyFlare()+ } finally {+ setTimeout(() => set({ isInternalCopying: false }), 400)+ }+ },++ async copySubitem(req) {+ set({ isInternalCopying: true })+ try {+ const ok = await edge.copySubitem(req)+ if (ok !== false) get().triggerCopyFlare()+ } finally {+ setTimeout(() => set({ isInternalCopying: false }), 400)+ }},async paste(id) {diff --git a/tests/itemCopyPromote.test.ts b/tests/itemCopyPromote.test.tsnew file mode 100644index 0000000..b3c4d35--- /dev/null+++ b/tests/itemCopyPromote.test.ts@@ -0,0 +1,115 @@+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import { mkdirSync, rmSync } from 'node:fs'+import { join } from 'node:path'+import { tmpdir } from 'node:os'++const fsRoots = vi.hoisted(() => ({+ home: '',+ userData: ''+}))++vi.mock('electron', () => ({+ app: {+ isPackaged: false,+ getAppPath: () => join(fsRoots.userData, 'app'),+ getPath: (name: string) => (name === 'userData' ? fsRoots.userData : join(fsRoots.userData, name))+ },+ nativeImage: { createFromPath: () => ({ isEmpty: () => true }) },+ safeStorage: { isEncryptionAvailable: () => false }+}))++vi.mock('node:os', async (importOriginal) => {+ const actual = await importOriginal<typeof import('node:os')>()+ return { ...actual, homedir: () => fsRoots.home }+})++import { ItemStore } from '../electron/store/ItemStore'++const LONG_TEXT = 'x'.repeat(500) // crosses the 300-char payload threshold++function makeStore(): ItemStore {+ return new ItemStore()+}++describe('copy-promotion correctness (self-duplication regression)', () => {+ beforeEach(() => {+ fsRoots.userData = join(tmpdir(), `ed-promote-${Date.now()}-${Math.random().toString(16).slice(2)}`)+ fsRoots.home = join(tmpdir(), `ed-promote-home-${Date.now()}-${Math.random().toString(16).slice(2)}`)+ mkdirSync(fsRoots.userData, { recursive: true })+ mkdirSync(join(fsRoots.userData, 'payloads'), { recursive: true })+ mkdirSync(join(fsRoots.userData, 'images'), { recursive: true })+ mkdirSync(fsRoots.home, { recursive: true })+ })++ afterEach(() => {+ try { rmSync(fsRoots.userData, { recursive: true, force: true }) } catch { /* ignore */ }+ try { rmSync(fsRoots.home, { recursive: true, force: true }) } catch { /* ignore */ }+ })++ it('LONG TEXT HAZARD: re-adding the full payload creates a DUPLICATE (why touch() is mandatory)', () => {+ // Documents the exact defect: item:copy used to promote via add(fullText).+ // The trap springs AFTER an index rebuild (restart/merge/split): stored+ // items carry 300-char preview signatures, so the full payload re-add+ // misses and creates a SECOND entry.+ const store = makeStore()+ store.add({ kind: 'text', text: LONG_TEXT, isUrl: false }, 10)+ const id = store.list()[0].id+ store.persistSync() // flush the debounced write before "restarting"++ // Force the rebuild path a restart takes: fresh instance -> load.+ const reopened = makeStore()+ reopened.load()+ expect(reopened.list()).toHaveLength(1)+ expect(reopened.list()[0].data.text.length).toBe(300) // preview stored++ const fullPayload = reopened.getFullText(id)+ expect(fullPayload).toBe(LONG_TEXT)++ reopened.add({ kind: 'text', text: fullPayload, isUrl: false }, 10)++ // This assertion PINS the hazard: if anyone reintroduces add()-promotion,+ // this expectation fails and explains why.+ expect(reopened.list()).toHaveLength(2)+ })++ it('SAFE PATH: touch() promotes without changing count, content, or signature', () => {+ const store = makeStore()+ store.add({ kind: 'text', text: LONG_TEXT, isUrl: false }, 10)+ const id = store.list()[0].id+ const before = store.list()[0]+ // Backdate so the recency bump is observable even within the same ms.+ ;(store.list()[0] as { capturedAt: number }).capturedAt -= 5+ const oldCapturedAt = store.list()[0].capturedAt++ const ok = store.touch(id)++ expect(ok).toBe(true)+ expect(store.list()).toHaveLength(1) // never duplicated+ const promoted = store.list()[0]+ expect(promoted.id).toBe(id)+ expect(promoted.hitCount).toBe(before.hitCount + 1)+ expect(promoted.capturedAt).toBeGreaterThan(oldCapturedAt)+ // Content identity fully intact (preview pointer + payload untouched).+ expect(promoted.data.kind === 'text' && promoted.data.hasFullPayload).toBe(true)+ expect(store.getFullText(id)).toBe(LONG_TEXT)+ })++ it('touch() moves unpinned items to the front of Recent', () => {+ const store = makeStore()+ store.add({ kind: 'text', text: 'first', isUrl: false }, 10)+ store.add({ kind: 'text', text: 'second', isUrl: false }, 10)+ const firstId = store.list()[store.list().length - 1].id++ store.touch(firstId)++ expect(store.list()[0].id).toBe(firstId)+ })++ it('short texts remain dedup-safe through add() (unchanged behavior)', () => {+ const store = makeStore()+ store.add({ kind: 'text', text: 'short', isUrl: false }, 10)+ store.add({ kind: 'text', text: 'short', isUrl: false }, 10)+ expect(store.list()).toHaveLength(1)+ expect(store.list()[0].hitCount).toBe(2)+ })+})