Repository navigation
fix: image-block 'Copy Image' and 'Show file in folder' context menu actions - #13552
Conversation
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
✅ 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
There was a problem hiding this comment.
💡 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".
| (if (and (util/electron?) | ||
| (seq image-src) | ||
| (not (string/starts-with? image-src "http"))) |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
| (p/catch (fn [error] | ||
| (js/console.error error)))))) | ||
| (js/console.error error) | ||
| (notification/show! (t :asset/missing-file image-src) :warning)))))) |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
|
E2E verification on dev Electron (Demo graph) — all passed Tested both fixes through the real UI; clipboard checked via
Additional notes
|
|
E2E re-verification on dev Electron (Demo graph) — all passed Added sibling blocks on the journal page and checked each rendered image's resolved
Additional checks
Recording: |
|
E2E re-verification (round 3) — ⋮ action bar on inline images — all passed
Notes
|
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  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.
3317684 to
8c83b5b
Compare
…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  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]>
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
srcURLwith(subs (.-srcURL params) 7)— i.e. it assumed a barefile:///pathand blindly stripped 7 characters — then callednativeImage.createFromPath. That breaks for URI-encoded paths (%20in the graph dir), remotehttps://images (stripshttps:/, leaving/host/path, a nonexistent local file),blob:/data:URLs, and Windows paths.createFromPathon a nonexistent path returns an emptyNativeImage;writeImagesilently writes nothing.assets://URLs only worked by accident — the truncated//host/pathhappened 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-rawon a URL (not a filesystem path) and failed silently. It now falls back to the same fetch/ClipboardItempath 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:
local?link flag: non-local?sources (file://, absolute/path,~paths) went towindow.apis.openExternal, which throws for relative paths and rejectsfile:URLs as 'illegal protocol' — a silent no-op — while being mislabeled "Open image in browser" for a local file.shell.showItemInFoldersilently do nothing.assets/<uuid>.<ext>, resolving to a wrong path for plugin-sourced and disk-basedexternal-urls.Fix: route on whether
image-srcis anhttp(s)URL (case-insensitive) — remote sources get "Open image in browser" viaopenExternal, everything else gets "Show file in folder" viaopenFileInFolder, gated byfs/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 viapath/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)
,,andreached the<img>as raw hrefs and resolved against the app origin → 404 (localhost:3001 in dev,ERR_FILE_NOT_FOUNDin release).Fix: new
assets/file-path->assets-urlresolves a filesystem path to anassets://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-linkuses it for non-asset hrefs on Electron, and<make-asset-url's Electron branch uses it for non-local-asset?paths.../assets/x.pngkeeps the existing graph-assets convention; web behavior unchanged.Review findings fixed here
path/url-to-pathnow decodes/logseq__colon/→:/(Windowsassets:///C/logseq__colon/...→C:/...), matchingsetup-interceptor!'s main-process decode; unit test added.file://external-urlresolves 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.fetchIPC or rendered-bitmap capture); flagged on the PR for a maintainer decision.Verification
Dev Electron app (Demo graph), recorded:
→assets://users/devin/Desktop/img.png✅ (previously 404); same for/abs,~/,file:///hrefshttps://and localassets://images → PNG on OS clipboardbb dev:lint-and-testgreen (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