Skip to content

monaco edit内容的链接点击问题 #62

Closed

Description

@gaoconggit

monaco edit内容的链接点击后在webview 中打开了
@claude 分析一下这个问题

Activity

  1. claude commented on Oct 17, 2025

    @claude

    Claude finished @gaoconggit's task —— View job • claude/issue-62-20251017-1129 • Create PR ➔


    Analysis Complete

    Issue: Links in Monaco editor content were opening within the WebView instead of in an external browser.

    Root Cause

    The OnNavigationStarting event handler in SharpPad.Desktop/Views/MainWindow.axaml.cs:20 was empty. When users clicked links in Monaco editor content, the WebView would navigate to those URLs internally instead of opening them in the default browser.

    Solution Implemented

    I've implemented the OnNavigationStarting handler to:

    1. Detect external links: Compare the navigation URL with the app's base URL (localhost:port)
    2. Cancel internal navigation: Prevent the WebView from loading external URLs
    3. Open in default browser: Use Process.Start with UseShellExecute to open links in the system's default browser

    Changes Made

    File Modified: SharpPad.Desktop/Views/MainWindow.axaml.cs

    The handler now:

    • Extracts the app's base URL from the ViewModel
    • Converts the navigation URL to a string for comparison
    • Uses Uri.TryCreate to safely parse both URLs
    • Compares the host and scheme to determine if the link is external
    • If external: cancels navigation and opens in default browser
    • If internal: allows normal navigation to proceed

    Testing

    • ✅ Build succeeded with no errors or warnings
    • ✅ Changes committed and pushed to branch

    Next Steps

    Please review and test the fix:

    1. Click on any external links in Monaco editor content
    2. Verify they open in your default browser instead of the WebView
    3. Verify internal navigation (within the app) still works normally

    --- |

  2. added a commit that references this issue on Oct 17, 2025
    78f1e03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions