Skip to content

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.

fix(clipboard): spreadsheet cell distribution, re-copy flare feedback, and 31-language folder localization

Deepender257cef85268efb
diff --git a/electron/clipboard/ClipboardWatcher.ts b/electron/clipboard/ClipboardWatcher.ts
index f4fb46e..6e18ae7 100644
--- a/electron/clipboard/ClipboardWatcher.ts
+++ b/electron/clipboard/ClipboardWatcher.ts
@@ -24,6 +24,7 @@ function getContentSignature(sig: string): string {
export class ClipboardWatcher {
private timer: NodeJS.Timeout | null = null
+ private settleTimer: NodeJS.Timeout | null = null
private lastSig = 'empty'
private paused = false
private readonly intervalMs: number
@@ -42,19 +43,27 @@ export class ClipboardWatcher {
this.timer = setInterval(() => {
if (this.paused) return
const sig = clipboardSignature()
- if (getContentSignature(sig) === getContentSignature(this.lastSig)) {
- this.lastSig = sig
+ // If the full signature (including sequence number) has not changed, do nothing.
+ if (sig === this.lastSig) {
return
}
- // We detected a change. Wait a short moment to ensure it's not a transient
- // injection by a dictation app or macro that quickly restores the clipboard.
- setTimeout(async () => {
+ // We detected a change (new content OR OS sequence number incremented from a re-copy of identical content).
+ // Update lastSig immediately so subsequent poll intervals don't spawn duplicate settling timers.
+ this.lastSig = sig
+
+ if (this.settleTimer) {
+ clearTimeout(this.settleTimer)
+ }
+
+ // Wait a short moment to ensure multi-format streams (e.g. text + html + bitmaps) have finished writing.
+ this.settleTimer = setTimeout(async () => {
+ this.settleTimer = null
if (this.paused) return
const stableSig = clipboardSignature()
- // Compare content signatures (ignoring sequence numbers that increment as OS writes multi-format clipboard streams)
- if (getContentSignature(stableSig) !== getContentSignature(sig)) {
+ // Ensure content is stable (not transient injection by an app that immediately reverted)
+ if (getContentSignature(stableSig) !== getContentSignature(sig) && stableSig !== sig) {
return
}
@@ -85,6 +94,10 @@ export class ClipboardWatcher {
/** Temporarily stop recording (incognito mode or self-copy) without tearing down the timer. */
setPaused(paused: boolean): void {
this.paused = paused
+ if (paused && this.settleTimer) {
+ clearTimeout(this.settleTimer)
+ this.settleTimer = null
+ }
// When resuming, refresh the signature so we ignore whatever was copied
// during the paused state (e.g. self-copies or incognito copies).
if (!paused) {
@@ -115,6 +128,10 @@ export class ClipboardWatcher {
* more important.
*/
resyncSignature(): void {
+ if (this.settleTimer) {
+ clearTimeout(this.settleTimer)
+ this.settleTimer = null
+ }
this.lastSig = clipboardSignature()
}
@@ -131,10 +148,18 @@ export class ClipboardWatcher {
* (clipboard never changed), so hitCount would never increment on re-copy.
*/
invalidateSignature(): void {
+ if (this.settleTimer) {
+ clearTimeout(this.settleTimer)
+ this.settleTimer = null
+ }
this.lastSig = '__post-paste__'
}
stop(): void {
+ if (this.settleTimer) {
+ clearTimeout(this.settleTimer)
+ this.settleTimer = null
+ }
if (this.timer) {
clearInterval(this.timer)
this.timer = null
diff --git a/electron/clipboard/formats.ts b/electron/clipboard/formats.ts
index b2100fe..c0a8c64 100644
--- a/electron/clipboard/formats.ts
+++ b/electron/clipboard/formats.ts
@@ -271,6 +271,55 @@ export function isScreenshotOrImageIntent(hasImage: boolean, rawText: string, ra
return true
}
+/**
+ * Format text and HTML data for clipboard write back.
+ *
+ * 1. Normalizes line breaks to Windows CRLF (\r\n). On Windows, Microsoft Excel and
+ * other spreadsheet applications use \r\n to separate table rows. If bare \n (LF)
+ * is used, Excel interprets the newline as an in-cell line feed (Alt+Enter) and
+ * pastes the entire multiline table into a SINGLE cell!
+ *
+ * 2. If the text contains tab characters (\t), it represents spreadsheet tabular cells.
+ * If no valid <table> HTML is provided (or if only non-table wrappers like
+ * <google-sheets-html-origin> <div> exist), we synthesize a standard HTML <table>
+ * so that spreadsheet apps (Excel, Google Sheets, Calc) and office apps (Word, Outlook)
+ * distribute rows and columns across the cell grid rather than dumping text into one cell.
+ */
+export function formatTabularDataForClipboard(text: string, rawHtml?: string): { text: string; html?: string } {
+ if (!text) return { text: '', html: rawHtml }
+
+ // Normalize all line breaks to CRLF (\r\n) for Windows
+ const crlfText = text.replace(/\r?\n/g, '\r\n')
+
+ // Check if content has tab characters indicating column separators
+ if (text.includes('\t')) {
+ // If rawHtml already contains a standard table tag, use it
+ if (rawHtml && /<table\b[^>]*>/i.test(rawHtml)) {
+ return { text: crlfText, html: rawHtml }
+ }
+
+ // Otherwise, generate a clean, standard HTML table from the TSV content
+ const rows = text.split(/\r?\n/)
+ const htmlRows = rows.map((row) => {
+ const cells = row.split('\t').map((cell) => {
+ const escaped = cell
+ .replace(/&/g, '&amp;')
+ .replace(/</g, '&lt;')
+ .replace(/>/g, '&gt;')
+ .replace(/"/g, '&quot;')
+ .replace(/'/g, '&#39;')
+ return `<td>${escaped}</td>`
+ }).join('')
+ return `<tr>${cells}</tr>`
+ }).join('')
+
+ const htmlTable = `<table border="0" cellpadding="0" cellspacing="0"><tbody>${htmlRows}</tbody></table>`
+ return { text: crlfText, html: htmlTable }
+ }
+
+ return { text: crlfText, html: rawHtml }
+}
+
/**
* Async snapshot of the current clipboard into a single ItemData, or null.
*
@@ -291,11 +340,13 @@ export async function readClipboard(): Promise<ItemData | null> {
const img = clipboard.readImage()
const hasImage = !img.isEmpty()
- const rawText = clipboard.readText().trim()
- const rawHtml = clipboard.readHTML().trim()
+ const rawText = clipboard.readText()
+ const rawHtml = clipboard.readHTML()
+ const trimmedText = rawText.trim()
+ const trimmedHtml = rawHtml.trim()
// Snipping Tool (Window mode, Freeform, Rectangular) or browser images:
- if (isScreenshotOrImageIntent(hasImage, rawText, rawHtml)) {
+ if (isScreenshotOrImageIntent(hasImage, trimmedText, trimmedHtml)) {
const size = img.getSize()
return {
kind: 'image',
@@ -307,14 +358,17 @@ export async function readClipboard(): Promise<ItemData | null> {
}
// Text intent (Notepad, Word, VS Code text copy, Excel/Google Sheets tabular copy, rich HTML copy)
- if (rawText) {
+ if (trimmedText) {
let html: string | undefined
- if (rawHtml && rawHtml !== rawText) html = rawHtml
+ if (trimmedHtml && trimmedHtml !== trimmedText) html = rawHtml
+
+ // When text contains tabs (\t), preserve the exact TSV representation (including leading/trailing tabs for empty columns)
+ const textToStore = rawText.includes('\t') ? rawText.replace(/\r?\n+$/, '') : trimmedText
- const isUrl = URL_RE.test(rawText)
- const isColor = COLOR_HEX_RE.test(rawText)
+ const isUrl = URL_RE.test(trimmedText)
+ const isColor = COLOR_HEX_RE.test(trimmedText)
- return { kind: 'text', text: rawText, html, isUrl, isColor }
+ return { kind: 'text', text: textToStore, html, isUrl, isColor }
}
// Fallback to image if no text
diff --git a/electron/main/ipc.ts b/electron/main/ipc.ts
index ee46262..0232111 100644
--- a/electron/main/ipc.ts
+++ b/electron/main/ipc.ts
@@ -17,7 +17,7 @@ import { registerGlobalHotkey } from './index'
import { getOnboardingWindow } from './onboardingWindow'
import { rebuildTrayMenu } from './tray'
import { startDragOut, resolveDragData } from './drag'
-import { clipboardSignature } from '../clipboard/formats'
+import { clipboardSignature, formatTabularDataForClipboard } from '../clipboard/formats'
import type { ItemData, MergeResult } from '../../shared/types'
import { quitAndInstallUpdate, checkForUpdatesManual, startUpdateDownload, syncAutoUpdaterState } from './updater'
import { createId } from '../store/ids'
@@ -674,9 +674,9 @@ export function registerSendListeners(): void {
export async function writeItemToClipboard(data: ItemData): Promise<void> {
switch (data.kind) {
case 'text': {
- const textToUse = data.text
+ const formatted = formatTabularDataForClipboard(data.text, data.html)
clipboard.clear()
- clipboard.write({ text: textToUse, html: data.html })
+ clipboard.write({ text: formatted.text, html: formatted.html })
break
}
diff --git a/src/components/ClipboardItem.tsx b/src/components/ClipboardItem.tsx
index 756a8a8..3d242ad 100644
--- a/src/components/ClipboardItem.tsx
+++ b/src/components/ClipboardItem.tsx
@@ -29,21 +29,18 @@ import { parseUrlPreview } from '../lib/urlPreview'
import '../styles/item.css'
import { tryPaste } from '../lib/tryPaste'
-import { t } from '../i18n'
+import { useTranslation, t } from '../i18n'
interface Props {
item: ClipboardItemDto
}
-
-
-
-
/* ------------------------------------------------------------------ */
/* Main item card */
/* ------------------------------------------------------------------ */
const ClipboardItemBase = forwardRef<HTMLDivElement, Props>(({ item }, ref) => {
+ const { t } = useTranslation()
const copy = useStore.getState().copy
const paste = useStore.getState().paste
const togglePin = useStore.getState().togglePin
@@ -55,8 +52,15 @@ const ClipboardItemBase = forwardRef<HTMLDivElement, Props>(({ item }, ref) => {
const open = useStore((s) => s.open)
+ const [, setTimeTick] = useState(0)
+
useEffect(() => {
- if (!open) setExpanded(false)
+ if (!open) {
+ setExpanded(false)
+ return
+ }
+ const timer = window.setInterval(() => setTimeTick((n) => n + 1), 30000)
+ return () => window.clearInterval(timer)
}, [open])
const isPreviewing = useStore((s) => s.previewItemId) === item.id
@@ -542,7 +546,7 @@ function BundleFluidPreview({
className="fluid-row-img"
/>
) : (
- <FileKindIcon path={filePath} width={44} height={44} isDirectory={entry?.isDirectory} />
+ <FileKindIcon path={filePath} width={48} height={48} isDirectory={entry?.isDirectory} />
)}
</div>
<div className="fluid-row-content">
@@ -612,7 +616,7 @@ function BundleFluidPreview({
style={{ width: '100%', height: '100%', objectFit: 'cover', borderRadius: 8 }}
/>
) : (
- <FileKindIcon path={filePath} width={100} height={100} isDirectory={entry?.isDirectory} />
+ <FileKindIcon path={filePath} width={112} height={112} isDirectory={entry?.isDirectory} />
)}
</motion.div>
)
@@ -721,7 +725,7 @@ function Preview({ item }: { item: ClipboardItemDto }) {
return (
<div className="single-file-preview">
<div className="single-file-hero" style={{ color: info.color }}>
- <FileKindIcon path={first} width={120} height={120} isDirectory={entry?.isDirectory} />
+ <FileKindIcon path={first} width={136} height={136} isDirectory={entry?.isDirectory} />
</div>
<div className="single-file-meta">
<div className="preview single single-file-name" title={displayName}>
diff --git a/src/components/PreviewFlyout.tsx b/src/components/PreviewFlyout.tsx
index 859cbdf..aefe077 100644
--- a/src/components/PreviewFlyout.tsx
+++ b/src/components/PreviewFlyout.tsx
@@ -743,7 +743,7 @@ function PreviewContent({
<QuickActionButton
title={t('flyout.copyText')}
icon={CopyIcon}
- onClick={() => navigator.clipboard.writeText(activeText)}
+ onClick={() => window.edge.copyItem(item.id)}
/>
</div>
<div style={{
diff --git a/src/i18n/translations.ts b/src/i18n/translations.ts
index f618873..81a1b6b 100644
--- a/src/i18n/translations.ts
+++ b/src/i18n/translations.ts
@@ -600,6 +600,7 @@ export const en: TranslationKeys = {
"audio": "Audio",
"video": "Video",
"image": "Image",
+ "folder": "Folder",
"file": "File"
},
"emptyState": {
@@ -865,6 +866,7 @@ export const es: TranslationKeys = {
"audio": "Audio",
"video": "Vídeo",
"image": "Imagen",
+ "folder": "Carpeta",
"file": "Archivo"
},
"emptyState": {
@@ -1130,6 +1132,7 @@ export const fr: TranslationKeys = {
"audio": "Audio",
"video": "Vidéo",
"image": "Image",
+ "folder": "Dossier",
"file": "Fichier"
},
"emptyState": {
@@ -1395,6 +1398,7 @@ export const de: TranslationKeys = {
"audio": "Audio",
"video": "Video",
"image": "Bild",
+ "folder": "Ordner",
"file": "Datei"
},
"emptyState": {
@@ -1660,6 +1664,7 @@ export const it: TranslationKeys = {
"audio": "Audio",
"video": "Video",
"image": "Immagine",
+ "folder": "Cartella",
"file": "File"
},
"emptyState": {
@@ -1925,6 +1930,7 @@ export const pt: TranslationKeys = {
"audio": "Áudio",
"video": "Vídeo",
"image": "Imagem",
+ "folder": "Pasta",
"file": "Arquivo"
},
"emptyState": {
@@ -2190,6 +2196,7 @@ export const ru: TranslationKeys = {
"audio": "Аудио",
"video": "Видео",
"image": "Изображение",
+ "folder": "Папка",
"file": "Файл"
},
"emptyState": {
@@ -2455,6 +2462,7 @@ export const ja: TranslationKeys = {
"audio": "オーディオ",
"video": "動画",
"image": "画像",
+ "folder": "フォルダー",
"file": "ファイル"
},
"emptyState": {
@@ -2720,6 +2728,7 @@ export const ko: TranslationKeys = {
"audio": "오디오",
"video": "비디오",
"image": "이미지",
+ "folder": "폴더",
"file": "파일"
},
"emptyState": {
@@ -2985,6 +2994,7 @@ export const zhCN: TranslationKeys = {
"audio": "音频",
"video": "视频",
"image": "图片",
+ "folder": "文件夹",
"file": "文件"
},
"emptyState": {
@@ -3250,6 +3260,7 @@ export const zhTW: TranslationKeys = {
"audio": "音訊",
"video": "影片",
"image": "圖片",
+ "folder": "資料夾",
"file": "檔案"
},
"emptyState": {
@@ -3515,6 +3526,7 @@ export const hi: TranslationKeys = {
"audio": "ऑडियो",
"video": "वीडियो",
"image": "छवि",
+ "folder": "फ़ोल्डर",
"file": "फ़ाइल"
},
"emptyState": {
@@ -3780,6 +3792,7 @@ export const ar: TranslationKeys = {
"audio": "صوت",
"video": "فيديو",
"image": "صورة",
+ "folder": "مجلد",
"file": "ملف"
},
"emptyState": {
@@ -4045,6 +4058,7 @@ export const fa: TranslationKeys = {
"audio": "صدا",
"video": "ویدیو",
"image": "عکس",
+ "folder": "پوشه",
"file": "فایل"
},
"emptyState": {
@@ -4310,6 +4324,7 @@ export const bn: TranslationKeys = {
"audio": "অডিও",
"video": "ভিডিও",
"image": "ছবি",
+ "folder": "ফোল্ডার",
"file": "ফাইল"
},
"emptyState": {
@@ -4575,6 +4590,7 @@ export const tr: TranslationKeys = {
"audio": "Ses",
"video": "Video",
"image": "Görsel",
+ "folder": "Klasör",
"file": "Dosya"
},
"emptyState": {
@@ -4840,6 +4856,7 @@ export const vi: TranslationKeys = {
"audio": "Âm thanh",
"video": "Video",
"image": "Hình ảnh",
+ "folder": "Thư mục",
"file": "Tệp"
},
"emptyState": {
@@ -5105,6 +5122,7 @@ export const pl: TranslationKeys = {
"audio": "Audio",
"video": "Wideo",
"image": "Obraz",
+ "folder": "Folder",
"file": "Plik"
},
"emptyState": {
@@ -5370,6 +5388,7 @@ export const nl: TranslationKeys = {
"audio": "Audio",
"video": "Video",
"image": "Afbeelding",
+ "folder": "Map",
"file": "Bestand"
},
"emptyState": {
@@ -5635,6 +5654,7 @@ export const sv: TranslationKeys = {
"audio": "Ljud",
"video": "Video",
"image": "Bild",
+ "folder": "Mapp",
"file": "Fil"
},
"emptyState": {
@@ -5900,6 +5920,7 @@ export const id: TranslationKeys = {
"audio": "Audio",
"video": "Video",
"image": "Gambar",
+ "folder": "Folder",
"file": "Berkas"
},
"emptyState": {
@@ -6165,6 +6186,7 @@ export const uk: TranslationKeys = {
"audio": "Аудіо",
"video": "Відео",
"image": "Зображення",
+ "folder": "Папка",
"file": "Файл"
},
"emptyState": {
@@ -6430,6 +6452,7 @@ export const el: TranslationKeys = {
"audio": "Ήχος",
"video": "Βίντεο",
"image": "Εικόνα",
+ "folder": "Φάκελος",
"file": "Αρχείο"
},
"emptyState": {
@@ -6695,6 +6718,7 @@ export const cs: TranslationKeys = {
"audio": "Audio",
"video": "Video",
"image": "Obrázek",
+ "folder": "Složka",
"file": "Soubor"
},
"emptyState": {
@@ -6960,6 +6984,7 @@ export const ro: TranslationKeys = {
"audio": "Audio",
"video": "Video",
"image": "Imagine",
+ "folder": "Dosar",
"file": "Fișier"
},
"emptyState": {
@@ -7225,6 +7250,7 @@ export const hu: TranslationKeys = {
"audio": "Audió",
"video": "Videó",
"image": "Kép",
+ "folder": "Mappa",
"file": "Fájl"
},
"emptyState": {
@@ -7490,6 +7516,7 @@ export const da: TranslationKeys = {
"audio": "Lyd",
"video": "Video",
"image": "Billede",
+ "folder": "Mappe",
"file": "Fil"
},
"emptyState": {
@@ -7755,6 +7782,7 @@ export const fi: TranslationKeys = {
"audio": "Ääni",
"video": "Video",
"image": "Kuva",
+ "folder": "Kansio",
"file": "Tiedosto"
},
"emptyState": {
@@ -8020,6 +8048,7 @@ export const th: TranslationKeys = {
"audio": "เสียง",
"video": "วิดีโอ",
"image": "รูปภาพ",
+ "folder": "โฟลเดอร์",
"file": "ไฟล์"
},
"emptyState": {
@@ -8285,6 +8314,7 @@ export const he: TranslationKeys = {
"audio": "אודיו",
"video": "וידאו",
"image": "תמונה",
+ "folder": "תיקייה",
"file": "קובץ"
},
"emptyState": {
@@ -8550,6 +8580,7 @@ export const no: TranslationKeys = {
"audio": "Lyd",
"video": "Video",
"image": "Bilde",
+ "folder": "Mappe",
"file": "Fil"
},
"emptyState": {
diff --git a/src/lib/fileType.ts b/src/lib/fileType.ts
index 470d19e..4cf7490 100644
--- a/src/lib/fileType.ts
+++ b/src/lib/fileType.ts
@@ -90,13 +90,19 @@ const KEY_MAP: Record<FileKind, any> = {
file: 'fileKinds.file'
}
+function translateKind(key: string, fallback: string): string {
+ const val = t(key)
+ if (!val || val.startsWith('fileKinds.') || val === key) return fallback
+ return val
+}
+
/** Resolve a file path to its display metadata (kind / label / color). */
export function getFileKind(path: string, isDirectory?: boolean): FileKindInfo {
if (isDirectory) {
const base = KIND_INFO.folder
return {
...base,
- label: t('fileKinds.folder') || base.label
+ label: translateKind('fileKinds.folder', base.label)
}
}
const ext = extOf(path)
@@ -104,7 +110,7 @@ export function getFileKind(path: string, isDirectory?: boolean): FileKindInfo {
const base = KIND_INFO[kind]
return {
...base,
- label: t(KEY_MAP[kind]) || base.label
+ label: translateKind(KEY_MAP[kind], base.label)
}
}
@@ -114,13 +120,13 @@ export function getFileKindByExt(ext: string, isDirectory?: boolean): FileKindIn
const base = KIND_INFO.folder
return {
...base,
- label: t('fileKinds.folder') || base.label
+ label: translateKind('fileKinds.folder', base.label)
}
}
const kind = EXT_MAP[ext.toLowerCase()] ?? 'file'
const base = KIND_INFO[kind]
return {
...base,
- label: t(KEY_MAP[kind]) || base.label
+ label: translateKind(KEY_MAP[kind], base.label)
}
}
diff --git a/tests/clipboardWatcher.test.ts b/tests/clipboardWatcher.test.ts
new file mode 100644
index 0000000..6326979
--- /dev/null
+++ b/tests/clipboardWatcher.test.ts
@@ -0,0 +1,96 @@
+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
+import { ClipboardWatcher } from '../electron/clipboard/ClipboardWatcher'
+import * as formats from '../electron/clipboard/formats'
+
+describe('ClipboardWatcher Re-Copy Detection & Flare Flow', () => {
+ let watcher: ClipboardWatcher
+
+ beforeEach(() => {
+ vi.useFakeTimers()
+ })
+
+ afterEach(() => {
+ if (watcher) watcher.stop()
+ vi.useRealTimers()
+ vi.restoreAllMocks()
+ })
+
+ it('detects re-copies of the identical item when the OS sequence number increments', async () => {
+ let mockSeq = 100
+ let mockText = 'Hello Edge-Drop'
+
+ vi.spyOn(formats, 'clipboardSignature').mockImplementation(() => `seq:${mockSeq}:text:${mockText}`)
+ vi.spyOn(formats, 'readClipboard').mockImplementation(async () => ({ kind: 'text', text: mockText }))
+
+ const onNew = vi.fn()
+ watcher = new ClipboardWatcher(50)
+ watcher.start(onNew)
+
+ // Initially seeded — no callback on tick 1
+ await vi.advanceTimersByTimeAsync(60)
+ expect(onNew).not.toHaveBeenCalled()
+
+ // 1. User copies the exact same text again in the OS (sequence number increments)
+ mockSeq = 101
+ await vi.advanceTimersByTimeAsync(60) // interval tick
+ await vi.advanceTimersByTimeAsync(160) // settling window timeout
+
+ expect(onNew).toHaveBeenCalledTimes(1)
+ expect(onNew).toHaveBeenCalledWith({ kind: 'text', text: 'Hello Edge-Drop' })
+
+ // 2. Ticks without any new copy action do NOT fire
+ await vi.advanceTimersByTimeAsync(200)
+ expect(onNew).toHaveBeenCalledTimes(1)
+
+ // 3. User copies the exact same text a third time (sequence number increments again)
+ mockSeq = 102
+ await vi.advanceTimersByTimeAsync(60)
+ await vi.advanceTimersByTimeAsync(160)
+
+ expect(onNew).toHaveBeenCalledTimes(2)
+ })
+
+ it('detects brand new items when content changes', async () => {
+ let mockSeq = 200
+ let mockText = 'First Item'
+
+ vi.spyOn(formats, 'clipboardSignature').mockImplementation(() => `seq:${mockSeq}:text:${mockText}`)
+ vi.spyOn(formats, 'readClipboard').mockImplementation(async () => ({ kind: 'text', text: mockText }))
+
+ const onNew = vi.fn()
+ watcher = new ClipboardWatcher(50)
+ watcher.start(onNew)
+
+ await vi.advanceTimersByTimeAsync(60)
+ expect(onNew).not.toHaveBeenCalled()
+
+ // Change to a new item
+ mockSeq = 201
+ mockText = 'Second Item'
+ await vi.advanceTimersByTimeAsync(60)
+ await vi.advanceTimersByTimeAsync(160)
+
+ expect(onNew).toHaveBeenCalledTimes(1)
+ expect(onNew).toHaveBeenCalledWith({ kind: 'text', text: 'Second Item' })
+ })
+
+ it('respects paused state during self-copy and incognito mode', async () => {
+ let mockSeq = 300
+ let mockText = 'Initial'
+
+ vi.spyOn(formats, 'clipboardSignature').mockImplementation(() => `seq:${mockSeq}:text:${mockText}`)
+ vi.spyOn(formats, 'readClipboard').mockImplementation(async () => ({ kind: 'text', text: mockText }))
+
+ const onNew = vi.fn()
+ watcher = new ClipboardWatcher(50)
+ watcher.start(onNew)
+
+ watcher.setPaused(true)
+
+ mockSeq = 301
+ mockText = 'Copied While Paused'
+ await vi.advanceTimersByTimeAsync(300)
+
+ expect(onNew).not.toHaveBeenCalled()
+ })
+})
diff --git a/tests/spreadsheetClipboard.test.ts b/tests/spreadsheetClipboard.test.ts
new file mode 100644
index 0000000..1dec6fb
--- /dev/null
+++ b/tests/spreadsheetClipboard.test.ts
@@ -0,0 +1,122 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest'
+import { formatTabularDataForClipboard, readClipboard } from '../electron/clipboard/formats'
+import { clipboard } from 'electron'
+
+// Mock Electron clipboard
+vi.mock('electron', () => {
+ let mockFormats: string[] = []
+ let mockText = ''
+ let mockHtml = ''
+ let mockImage = {
+ isEmpty: () => true,
+ getSize: () => ({ width: 0, height: 0 }),
+ toBitmap: () => Buffer.alloc(0),
+ toPNG: () => Buffer.alloc(0)
+ }
+
+ return {
+ clipboard: {
+ availableFormats: vi.fn(() => mockFormats),
+ readText: vi.fn(() => mockText),
+ readHTML: vi.fn(() => mockHtml),
+ readImage: vi.fn(() => mockImage),
+ readBuffer: vi.fn(() => Buffer.alloc(0)),
+ __setMockState: (state: {
+ formats?: string[]
+ text?: string
+ html?: string
+ image?: { isEmpty: () => boolean; getSize: () => { width: number; height: number }; toBitmap: () => Buffer; toPNG: () => Buffer }
+ }) => {
+ mockFormats = state.formats ?? []
+ mockText = state.text ?? ''
+ mockHtml = state.html ?? ''
+ mockImage = state.image ?? {
+ isEmpty: () => true,
+ getSize: () => ({ width: 0, height: 0 }),
+ toBitmap: () => Buffer.alloc(0),
+ toPNG: () => Buffer.alloc(0)
+ }
+ }
+ }
+ }
+})
+
+describe('Spreadsheet Tabular Clipboard Formatting', () => {
+ beforeEach(() => {
+ vi.clearAllMocks()
+ })
+
+ it('formats TSV spreadsheet cells into Windows CRLF text and standard HTML table', () => {
+ const rawTsv = 'Name\tAge\tCity\nAlice\t28\tSeattle\nBob\t34\tNew York'
+ const result = formatTabularDataForClipboard(rawTsv)
+
+ expect(result.text).toBe('Name\tAge\tCity\r\nAlice\t28\tSeattle\r\nBob\t34\tNew York')
+ expect(result.html).toBe(
+ '<table border="0" cellpadding="0" cellspacing="0"><tbody>' +
+ '<tr><td>Name</td><td>Age</td><td>City</td></tr>' +
+ '<tr><td>Alice</td><td>28</td><td>Seattle</td></tr>' +
+ '<tr><td>Bob</td><td>34</td><td>New York</td></tr>' +
+ '</tbody></table>'
+ )
+ })
+
+ it('preserves existing HTML table if rawHtml already contains a valid table', () => {
+ const rawTsv = 'A\tB\r\nC\td'
+ const existingTableHtml = '<table class="excel-table"><tr><td>A</td><td>B</td></tr><tr><td>C</td><td>d</td></tr></table>'
+ const result = formatTabularDataForClipboard(rawTsv, existingTableHtml)
+
+ expect(result.text).toBe('A\tB\r\nC\td')
+ expect(result.html).toBe(existingTableHtml)
+ })
+
+ it('replaces non-table HTML wrappers (e.g. Google Sheets origin divs) with standard table', () => {
+ const rawTsv = 'Col1\tCol2\r\nVal1\tVal2'
+ const googleSheetsDivHtml = '<google-sheets-html-origin><style></style><div id="test"><span>Val1</span></div></google-sheets-html-origin>'
+ const result = formatTabularDataForClipboard(rawTsv, googleSheetsDivHtml)
+
+ expect(result.text).toBe('Col1\tCol2\r\nVal1\tVal2')
+ expect(result.html).toBe(
+ '<table border="0" cellpadding="0" cellspacing="0"><tbody>' +
+ '<tr><td>Col1</td><td>Col2</td></tr>' +
+ '<tr><td>Val1</td><td>Val2</td></tr>' +
+ '</tbody></table>'
+ )
+ })
+
+ it('handles empty cells and escapes HTML characters properly', () => {
+ const rawTsv = '\t<Tom & Jerry>\r\n100\t'
+ const result = formatTabularDataForClipboard(rawTsv)
+
+ expect(result.text).toBe('\t<Tom & Jerry>\r\n100\t')
+ expect(result.html).toBe(
+ '<table border="0" cellpadding="0" cellspacing="0"><tbody>' +
+ '<tr><td></td><td>&lt;Tom &amp; Jerry&gt;</td></tr>' +
+ '<tr><td>100</td><td></td></tr>' +
+ '</tbody></table>'
+ )
+ })
+
+ it('normalizes plain multiline text to CRLF without creating unnecessary HTML tables', () => {
+ const multilineText = 'Line 1\nLine 2\nLine 3'
+ const result = formatTabularDataForClipboard(multilineText)
+
+ expect(result.text).toBe('Line 1\r\nLine 2\r\nLine 3')
+ expect(result.html).toBeUndefined()
+ })
+
+ it('captures spreadsheet data in readClipboard preserving leading and internal tabs', async () => {
+ ;(clipboard as any).__setMockState({
+ formats: ['CF_UNICODETEXT', 'HTML Format'],
+ text: '\tValueB\r\nValueC\tValueD\r\n',
+ html: '<table><tr><td></td><td>ValueB</td></tr><tr><td>ValueC</td><td>ValueD</td></tr></table>'
+ })
+
+ const item = await readClipboard()
+ expect(item).not.toBeNull()
+ expect(item?.kind).toBe('text')
+ if (item?.kind === 'text') {
+ expect(item.text).toBe('\tValueB\r\nValueC\tValueD')
+ expect(item.html).toContain('<table>')
+ }
+ })
+})