Skip to content

fix: image-block 'Copy Image' and 'Show file in folder' context menu actions - #13552

Merged
tiensonqin merged 13 commits into
masterfrom
devin/1790842154-image-asset-menu-fixes
Oct 1, 2026
Merged

tiensonqin merged 13 commits into
masterfrom
devin/1790842154-image-asset-menu-fixes

Conversation

@RCmerci

@RCmerci RCmerci commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes the two no-op actions on image blocks in Electron — the native context-menu "Copy Image" and "Show file in folder" (asset action-bar ⋮ and block context menu) — plus local filesystem image paths that never rendered on desktop.

Issue 1 — "Copy Image" does nothing

Root cause: the Electron context-menu handler resolved the clicked image's srcURL with (subs (.-srcURL params) 7) — i.e. it assumed a bare file:///path and blindly stripped 7 characters — then called nativeImage.createFromPath. That breaks for URI-encoded paths (%20 in the graph dir), remote https:// images (strips https:/, leaving /host/path, a nonexistent local file), blob:/data: URLs, and Windows paths. createFromPath on a nonexistent path returns an empty NativeImage; writeImage silently writes nothing. assets:// URLs only worked by accident — the truncated //host/path happened to resolve as a POSIX absolute path on case-insensitive filesystems.

Fix: use webContents.copyImageAt(x, y) — Electron's built-in that copies the rendered bitmap at the click point, for any image source.

Also fixed the asset ⋮ "Copy image" item: for http(s) sources it called fs/read-file-raw on a URL (not a filesystem path) and failed silently. It now falls back to the same fetch/ClipboardItem path used on web, and copy failures surface a "Can't find file" toast instead of a console-only error.

Issue 2 — "Show file in folder" does nothing

Root causes:

  • The ⋮ item routed on the local? link flag: non-local? sources (file://, absolute /path, ~ paths) went to window.apis.openExternal, which throws for relative paths and rejects file: URLs as 'illegal protocol' — a silent no-op — while being mislabeled "Open image in browser" for a local file.
  • Missing/unresolved files made shell.showItemInFolder silently do nothing.
  • The block context-menu item hardcoded assets/<uuid>.<ext>, resolving to a wrong path for plugin-sourced and disk-based external-urls.

Fix: route on whether image-src is an http(s) URL (case-insensitive) — remote sources get "Open image in browser" via openExternal, everything else gets "Show file in folder" via openFileInFolder, gated by fs/file-exists? with a "Can't find file" toast. The block menu resolves plugin-sourced (assets/storages/<id>/...) paths from :logseq.property.asset/external-url, and absolute/file:// external-urls via path/absolute? + path/file-url-or-path->path. Still Electron-only ((when (util/electron?))) — hidden on web as before.

Local filesystem image paths didn't render on desktop (new)

![x](../../../Desktop/img.png), ![x](/abs/path.png), ![x](~/path.png) and ![x](file:///path.png) reached the <img> as raw hrefs and resolved against the app origin → 404 (localhost:3001 in dev, ERR_FILE_NOT_FOUND in release).

Fix: new assets/file-path->assets-url resolves a filesystem path to an assets:// URL — ~/ expands to home, file:///assets:// unwrap to the native path, absolute paths pass through, and .//..//bare relative paths resolve against the graph dir (real .. traversal). image-link uses it for non-asset hrefs on Electron, and <make-asset-url's Electron branch uses it for non-local-asset? paths. ../assets/x.png keeps the existing graph-assets convention; web behavior unchanged.

Review findings fixed here

  • path/url-to-path now decodes /logseq__colon/ → :/ (Windows assets:///C/logseq__colon/... → C:/...), matching setup-interceptor!'s main-process decode; unit test added.
  • Absolute-path/file:// external-url resolves to its native path for reveal.
  • http(s) scheme checks are case-insensitive.

Not fixed (deliberately): copying remote images served without CORS still fails — needs bytes fetched outside renderer CORS (main-process net.fetch IPC or rendered-bitmap capture); flagged on the PR for a maintainer decision.

Verification

Dev Electron app (Demo graph), recorded:

  • ![rel](../../../Desktop/img.png) → assets://users/devin/Desktop/img.png ✅ (previously 404); same for /abs, ~/, file:/// hrefs
  • Native "Copy Image" on remote https:// and local assets:// images → PNG on OS clipboard
  • ⋮ "Copy image" / "Show file in folder" on local and remote assets → "Copied!" toast / Finder reveal
  • Block-bullet "Show file in folder" → Finder reveal; External URL = absolute path → reveals the external file
  • Missing-file paths → "Can't find file …" toast instead of a silent no-op

bb dev:lint-and-test green (kondo 0 errors, unit tests pass).

Link to Devin session: https://app.devin.ai/sessions/f556148c6dd043c8a5d4ea58c0c0c6ed
Open in Devin Desktop: https://app.devin.ai/desktop/session/f556148c6dd043c8a5d4ea58c0c0c6ed?variant=devin
Requested by: @RCmerci


Devin Review

@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-01T08:19:59.609681Z 36ec3bc PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@devin-ai-integration devin-ai-integration Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin resolved all 3 findings on 8c83b5b

Fixed by Devin (3)

  • Inline non-file image actions fail
  • Uppercase HTTP images become local files
  • Root-relative published images lose their root

View all findings in Devin Review

Devin Review

devin-ai-integration[bot]

This comment was marked as resolved.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 36ec3bc984

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/main/frontend/components/block.cljs Outdated
Comment on lines +289 to +291
(if (and (util/electron?)
(seq image-src)
(not (string/starts-with? image-src "http")))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Propagate clipboard failures before reporting success

When an Electron HTTP(S) image takes this newly selected branch, copy-image-to-clipboard does not return a reliable completion promise: write-blob-to-clipboard catches rejected clipboard writes in frontend/util.cljc:1292-1311, and non-PNG conversion in image-blob->png returns before its callback writes anything. Consequently JPEG/WebP copies can report “Copied!” prematurely, and rejected PNG writes can still report success while leaving the clipboard unchanged. Make the helpers return a rejecting promise that spans conversion and the actual clipboard write.

AGENTS.md reference: AGENTS.md:L12-L15

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Real but pre-existing: copy-image-to-clipboard/copy-image-blob-to-clipboard already resolve before conversion + write complete on web too — this PR only routes Electron remote-src copies through the same helper, so the premature "Copied!" semantics are unchanged. Making the promise span conversion+write is a util-level change; happy to take it if you'd like it here, otherwise it fits better as a follow-up.

Comment on lines 315 to +317
(p/catch (fn [error]
(js/console.error error))))))
(js/console.error error)
(notification/show! (t :asset/missing-file image-src) :warning))))))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not report CORS copy failures as missing files

When a displayed remote image comes from a server without Access-Control-Allow-Origin, its <img> can render normally but the new renderer-side fetch in copy-image-to-clipboard is rejected because production Electron enables webSecurity. This catch then says “Can't find file ”, so the remote Copy action remains unusable for common cross-origin images and gives an unrelated diagnosis. Copy the already-rendered bitmap through an Electron-privileged path, or at least use a copy-specific failure message instead of the local missing-file translation.

AGENTS.md reference: AGENTS.md:L24-L25

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed the "Can't find file" message is misleading for a fetch rejection, and non-CORS remote images still can't be copied this way — same root limitation as the Devin Review finding on this branch. Fixing it properly needs bytes fetched outside renderer CORS (main-process net.fetch IPC or rendered-bitmap capture without click coordinates), which is a scope expansion — flagging for a maintainer decision rather than folding it in.

Comment thread src/main/frontend/components/block.cljs Resolved
@devin-ai-integration

Copy link
Copy Markdown
Contributor

E2E verification on dev Electron (Demo graph) — all passed

Tested both fixes through the real UI; clipboard checked via osascript -e 'clipboard info' after each action.

  • Native "Copy Image" on remote https image — the previously-broken path: clipboard now receives a 22KB PNG (verified empty→PNG transition). ✅
  • Native "Copy Image" on local asset — clipboard receives the PNG. ✅

native Copy Image on remote image

  • ⋮ "Copy image" → "Copied!" toast + PNG on clipboard ✅

Copied! toast

  • ⋮ "Show file in folder" → Finder opens assets/ with the PNG selected ✅
  • Block-bullet context menu → "Show file in folder" → same Finder reveal ✅

Finder reveal via block context menu

  • Missing file (asset moved to /tmp): both entry points now show a "Can't find file …" toast instead of silently doing nothing ✅

Can't find file toast

  • Remote-src asset (External URL set to an https URL): ⋮ shows "Open image in browser" (replacing "Show file in folder") and clicking it opened the URL in Safari ✅

Open image in browser

Additional notes

@devin-ai-integration

Copy link
Copy Markdown
Contributor

E2E re-verification on dev Electron (Demo graph) — all passed

Added sibling blocks on the journal page and checked each rendered image's resolved img.src:

  • ![rel](../../../Desktop/img.png) → assets://users/devin/Desktop/img.png ✅ (previously 404 against localhost:3001)
  • ![abs](https://app.devin.ai/api/presigned_proxy?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjpudWxsLCJidWNrZXRfbmFtZSI6ImRldmluYXR0YWNobWVudHMiLCJidWNrZXRfa2V5IjoiYXR0YWNobWVudHNfcHJpdmF0ZS9vcmctZjZmZDVmNzI0MzlkNDlmZmJmY2QxYWQ2NTMwNjdhZTMvYjA1NzMwOGItZjk0Yy00MjQxLThkM2QtODFlYjdjNDRiNGU5IiwiaWF0IjoxNzkwODU0NDE5LCJleHAiOjE3OTE0NTkyMTksIm9yZ19pZCI6Im9yZy1mNmZkNWY3MjQzOWQ0OWZmYmZjZDFhZDY1MzA2N2FlMyIsImZpbGVuYW1lIjoiaW1nLnBuZyJ9.GkBn5a8LkvyM5I6YKsOEIp8APzt3XjljlcpCRlxe5CE) → assets://users/devin/Desktop/img.png ✅
  • ![home](https://app.devin.ai/api/presigned_proxy?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjpudWxsLCJidWNrZXRfbmFtZSI6ImRldmluYXR0YWNobWVudHMiLCJidWNrZXRfa2V5IjoiYXR0YWNobWVudHNfcHJpdmF0ZS9vcmctZjZmZDVmNzI0MzlkNDlmZmJmY2QxYWQ2NTMwNjdhZTMvNGU1ZWQ1MTAtNGI3ZC00NjdkLWJjMmEtYzkzNDczNWRlZDEyIiwiaWF0IjoxNzkwODU0NDE5LCJleHAiOjE3OTE0NTkyMTksIm9yZ19pZCI6Im9yZy1mNmZkNWY3MjQzOWQ0OWZmYmZjZDFhZDY1MzA2N2FlMyIsImZpbGVuYW1lIjoiaW1nLnBuZyJ9.w-L9gdwt8uWHXySHvFhE10NeH3ggNNgSzbIv992YC_w) → assets://users/devin/Desktop/img.png ✅ (home expansion)
  • ![file](https://app.devin.ai/api/presigned_proxy?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjpudWxsLCJidWNrZXRfbmFtZSI6ImRldmluYXR0YWNobWVudHMiLCJidWNrZXRfa2V5IjoiYXR0YWNobWVudHNfcHJpdmF0ZS9vcmctZjZmZDVmNzI0MzlkNDlmZmJmY2QxYWQ2NTMwNjdhZTMvYjA1NzMwOGItZjk0Yy00MjQxLThkM2QtODFlYjdjNDRiNGU5IiwiaWF0IjoxNzkwODU0NDE5LCJleHAiOjE3OTE0NTkyMTksIm9yZ19pZCI6Im9yZy1mNmZkNWY3MjQzOWQ0OWZmYmZjZDFhZDY1MzA2N2FlMyIsImZpbGVuYW1lIjoiaW1nLnBuZyJ9.GkBn5a8LkvyM5I6YKsOEIp8APzt3XjljlcpCRlxe5CE) → renders as image, assets://users/devin/Desktop/img.png ✅
  • ![x](../assets/<uuid>.png) inline local asset link → still renders ✅ (regression)

all blocks rendered

  • Native right-click Copy Image on the assets://-rendered image → PNG on OS clipboard ✅
  • Asset ⋮ Copy image → "Copied!" toast + PNG; ⋮ Show file in folder → Finder reveal ✅
  • Block-bullet Show file in folder → Finder reveal ✅
Additional checks
  • Asset External URL = absolute path → block menu "Show file in folder" revealed ~/Desktop/img.png in Finder ✅ (new path/absolute? branch)

Finder reveals Desktop img.png

  • Renderer console: no image-load errors; only unrelated React dev warnings. Main log shows a pre-existing Unknown assets url WARN that also fires for the pasted asset which renders correctly.
  • Windows logseq__colon decode covered by unit test; not exercised in the macOS app.

Recording: /Users/devin/screencasts/pr13552-round2-local-path-images/pr13552-round2-local-path-images-edited.mp4

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@devin-ai-integration

Copy link
Copy Markdown
Contributor

E2E re-verification (round 3) — ⋮ action bar on inline images — all passed

  • Inline ![rel](../../../Desktop/img.png) (no asset entity) now shows the ⋮ action bar on Electron. Menu contains exactly "Copy image" + "Show file in folder" — Align submenu and Delete correctly remain asset-block-gated.

inline image menu

  • ⋮ "Copy image" → PNG on OS clipboard (file-read path) ✅
  • ⋮ "Show file in folder" → Finder reveals ~/Desktop/img.png ✅
  • Regression: pasted asset block keeps the full menu (Align ▸, Copy, Show file in folder, Delete) ✅
  • Remote inline https:// image gets ⋮ → Copy + "Open image in browser" (opens URL in browser) ✅
  • ![x](//devin/...) protocol-relative href passes through untouched (resolves as URL, not assets://) ✅
Notes
  • Console clean — only an expected ERR_FILE_NOT_FOUND probing the // passthrough.
  • Recording: /Users/devin/screencasts/pr13552-round3-final-inline-menu/pr13552-round3-final-inline-menu-edited.mp4

RCmerci and others added 13 commits October 1, 2026 20:17
The native right-click 'Copy Image' resolved the image srcURL with a raw 'subs 7' and nativeImage.createFromPath, which only works for bare POSIX file:/// URLs: any URI-encoded path (e.g. a graph directory containing spaces -> %20), https/blob/data srcURLs and Windows paths produced an empty image and silently wrote nothing to the clipboard. Use webContents.copyImageAt(x, y) instead, which copies the rendered image for any source.

Also fix the asset 'Copy image' action: for http(s) image sources read-file-raw is not a filesystem path and failed silently; fall back to the fetch/ClipboardItem path (same as web), and surface a 'Can't find file' toast instead of a console-only error when the local file is missing.
The image action-bar item routed on the 'local?' link flag: non-local sources (file://, absolute /path, ~ paths) were sent to shell.openExternal, which throws 'illegal protocol' for non-http(s) URLs and relative paths - a silent no-op, with a misleading 'Open image in browser' label for what is actually a local file. Route on whether the resolved image-src is an http(s) URL instead: remote sources open in the browser, everything else reveals via openFileInFolder, labeled 'Show file in folder'.

Both reveal entry points (image action bar and block context menu) also silently did nothing when the file was missing or the path was unresolved (missing download, plugin-sourced asset under assets/storages/<id>). Check the file exists first and show a 'Can't find file' toast; resolve plugin-sourced asset paths from the asset's external-url the same way the renderer does.
assets:// URLs protect a Windows drive colon as /logseq__colon/; the
renderer-side decoder in url-to-path never restored it, so the
resolved path stayed encoded instead of a native C:/ path.
The block menu resolved a non-local-relative external-url to the
block's uuid path, so an absolute path or file:// URL revealed a
non-existent file.
Local filesystem image hrefs resolved against the app origin and 404d.
Route ~/, file://, absolute, and graph-relative (./ ../ bare) paths
through assets:// URLs; bare http(s) URLs and web behavior unchanged.
URL schemes are case-insensitive; an uppercase HTTPS:// src was
misclassified as a local file path for copy and reveal.
Routing every non-asset href through assets:// on Electron mangled
uppercase HTTP:// links into graph paths, and reordering publishing
before the ~ / check stripped the root slash from published images.
Match the scheme case-insensitively and restore the leading ~ /
branch ahead of the publishing rewrite; Electron still resolves both
to assets:// URLs.
//host/path is a remote URL, not a filesystem path; the Electron
assets:// resolution was mangling it.
Inline ![](path) images have no asset entity, so the dots menu never
rendered. Show it on Electron whenever the image src resolves, and
keep Align/Delete gated on the asset entity.
data:/blob:// image-src values were sent down the filesystem copy
path and got a folder-reveal item that could never resolve. Treat
image-src as a file only when it has no scheme and no // prefix
(C:/ stays a Windows path, not a scheme), and hide the
reveal/browser item when neither applies.
assets://server/share unwraps to //server/share in image-src;
checking src for the // prefix keeps UNC files on the filesystem
path while raw //host hrefs still count as remote.
@tiensonqin
tiensonqin force-pushed the devin/1790842154-image-asset-menu-fixes branch from 3317684 to 8c83b5b Compare October 1, 2026 12:17
@tiensonqin
tiensonqin merged commit 8ffbb22 into master Oct 1, 2026
27 checks passed
@tiensonqin
tiensonqin deleted the devin/1790842154-image-asset-menu-fixes branch October 1, 2026 12:18
devin-ai-integration Bot pushed a commit that referenced this pull request Oct 8, 2026
…actions (#13552)

* fix: 'Copy Image' context menu action

The native right-click 'Copy Image' resolved the image srcURL with a raw 'subs 7' and nativeImage.createFromPath, which only works for bare POSIX file:/// URLs: any URI-encoded path (e.g. a graph directory containing spaces -> %20), https/blob/data srcURLs and Windows paths produced an empty image and silently wrote nothing to the clipboard. Use webContents.copyImageAt(x, y) instead, which copies the rendered image for any source.

Also fix the asset 'Copy image' action: for http(s) image sources read-file-raw is not a filesystem path and failed silently; fall back to the fetch/ClipboardItem path (same as web), and surface a 'Can't find file' toast instead of a console-only error when the local file is missing.

* fix: 'Show file in folder' context menu actions

The image action-bar item routed on the 'local?' link flag: non-local sources (file://, absolute /path, ~ paths) were sent to shell.openExternal, which throws 'illegal protocol' for non-http(s) URLs and relative paths - a silent no-op, with a misleading 'Open image in browser' label for what is actually a local file. Route on whether the resolved image-src is an http(s) URL instead: remote sources open in the browser, everything else reveals via openFileInFolder, labeled 'Show file in folder'.

Both reveal entry points (image action bar and block context menu) also silently did nothing when the file was missing or the path was unresolved (missing download, plugin-sourced asset under assets/storages/<id>). Check the file exists first and show a 'Can't find file' toast; resolve plugin-sourced asset paths from the asset's external-url the same way the renderer does.

* fix: decode protected Windows drive colon in url-to-path

assets:// URLs protect a Windows drive colon as /logseq__colon/; the
renderer-side decoder in url-to-path never restored it, so the
resolved path stayed encoded instead of a native C:/ path.

* fix: reveal absolute-path external-url in folder

The block menu resolved a non-local-relative external-url to the
block's uuid path, so an absolute path or file:// URL revealed a
non-existent file.

* fix: render local filesystem image paths on Electron

Local filesystem image hrefs resolved against the app origin and 404d.
Route ~/, file://, absolute, and graph-relative (./ ../ bare) paths
through assets:// URLs; bare http(s) URLs and web behavior unchanged.

* fix: match http image sources case-insensitively

URL schemes are case-insensitive; an uppercase HTTPS:// src was
misclassified as a local file path for copy and reveal.

* fix: keep http and root-relative image links in image-link

Routing every non-asset href through assets:// on Electron mangled
uppercase HTTP:// links into graph paths, and reordering publishing
before the ~ / check stripped the root slash from published images.
Match the scheme case-insensitively and restore the leading ~ /
branch ahead of the publishing rewrite; Electron still resolves both
to assets:// URLs.

* fix: pass protocol-relative image links through unchanged

//host/path is a remote URL, not a filesystem path; the Electron
assets:// resolution was mangling it.

* feat: show asset action bar on inline images in Electron

Inline ![](path) images have no asset entity, so the dots menu never
rendered. Show it on Electron whenever the image src resolves, and
keep Align/Delete gated on the asset entity.

* fix: classify inline image actions by URL scheme

data:/blob:// image-src values were sent down the filesystem copy
path and got a folder-reveal item that could never resolve. Treat
image-src as a file only when it has no scheme and no // prefix
(C:/ stays a Windows path, not a scheme), and hide the
reveal/browser item when neither applies.

* fix: close added when/let around image menu reveal item

* add external assets comment

* fix: classify // by original src, keeping UNC paths as files

assets://server/share unwraps to //server/share in image-src;
checking src for the // prefix keeps UNC files on the filesystem
path while raw //host hrefs still count as remote.

---------

Co-authored-by: Tienson Qin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants