Skip to content

fix(desktop): return relative image path for local-path-string inserts - #4492

Merged
Jocs merged 1 commit into
developfrom
fix/relative-image-path-string-branch
Jun 14, 2026
Merged

Jocs merged 1 commit into
developfrom
fix/relative-image-path-string-branch

Conversation

@Jocs

@Jocs Jocs commented Jun 14, 2026

Copy link
Copy Markdown
Member

Problem

With Insert action = Folder + Prefer relative directory enabled (imageRelativeDirectoryName='assets', base = file), inserting an image via Format → Image with a typed or picked local path did not produce a relative reference. The image was copied into the assets/ folder, but the inserted markdown used an absolute path, ignoring the "prefer relative directory" preference.

Root cause

In packages/desktop/src/renderer/src/util/fileSystem.ts, moveImageToFolder only applied the isRelative → path.relative() conversion in the binary File branch. A local path string (Format → Image) hits the isPath branch, which returned the absolute hashFilePath/imagePath regardless of isRelative.

This is the persistence half of the Phase-G relative-path image work (#4428); the two new code paths (persist-as-relative and render-relative) must stay consistent, and the path-string persistence half was the gap.

Fix

Extract a toResult() helper and apply it to both branches so path-string inserts persist the portable relative reference too.

Testing

  • New test/unit/specs/move-image-to-folder.spec.ts: asserts the File branch returns a relative path (already passing) and the path-string branch both copies into assets/ and returns a relative path (failing before the fix, passing after).
  • Full unit suite: 467/467 pass. typecheck and eslint clean.

Note: this covers the persistence half. The render half (muya getImageSrc/resolveRelativePath anchoring on window.DIRNAME) is GUI-dependent and not exercised here — manual verification of end-to-end display is recommended.

🤖 Generated with Claude Code

moveImageToFolder only applied the isRelative -> path.relative()
conversion in the binary File branch. Inserting an image via a local
path string (Format -> Image with a typed/picked path) hit the isPath
branch, which copied the file into the relative assets dir but returned
an absolute path, so the inserted markdown ignored the
"prefer relative directory" preference.

Extract a toResult() helper and apply it to both branches so path-string
inserts persist the portable relative reference too.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@Jocs
Jocs merged commit ba261e6 into develop Jun 14, 2026
8 of 9 checks passed
@Jocs
Jocs deleted the fix/relative-image-path-string-branch branch June 14, 2026 05:45
@github-actions

Copy link
Copy Markdown
Contributor

Build artifacts for PR #4492:

Run: https://github.com/marktext/marktext/actions/runs/27489753774

Artifact Size Link
marktext-windows-arm64 256.5 MB Download
marktext-macos-x64 257.1 MB Download
marktext-linux 556.5 MB Download
marktext-windows-x64 257.8 MB Download
marktext-macos-arm64 246.8 MB Download

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.

1 participant