Skip to content

Allow opening files start with ../#86

Merged
cyanzhong merged 7 commits intomainfrom
copilot/fix-relative-links-handling
Mar 29, 2026
Merged

Allow opening files start with ../#86
cyanzhong merged 7 commits intomainfrom
copilot/fix-relative-links-handling

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 29, 2026

Links starting with ../ like [Title](../assets/image.png) resolve against http://localhost/ in preview mode, so .. segments are silently dropped and clicks become no-ops.

  • src/view.ts: Click event delegation on the preview pane intercepts <a> clicks whose href starts with ../, resolves against MarkEdit.getFileInfo().parentPath, and opens via MarkEdit.openFile()

The handler uses getAttribute('href') (not .href) to preserve the raw relative path, and only calls preventDefault() and stopPropagation() after confirming a valid parent path is available — so the browser default still applies when the native API isn't present or returns no valid path. The scope is intentionally limited to ../ links only.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI linked an issue Mar 29, 2026 that may be closed by this pull request
Add isRelativePath() utility to detect relative URLs and click event
delegation on preview pane to intercept relative link clicks, resolve
them against the current file's parent path, and open via
MarkEdit.openFile(). Includes 13 new tests for isRelativePath().

Agent-Logs-Url: https://github.com/MarkEdit-app/MarkEdit-preview/sessions/d166ad61-577f-4c71-a7e5-d62f97cab8f6

Co-authored-by: cyanzhong <6745066+cyanzhong@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix handling of relative links outside root in preview mode Handle relative links in preview mode via native file API Mar 29, 2026
Copilot AI requested a review from cyanzhong March 29, 2026 01:31
@cyanzhong
Copy link
Copy Markdown
Contributor

@copilot I haven't yet checked the details, can you make sure your change only applies to links start with "../".

Per maintainer feedback, restrict the click interception to links
starting with "../" only. Remove the now-unnecessary isRelativePath()
utility and its test file.

Agent-Logs-Url: https://github.com/MarkEdit-app/MarkEdit-preview/sessions/bf2367cc-cfbf-4aab-8991-df30b8f2a973

Co-authored-by: cyanzhong <6745066+cyanzhong@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 29, 2026

@copilot I haven't yet checked the details, can you make sure your change only applies to links start with "../".

Updated in d41be5f — the click handler now only intercepts links starting with ../. Removed the broader isRelativePath() utility and its tests since they're no longer needed.

Copilot AI changed the title Handle relative links in preview mode via native file API Handle ../ relative links in preview mode via native file API Mar 29, 2026
src/view.ts Outdated
return;
}

event.preventDefault();
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.

@copilot Should we call stop propagation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added event.stopPropagation() alongside preventDefault() in ec61398.

Copilot AI requested a review from cyanzhong March 29, 2026 01:50
Copilot AI requested a review from cyanzhong March 29, 2026 01:53
Co-authored-by: George Politis <georgios.politis@icloud.com>
@cyanzhong cyanzhong changed the title Handle ../ relative links in preview mode via native file API Allow opening files start with ../ Mar 29, 2026
@cyanzhong cyanzhong marked this pull request as ready for review March 29, 2026 04:29
@cyanzhong cyanzhong requested review from Copilot and removed request for cyanzhong March 29, 2026 04:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts preview-mode link handling so relative links that start with ../ open the corresponding file via MarkEdit’s native file APIs instead of being resolved against http://localhost/.

Changes:

  • Import joinPaths and add preview-pane click delegation for ../ links in setUp().
  • Add handleExternalFiles() to resolve ../ hrefs against MarkEdit.getFileInfo().parentPath and open via MarkEdit.openFile().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@cyanzhong cyanzhong force-pushed the copilot/fix-relative-links-handling branch 3 times, most recently from 24a8b65 to 27d658d Compare March 29, 2026 05:04
@cyanzhong cyanzhong requested a review from Copilot March 29, 2026 05:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@cyanzhong cyanzhong force-pushed the copilot/fix-relative-links-handling branch from 27d658d to b9fd3ab Compare March 29, 2026 05:22
@cyanzhong cyanzhong merged commit 9e3574c into main Mar 29, 2026
1 check passed
@cyanzhong cyanzhong deleted the copilot/fix-relative-links-handling branch March 29, 2026 05:24
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.

Relative links outside "root"

4 participants