Skip to content

Address issue #222: Smart paste linkification for selected text#223

Merged
schuyler merged 1 commit intomainfrom
claude/resolve-issue-222-QBdDX
Dec 21, 2025
Merged

Address issue #222: Smart paste linkification for selected text#223
schuyler merged 1 commit intomainfrom
claude/resolve-issue-222-QBdDX

Conversation

@schuyler
Copy link
Copy Markdown
Owner

Summary

When text is selected in the editor and an http(s) URL is pasted, the selected text is now wrapped in Markdown link format [selected text](pasted-url) instead of being replaced by the URL.

This matches the behavior of VS Code, Obsidian plugins, and other Markdown editors.

Changes

  • Override paste: action in MPEditorView
  • Check for text selection and valid http/https URL in clipboard
  • Create [selected text](url) using insertText:replacementRange:
  • Fall back to normal paste behavior for all other cases

Related Issue

Related to #222

Manual Testing Plan

Core Scenarios

  1. Basic linkification: Select text, paste http/https URL → [text](url)
  2. HTTP and HTTPS: Both schemes work
  3. Complex URLs: Paths, queries, fragments preserved
  4. Multi-line selection: Works correctly
  5. Markdown formatting: Preserved in selected text (e.g., [**bold**](url))
  6. Selected text is URL: Still linkifies

Edge Cases (should NOT linkify)

  • No text selected → normal paste
  • Non-URL content pasted → normal paste
  • file:// URLs → normal paste
  • ftp:// or other schemes → normal paste
  • Malformed URLs → normal paste

Undo/Redo

  • Single Cmd+Z reverts entire linkification
  • Cmd+Shift+Z restores linkification

Regression

  • Normal paste without selection still works
  • Copy/Cut operations unaffected

Review Notes

  • Architecture: Override paste: in NSTextView subclass (recommended by Groucho)
  • Code quality: Reviewed by Chico - ready to merge, no blocking issues
  • Documentation: Reviewed by Harpo - no updates needed

When text is selected and an http(s) URL is pasted, the selected text
is now wrapped in Markdown link format [selected text](pasted url)
instead of being replaced by the URL.

- Override paste: action in MPEditorView
- Check for text selection and valid http/https URL in clipboard
- Fall back to normal paste behavior for other cases
- Undo works as single operation (NSTextView handles this automatically)

Related to #222
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 21, 2025

Code Coverage Report

Current Coverage: 42.52%

Coverage Details (Summary)
Name                                                                                                                                   Coverage            
-------------------------------------------------------------------------------------------------------------------------------------- ------------------- 
MASPreferences.bundle                                                                                                                  0.00% (0/0)         
MacDown 3000.app                                                                                                                       54.57% (6801/12463) 
    /Users/runner/work/macdown3000/macdown3000/MacDown/Code/Preferences/MPHtmlPreferencesViewController.m                              0.00% (0/87)        
        MPPrismDefaultThemeName                                                                                                        0.00% (0/2)         
        -[MPHtmlPreferencesViewController viewIdentifier]                                                                              0.00% (0/3)         
        -[MPHtmlPreferencesViewController toolbarItemImage]                                                                            0.00% (0/3)         
        -[MPHtmlPreferencesViewController toolbarItemLabel]                                                                            0.00% (0/2)         
        -[MPHtmlPreferencesViewController viewWillAppear]                                                                              0.00% (0/4)         
        -[MPHtmlPreferencesViewController changeStylesheet:]                                                                           0.00% (0/7)         
        -[MPHtmlPreferencesViewController changeHighlightingTheme:]                                                                    0.00% (0/7)         
        -[MPHtmlPreferencesViewController invokeStylesheetFunction:]                                                                   0.00% (0/23)        
        -[MPHtmlPreferencesViewController loadStylesheets]                                                                             0.00% (0/13)        
        -[MPHtmlPreferencesViewController loadHighlightingThemes]                                                                      0.00% (0/23)        
    /Users/runner/work/macdown3000/macdown3000/MacDown/Code/Extension/DOMNode+Text.m                                                   0.00% (0/94)        
        -[NSString(WordCount) numberOfWords]                                                                                           0.00% (0/11)        
        __36-[NSString(WordCount) numberOfWords]_block_invoke                                                                          0.00% (0/3)         
        -[NSString(WordCount) lengthWithoutNewlines]                                                                                   0.00% (0/11)        
        __44-[NSString(WordCount) lengthWithoutNewlines]_block_invoke                                                                  0.00% (0/3)         
        -[NSString(WordCount) lengthWithoutWhitespacesAndNewlines]                                                                     0.00% (0/11)        
        __58-[NSString(WordCount) lengthWithoutWhitespacesAndNewlines]_block_invoke                                                    0.00% (0/3)         
        MPGetChildrenNodetextCount                                                                                                     0.00% (0/6)         
        MPGetNodeTextCount                                                                                                             0.00% (0/38)        
        -[DOMNode(Text) textCount]                                                                                                     0.00% (0/8)         
    /Users/runner/work/macdown3000/macdown3000/Dependency/peg-markdown-highlight/HGMarkdownHighlightingStyle.m                         87.69% (57/65)      
        +[HGMarkdownHighlightingStyle colorFromARGBColor:]                                                                             100.00% (6/6)       
        -[HGMarkdownHighlightingStyle initWithType:attributesToAdd:toRemove:fontTraitsToAdd:]                                          88.89% (8/9)        
        -[HGMarkdownHighlightingStyle initWithStyleAttributes:baseFont:]                                                               86.00% (43/50)      
    /Users/runner/work/macdown3000/macdown3000/MacDown/Code/Extension/hoedown_html_patch.c                                             73.64% (95/129)     
        hoedown_patch_render_blockcode                                                                                                 89.09% (49/55)      
        hoedown_patch_render_listitem                                                                                                  100.00% (46/46)     
        hoedown_patch_render_toc_header                                                                                                0.00% (0/28)        
    /Users/runner/work/macdown3000/macdown3000/MacDown/Code/Application/MPMainController.m                                             40.76% (97/238)     
        MPOpenBundledFile                                                                                                              95.24% (20/21)      
        __MPOpenBundledFile_block_invoke                                                                                               85.71% (6/7)        
        treat                                                                                                                          20.00% (6/30)       
        __treat_block_invoke                                                                                                           0.00% (0/3)         
        -[MPMainController applicationDidFinishLaunching:]                                                                             100.00% (6/6)       
        -[MPMainController openUrlSchemeAppleEvent:withReplyEvent:]                                                                    0.00% (0/45)        
        __59-[MPMainController openUrlSchemeAppleEvent:withReplyEvent:]_block_invoke                                                   0.00% (0/7)         
        -[MPMainController valueForKey:fromQueryItems:]                                                                                0.00% (0/5)         
        -[MPMainController preferences]                                                                                                100.00% (3/3)       
        -[MPMainController preferencesWindowController]                                                                                0.00% (0/18)        
        -[MPMainController showPreferencesWindow:]                                                                                     0.00% (0/2)         
        -[MPMainController showHelp:]                                                                                                  100.00% (3/3)       
        -[MPMainController showContributing:]                                                                                          100.00% (3/3)       
        -[MPMainController init]                                                                                                       90.91% (10/11)      
        -[MPMainController applicationShouldOpenUntitledFile:]                                                                         80.00% (4/5)        
        -[MPMainController applicationDidBecomeActive:]                                                                                100.00% (5/5)       

... (2115 more lines truncated)

📊 **Full coverage report available in workflow artifacts**

@schuyler
Copy link
Copy Markdown
Owner Author

Tested locally, works great.

@schuyler schuyler merged commit b38afec into main Dec 21, 2025
5 checks passed
@schuyler schuyler deleted the claude/resolve-issue-222-QBdDX branch December 21, 2025 07:08
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