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): keep original image names on drop, drag, and paste

Deepender25c4586d056cad
diff --git a/electron/clipboard/formats.ts b/electron/clipboard/formats.ts
index c0a8c64..5a99674 100644
--- a/electron/clipboard/formats.ts
+++ b/electron/clipboard/formats.ts
@@ -9,8 +9,9 @@
import { clipboard } from 'electron'
import { execFile } from 'node:child_process'
import { promisify } from 'node:util'
+import { existsSync } from 'node:fs'
import koffi from 'koffi'
-import type { ItemData } from '../../shared/types'
+import type { ClipboardImageSource, ItemData } from '../../shared/types'
let getSeqNum: (() => number) | null = null
if (process.platform === 'win32') {
@@ -122,6 +123,77 @@ export function buildFileListBuffer(paths: string[]): Buffer {
const URL_RE = /^(https?:\/\/|www\.)[^\s]+$/i
const COLOR_HEX_RE = /^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i
+const FILE_URL_RE = /file:\/\/\/?([^\s"'<>]+)/i
+
+/** Turn a clipboard file:// URL into a local path if that file exists. */
+export function localPathFromClipboardFileUrl(raw: string): string | null {
+ const m = raw.match(FILE_URL_RE)
+ if (!m) return null
+ try {
+ let decoded = decodeURIComponent(m[1].replace(/"/g, ''))
+ if (/^[a-zA-Z]:[\\/]/.test(decoded) || decoded.startsWith('\\\\')) {
+ decoded = decoded.replace(/\//g, '\\')
+ } else if (/^[a-zA-Z]\//.test(decoded)) {
+ decoded = decoded.replace(/^([a-zA-Z])\//, '$1:\\').replace(/\//g, '\\')
+ }
+ return existsSync(decoded) ? decoded : null
+ } catch {
+ return null
+ }
+}
+
+export function extractClipboardImageFileName(text: string, html: string): string | undefined {
+ const fromHtml = localPathFromClipboardFileUrl(html)
+ if (fromHtml) {
+ const base = fromHtml.replace(/^.*[\\/]/, '')
+ if (base) return base
+ }
+ const fromText = localPathFromClipboardFileUrl(text)
+ if (fromText) {
+ const base = fromText.replace(/^.*[\\/]/, '')
+ if (base) return base
+ }
+ const http = text.match(/^(https?:\/\/.+)\/([^/?#]+)$/i)
+ if (http && /\.(png|jpe?g|gif|webp|bmp|svg|avif)$/i.test(http[2])) {
+ try {
+ return decodeURIComponent(http[2])
+ } catch {
+ return http[2]
+ }
+ }
+ return undefined
+}
+
+export function detectClipboardImageSource(text: string, html: string): ClipboardImageSource {
+ try {
+ const formats = clipboard.availableFormats().map((f) => f.toLowerCase())
+ if (formats.some((f) => /screenshot|snipping|screen\s*clip|screenclip/.test(f))) {
+ return 'screenshot'
+ }
+ if (formats.some((f) => /filegroupdescriptor|filecontents|filenamew|shell idlist/.test(f))) {
+ return 'image'
+ }
+ } catch {
+ /* ignore */
+ }
+
+ if (localPathFromClipboardFileUrl(html) || localPathFromClipboardFileUrl(text)) return 'image'
+ if (/^<img\b/i.test(html.trim()) || URL_RE.test(text.trim())) return 'image'
+
+ const trimmed = text.trim()
+ if (
+ trimmed &&
+ !URL_RE.test(trimmed) &&
+ !trimmed.includes('\t') &&
+ trimmed.split(/\r?\n/).filter(Boolean).length === 1 &&
+ trimmed.length <= 200
+ ) {
+ return 'screenshot'
+ }
+
+ if (!trimmed && !html.trim()) return 'screenshot'
+ return 'image'
+}
/** Sensitive clipboard formats used by password managers and transient scripts. */
const IGNORED_FORMATS = [
@@ -345,6 +417,9 @@ export async function readClipboard(): Promise<ItemData | null> {
const trimmedText = rawText.trim()
const trimmedHtml = rawHtml.trim()
+ const localFromHtml = localPathFromClipboardFileUrl(trimmedHtml) || localPathFromClipboardFileUrl(trimmedText)
+ if (localFromHtml) return { kind: 'files', paths: [localFromHtml] }
+
// Snipping Tool (Window mode, Freeform, Rectangular) or browser images:
if (isScreenshotOrImageIntent(hasImage, trimmedText, trimmedHtml)) {
const size = img.getSize()
@@ -353,7 +428,9 @@ export async function readClipboard(): Promise<ItemData | null> {
imageId: '',
width: size.width,
height: size.height,
- bytes: 0 // placeholder — ClipboardWatcher overwrites this with the actual PNG buffer length
+ bytes: 0, // placeholder — ClipboardWatcher overwrites this with the actual PNG buffer length
+ source: detectClipboardImageSource(trimmedText, trimmedHtml),
+ fileName: extractClipboardImageFileName(trimmedText, trimmedHtml)
}
}
@@ -379,7 +456,9 @@ export async function readClipboard(): Promise<ItemData | null> {
imageId: '',
width: size.width,
height: size.height,
- bytes: 0
+ bytes: 0,
+ source: detectClipboardImageSource(trimmedText, trimmedHtml),
+ fileName: extractClipboardImageFileName(trimmedText, trimmedHtml)
}
}
diff --git a/electron/main/drag.ts b/electron/main/drag.ts
index 3dd55f6..6ac9e97 100644
--- a/electron/main/drag.ts
+++ b/electron/main/drag.ts
@@ -22,11 +22,7 @@ import type { DragRequest, ItemData } from '../../shared/types'
import { getStore } from './state'
import { getFileKind } from '../../src/lib/fileType'
-/**
- * Formats a clean, Windows OS-compliant human-readable screenshot filename
- * based on the capture timestamp (e.g. "Screenshot 2026-08-15 22.30.45.png").
- */
-export function formatScreenshotFilename(capturedAt?: number, ext = 'png', indexSuffix?: number): string {
+function stampForFilename(capturedAt?: number): string {
const d = capturedAt ? new Date(capturedAt) : new Date()
const year = d.getFullYear()
const month = String(d.getMonth() + 1).padStart(2, '0')
@@ -34,10 +30,38 @@ export function formatScreenshotFilename(capturedAt?: number, ext = 'png', index
const hours = String(d.getHours()).padStart(2, '0')
const minutes = String(d.getMinutes()).padStart(2, '0')
const seconds = String(d.getSeconds()).padStart(2, '0')
+ return `${year}-${month}-${day} ${hours}.${minutes}.${seconds}`
+}
+
+function sanitizeFileName(name: string): string {
+ return name.replace(/[<>:"/\\|?*\u0000-\u001f]/g, '_').replace(/^\.+/, '').trim() || 'Image'
+}
+/**
+ * Filename for a staged clipboard bitmap.
+ * Screenshots keep the Windows-style Screenshot stamp; other bitmaps use Image
+ * (or the original name when the clipboard provided one).
+ */
+export function formatClipboardImageFilename(
+ capturedAt?: number,
+ ext = 'png',
+ opts?: { source?: 'screenshot' | 'image'; fileName?: string; indexSuffix?: number }
+): string {
const cleanExt = ext.replace(/^\./, '') || 'png'
- const suffix = typeof indexSuffix === 'number' && indexSuffix > 1 ? ` (${indexSuffix})` : ''
- return `Screenshot ${year}-${month}-${day} ${hours}.${minutes}.${seconds}${suffix}.${cleanExt}`
+ const suffix = typeof opts?.indexSuffix === 'number' && opts.indexSuffix > 1 ? ` (${opts.indexSuffix})` : ''
+ if (opts?.fileName) {
+ const safe = sanitizeFileName(opts.fileName)
+ const base = safe.replace(/\.[^.]+$/, '')
+ const givenExt = (safe.match(/\.([a-z0-9]+)$/i)?.[1] || cleanExt).toLowerCase()
+ return `${base}${suffix}.${givenExt}`
+ }
+ const prefix = opts?.source === 'image' ? 'Image' : 'Screenshot'
+ return `${prefix} ${stampForFilename(capturedAt)}${suffix}.${cleanExt}`
+}
+
+/** @deprecated use formatClipboardImageFilename */
+export function formatScreenshotFilename(capturedAt?: number, ext = 'png', indexSuffix?: number): string {
+ return formatClipboardImageFilename(capturedAt, ext, { source: 'screenshot', indexSuffix })
}
/**
@@ -137,7 +161,10 @@ export function stageDragFile(data: ItemData, capturedAt?: number): Staged | nul
const src = getStore().getImagePath(data.imageId, data.ext)
if (!existsSync(src)) return null
const ext = extname(src) || '.png'
- const fileName = formatScreenshotFilename(capturedAt, ext)
+ const fileName = formatClipboardImageFilename(capturedAt, ext, {
+ source: data.source,
+ fileName: data.fileName
+ })
const dest = join(temp, fileName)
try {
if (!existsSync(dest)) {
@@ -156,7 +183,11 @@ export function stageDragFile(data: ItemData, capturedAt?: number): Staged | nul
const src = getStore().getImagePath(img.imageId, img.ext)
if (existsSync(src)) {
const ext = extname(src) || '.png'
- const fileName = formatScreenshotFilename(capturedAt, ext, idx)
+ const fileName = formatClipboardImageFilename(capturedAt, ext, {
+ source: img.source,
+ fileName: img.fileName,
+ indexSuffix: idx
+ })
const dest = join(temp, fileName)
try {
if (!existsSync(dest)) {
diff --git a/electron/main/ipc.ts b/electron/main/ipc.ts
index 616bd61..e0cdb13 100644
--- a/electron/main/ipc.ts
+++ b/electron/main/ipc.ts
@@ -16,7 +16,7 @@ import { sendToMainWindow, setInteractive, setHeartbeatPaused, setHotZoneWidth,
import { registerGlobalHotkey } from './index'
import { getOnboardingWindow } from './onboardingWindow'
import { rebuildTrayMenu } from './tray'
-import { startDragOut, resolveDragData, prestageDrag } from './drag'
+import { startDragOut, resolveDragData, prestageDrag, stageDragFile } from './drag'
import { clipboardSignature, formatTabularDataForClipboard } from '../clipboard/formats'
import type { ItemData, MergeResult } from '../../shared/types'
import { quitAndInstallUpdate, checkForUpdatesManual, startUpdateDownload, syncAutoUpdaterState } from './updater'
@@ -112,6 +112,34 @@ async function writeFileListToClipboard(rawPaths: string[]): Promise<void> {
}
}
+/** Bitmap for apps that read CF_DIB, plus a named file so Explorer paste keeps our filename. */
+async function writeImageWithNamedFile(imagePath: string, namedPath: string): Promise<boolean> {
+ if (process.platform !== 'win32') return false
+ try {
+ const b64Img = Buffer.from(imagePath, 'utf8').toString('base64')
+ const b64File = Buffer.from(namedPath, 'utf8').toString('base64')
+ const script = [
+ 'Add-Type -AssemblyName System.Windows.Forms',
+ 'Add-Type -AssemblyName System.Drawing',
+ `$img=[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${b64Img}'))`,
+ `$fp=[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${b64File}'))`,
+ '$bmp=[Drawing.Image]::FromFile($img)',
+ '$d=New-Object Windows.Forms.DataObject',
+ '$d.SetImage($bmp)',
+ '$c=New-Object System.Collections.Specialized.StringCollection',
+ '$c.Add($fp)|Out-Null',
+ '$d.SetFileDropList($c)',
+ '[Windows.Forms.Clipboard]::SetDataObject($d,$true)',
+ '$bmp.Dispose()'
+ ].join(';')
+ await psHost.run(script, 3000)
+ return true
+ } catch (err) {
+ console.error('[ipc] writeImageWithNamedFile failed:', err)
+ return false
+ }
+}
+
export async function writeImageToClipboard(imagePath: string | null, previewDataUrl?: string): Promise<void> {
// If we have the full image path on disk, load the nativeImage directly from path
if (imagePath && existsSync(imagePath)) {
@@ -464,7 +492,17 @@ export function registerIpc(): void {
}
if (data.kind === 'image' && (data as any).imageUrl) {
- const imageUrl = (data as any).imageUrl
+ const imageUrl = (data as any).imageUrl as string
+ if (/^file:/i.test(imageUrl)) {
+ const local = imageUrl.replace(/^file:\/\//i, '').replace(/^\/([a-zA-Z]:)/, '$1')
+ try {
+ const decoded = decodeURIComponent(local).replace(/\//g, '\\')
+ if (existsSync(decoded)) {
+ addFiles([decoded])
+ return getStore().toDto()
+ }
+ } catch { /* fall through to bitmap import */ }
+ }
try {
let img = nativeImage.createFromDataURL(imageUrl)
if (img.isEmpty() && /^https?:\/\//i.test(imageUrl)) {
@@ -482,6 +520,11 @@ export function registerIpc(): void {
data.width = size.width
data.height = size.height
data.ext = 'png'
+ data.source = 'image'
+ const fromUrl = imageUrl.split(/[\\/]/).pop()?.split('?')[0]
+ if (fromUrl && /\.(png|jpe?g|gif|webp|bmp|svg|avif)$/i.test(fromUrl)) {
+ data.fileName = decodeURIComponent(fromUrl)
+ }
getStore().stageImageBytes(data.imageId, png)
png = null
img = null as any
@@ -689,10 +732,13 @@ export async function writeItemToClipboard(data: ItemData): Promise<void> {
(d) => d.data.kind === 'image' && d.data.imageId === data.imageId
)
if (dto && dto.data.kind === 'image') {
- // Write bitmap AND file reference atomically via PowerShell DataObject.
- // This lets the user paste into Slack/Word (reads bitmap) AND into
- // Explorer (reads CF_HDROP file reference) from the same clipboard write.
const src = getStore().getImagePath(dto.data.imageId, dto.data.ext)
+ const staged = src && existsSync(src) ? stageDragFile(data, dto.capturedAt) : null
+ if (staged?.file && src && existsSync(src)) {
+ const named = toUnpackagedFilePath(staged.file)
+ const ok = await writeImageWithNamedFile(toUnpackagedFilePath(src), named)
+ if (ok) break
+ }
await writeImageToClipboard(src && existsSync(src) ? src : null, dto.data.preview)
}
break
diff --git a/electron/main/state.ts b/electron/main/state.ts
index c402f2b..74993d5 100644
--- a/electron/main/state.ts
+++ b/electron/main/state.ts
@@ -10,9 +10,7 @@ import { ClipboardWatcher } from '../clipboard/ClipboardWatcher'
import { loadSettings, saveSettings } from '../store/settings'
import type { ClipboardItemDto, Settings } from '../../shared/types'
import { MAX_STACK } from '../../shared/types'
-import { createId } from '../store/ids'
-import { nativeImage, BrowserWindow, powerMonitor } from 'electron'
-import { readFileSync } from 'node:fs'
+import { BrowserWindow, powerMonitor } from 'electron'
import { isStagedTempPath } from '../store/paths'
import { prefetchFileIcons } from './drag'
import { runtime } from './config'
@@ -169,87 +167,20 @@ export interface AddFilesResult {
}
/**
- * Import dropped file paths.
- *
- * Drops are partitioned into images vs. other files (so a mixed drop of e.g.
- * 2 images + 3 docs becomes an image-collection *and* a files bundle instead of
- * collapsing everything into a generic bundle that loses image previews). Each
- * partition is then chunked into stacks of at most MAX_STACK items.
+ * Import dropped file paths the same way Explorer Ctrl+C is captured:
+ * keep the original paths (and names). Do not copy image bytes into the
+ * internal image store — that made drag-out invent a Screenshot filename.
*/
export function addFiles(paths: string[]): AddFilesResult {
- // Prevent duplicating items when a user accidentally drops our own staged temp
- // files back into the app. Real files are deduplicated automatically by path,
- // but images are staged to temp-drag and would otherwise get new IDs.
const clean = paths.filter((p) => !isStagedTempPath(p))
if (clean.length === 0) return { stacksCreated: 0 }
- const imageExts = /\.(png|jpe?g|gif|webp|bmp|svg|avif|ico|tiff?|jfif|pjpeg|pjp)$/i
- const imagePaths: string[] = []
- const otherPaths: string[] = []
- for (const p of clean) (imageExts.test(p) ? imagePaths : otherPaths).push(p)
-
- if (otherPaths.length > 0) {
- prefetchFileIcons(otherPaths)
- }
+ prefetchFileIcons(clean)
const limit = loadSettings().historyLimit
let stacksCreated = 0
-
- // --- images -> image collections (chunked to MAX_STACK) ---
- if (imagePaths.length > 0) {
- const images = []
- for (const p of imagePaths) {
- try {
- const rawBytes = readFileSync(p)
- let img = nativeImage.createFromBuffer(rawBytes)
- if (img.isEmpty()) {
- const ext = p.split('.').pop()?.toLowerCase() ?? 'png'
- const mime = ext === 'svg' ? 'image/svg+xml'
- : ext === 'gif' ? 'image/gif'
- : ext === 'webp' ? 'image/webp'
- : ext === 'bmp' ? 'image/bmp'
- : ext === 'avif' ? 'image/avif'
- : ext === 'ico' ? 'image/x-icon'
- : ext === 'jpg' || ext === 'jpeg' || ext === 'jfif' || ext === 'pjpeg' || ext === 'pjp' ? 'image/jpeg'
- : ext === 'tif' || ext === 'tiff' ? 'image/tiff'
- : 'image/png'
- const dataUrl = `data:${mime};base64,${rawBytes.toString('base64')}`
- img = nativeImage.createFromDataURL(dataUrl)
- }
-
- const ext = p.split('.').pop()?.toLowerCase() || 'png'
- let width = 300
- let height = 300
- if (!img.isEmpty()) {
- const size = img.getSize()
- if (size.width > 0 && size.height > 0) {
- width = size.width
- height = size.height
- }
- }
-
- const imageId = createId()
- store.stageImageBytes(imageId, rawBytes, ext)
- images.push({ imageId, width, height, bytes: rawBytes.length, ext })
- } catch {
- otherPaths.push(p) // unreadable -> treat as plain file
- }
- }
-
- for (let i = 0; i < images.length; i += MAX_STACK) {
- const chunk = images.slice(i, i + MAX_STACK)
- if (chunk.length === 1) {
- store.add({ kind: 'image', ...chunk[0] }, limit)
- } else {
- store.add({ kind: 'image-collection', images: chunk }, limit)
- }
- stacksCreated++
- }
- }
-
- // --- other files -> files bundles (chunked to MAX_STACK) ---
- for (let i = 0; i < otherPaths.length; i += MAX_STACK) {
- const chunk = otherPaths.slice(i, i + MAX_STACK)
+ for (let i = 0; i < clean.length; i += MAX_STACK) {
+ const chunk = clean.slice(i, i + MAX_STACK)
store.add({ kind: 'files', paths: chunk }, limit)
stacksCreated++
}
diff --git a/electron/store/ItemStore.ts b/electron/store/ItemStore.ts
index 36bdfe7..ef04e0a 100644
--- a/electron/store/ItemStore.ts
+++ b/electron/store/ItemStore.ts
@@ -353,8 +353,8 @@ export class ItemStore {
if (src.data.kind !== 'files' && tgt.data.kind !== 'files') {
const srcData = src.data
const tgtData = tgt.data
- const srcImages = srcData.kind === 'image-collection' ? srcData.images : srcData.kind === 'image' ? [{ imageId: srcData.imageId, width: srcData.width, height: srcData.height, bytes: srcData.bytes, ext: srcData.ext }] : []
- const tgtImages = tgtData.kind === 'image-collection' ? tgtData.images : tgtData.kind === 'image' ? [{ imageId: tgtData.imageId, width: tgtData.width, height: tgtData.height, bytes: tgtData.bytes, ext: tgtData.ext }] : []
+ const srcImages = srcData.kind === 'image-collection' ? srcData.images : srcData.kind === 'image' ? [{ imageId: srcData.imageId, width: srcData.width, height: srcData.height, bytes: srcData.bytes, ext: srcData.ext, source: srcData.source, fileName: srcData.fileName }] : []
+ const tgtImages = tgtData.kind === 'image-collection' ? tgtData.images : tgtData.kind === 'image' ? [{ imageId: tgtData.imageId, width: tgtData.width, height: tgtData.height, bytes: tgtData.bytes, ext: tgtData.ext, source: tgtData.source, fileName: tgtData.fileName }] : []
const seen = new Set(tgtImages.map((i) => i.imageId))
const combined = [...tgtImages, ...srcImages.filter((i) => !seen.has(i.imageId))]
@@ -463,7 +463,7 @@ export class ItemStore {
capturedAt: Date.now(),
hitCount: 1,
pinned: false,
- data: { kind: 'image', imageId: targetImg.imageId, width: targetImg.width, height: targetImg.height, bytes: targetImg.bytes }
+ data: { kind: 'image', ...targetImg }
}
this.items.splice(req.splitPlacement === 'after' ? sourceIndex + 1 : sourceIndex, 0, newItem)
this.rebuildIndex()
@@ -695,10 +695,10 @@ export class ItemStore {
toDto(): ClipboardItemDto[] {
return this.items.map((it) => {
if (it.data.kind === 'image') {
- const { kind, imageId, width, height, bytes, ext } = it.data
+ const { kind, imageId, width, height, bytes, ext, source, fileName } = it.data
return {
...it,
- data: { kind, imageId, width, height, bytes, ext, preview: thumbnailUrlForStoredImage(imageId) }
+ data: { kind, imageId, width, height, bytes, ext, source, fileName, preview: thumbnailUrlForStoredImage(imageId) }
}
}
if (it.data.kind === 'image-collection') {
diff --git a/shared/types.ts b/shared/types.ts
index 862bb67..0dd6cf4 100644
--- a/shared/types.ts
+++ b/shared/types.ts
@@ -11,11 +11,24 @@
/** Maximum number of sub-items that may live in a single stack/bundle. */
export const MAX_STACK = 10
+/** How a clipboard bitmap was captured. Omitted on older persisted items. */
+export type ClipboardImageSource = 'screenshot' | 'image'
+
+export type ClipboardImageFields = {
+ imageId: string
+ width: number
+ height: number
+ bytes: number
+ ext?: string
+ source?: ClipboardImageSource
+ fileName?: string
+}
+
/** Discriminated union describing the payload of a clipboard item. */
export type ItemData =
| { kind: 'text'; text: string; html?: string; isUrl: boolean; isColor?: boolean; hasFullPayload?: boolean; previewText?: string }
- | { kind: 'image'; imageId: string; width: number; height: number; bytes: number; ext?: string }
- | { kind: 'image-collection'; images: { imageId: string; width: number; height: number; bytes: number; ext?: string }[] }
+ | ({ kind: 'image' } & ClipboardImageFields)
+ | { kind: 'image-collection'; images: ClipboardImageFields[] }
| { kind: 'files'; paths: string[] }
export type ItemKind = ItemData['kind']
@@ -56,8 +69,8 @@ export interface FileEntry {
export interface ClipboardItemDto extends Omit<ClipboardItem, 'data'> {
data:
| { kind: 'text'; text: string; html?: string; isUrl: boolean; isColor?: boolean; hasFullPayload?: boolean; previewText?: string }
- | { kind: 'image'; imageId: string; width: number; height: number; bytes: number; preview: string; ext?: string }
- | { kind: 'image-collection'; images: { imageId: string; width: number; height: number; bytes: number; preview: string; ext?: string }[] }
+ | ({ kind: 'image'; preview: string } & ClipboardImageFields)
+ | { kind: 'image-collection'; images: Array<ClipboardImageFields & { preview: string }> }
| { kind: 'files'; paths: string[]; previews?: string[]; entries?: FileEntry[] }
}
diff --git a/src/lib/format.ts b/src/lib/format.ts
index 52e989e..936944b 100644
--- a/src/lib/format.ts
+++ b/src/lib/format.ts
@@ -57,20 +57,26 @@ export function basename(p: string): string {
return parts[parts.length - 1] ?? p
}
-/** Formats a path into a clean display title (converts internal hash IDs to human screenshot titles). */
-export function formatImageDisplayName(path: string, capturedAt?: number): string {
+/** Formats a path into a clean display title (internal hashes become Screenshot or Image + time). */
+export function formatImageDisplayName(
+ path: string,
+ capturedAt?: number,
+ source?: 'screenshot' | 'image',
+ originalName?: string
+): string {
+ if (originalName && originalName.trim()) return originalName
const name = basename(path)
const isInternalHash = /^[a-z0-9]{6,12}-[a-z0-9]{6,12}\.[a-z0-9]+$/i.test(name) || path.includes('edge-drop/images') || path.includes('edge-drop\\images') || path.includes('edge-drop/temp') || path.includes('edge-drop\\temp')
-
+
if (isInternalHash) {
- const screenshotLabel = t('item.screenshot')
+ const label = source === 'image' ? t('item.imageItem') : t('item.screenshot')
if (capturedAt) {
const d = new Date(capturedAt)
const dateStr = d.toLocaleDateString(undefined, { month: 'short', day: 'numeric' })
const timeStr = d.toLocaleTimeString(undefined, { hour: 'numeric', minute: '2-digit' })
- return `${screenshotLabel} ${dateStr}, ${timeStr}`
+ return `${label} ${dateStr}, ${timeStr}`
}
- return screenshotLabel
+ return label
}
return name
}
diff --git a/tests/dragDrop.test.ts b/tests/dragDrop.test.ts
index b688e10..584aa00 100644
--- a/tests/dragDrop.test.ts
+++ b/tests/dragDrop.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
-import { formatScreenshotFilename, stageDragFile } from '../electron/main/drag'
+import { formatScreenshotFilename, formatClipboardImageFilename, stageDragFile } from '../electron/main/drag'
import type { ItemData } from '../shared/types'
// Mock dependencies for staging
@@ -52,6 +52,18 @@ describe('formatScreenshotFilename', () => {
expect(formatScreenshotFilename(date.getTime(), 'png', 3)).toBe('Screenshot 2026-08-15 14.00.00 (3).png')
})
+ it('uses Image prefix for non-screenshot clipboard bitmaps', () => {
+ const date = new Date(2026, 7, 15, 22, 30, 45)
+ expect(formatClipboardImageFilename(date.getTime(), 'png', { source: 'image' })).toBe(
+ 'Image 2026-08-15 22.30.45.png'
+ )
+ })
+
+ it('keeps an original filename when the clipboard provided one', () => {
+ expect(formatClipboardImageFilename(Date.now(), 'png', { source: 'image', fileName: 'vacation photo.jpg' }))
+ .toBe('vacation photo.jpg')
+ })
+
it('ensures zero illegal Windows filesystem characters in generated names', () => {
const date = new Date()
const filename = formatScreenshotFilename(date.getTime())
@@ -82,6 +94,36 @@ describe('stageDragFile dual-channel payload', () => {
expect(staged?.files?.[0]).toBe(staged?.file)
})
+ it('stages dropped folder images with their original filename', () => {
+ const dropped: ItemData = {
+ kind: 'image',
+ imageId: 'img_test_123',
+ width: 1920,
+ height: 1080,
+ bytes: 50000,
+ ext: 'jpg',
+ source: 'image',
+ fileName: 'holiday.jpg'
+ }
+ const staged = stageDragFile(dropped, timestamp)
+ expect(staged?.file).toMatch(/holiday\.jpg$/i)
+ expect(staged?.file).not.toContain('Screenshot')
+ })
+
+ it('stages copied photos as Image timestamp, not Screenshot', () => {
+ const copiedPhoto: ItemData = {
+ kind: 'image',
+ imageId: 'img_test_123',
+ width: 1920,
+ height: 1080,
+ bytes: 50000,
+ ext: 'png',
+ source: 'image'
+ }
+ const stagedPhoto = stageDragFile(copiedPhoto, timestamp)
+ expect(stagedPhoto?.file).toContain('Image 2026-08-15 22.30.45.png')
+ })
+
it('returns indexed filenames and files array for image-collection items', () => {
const collectionData: ItemData = {
kind: 'image-collection',
diff --git a/tests/snippingTool.test.ts b/tests/snippingTool.test.ts
index 1320cff..bcee3b4 100644
--- a/tests/snippingTool.test.ts
+++ b/tests/snippingTool.test.ts
@@ -69,6 +69,7 @@ describe('Windows Snipping Tool & Clipboard Image Detection (#41)', () => {
if (result?.kind === 'image') {
expect(result.width).toBe(1920)
expect(result.height).toBe(1080)
+ expect(result.source).toBe('screenshot')
}
const sig = clipboardSignature()
@@ -97,6 +98,7 @@ describe('Windows Snipping Tool & Clipboard Image Detection (#41)', () => {
if (result?.kind === 'image') {
expect(result.width).toBe(800)
expect(result.height).toBe(600)
+ expect(result.source).toBe('screenshot')
}
const sig = clipboardSignature()
@@ -122,6 +124,10 @@ describe('Windows Snipping Tool & Clipboard Image Detection (#41)', () => {
const result = await readClipboard()
expect(result).not.toBeNull()
expect(result?.kind).toBe('image')
+ if (result?.kind === 'image') {
+ expect(result.source).toBe('image')
+ expect(result.fileName).toBe('photo.png')
+ }
const sig = clipboardSignature()
expect(sig).toContain('image:400x300:')