Improve drag & drop image inlining functionality#244
Merged
Conversation
- Support multiple image formats: JPEG, PNG, GIF, WebP - Detect actual file type and use correct MIME type in data URLs - Process all dropped image files, not just the first one - Use insertText:replacementRange: for proper undo support - Update to modern APIs (NSPasteboardTypeFileURL, base64EncodedStringWithOptions:) - Add proper filtering in draggingEntered: to only accept supported images - Fall back to default NSTextView behavior for non-image files Related to #243
- Fix error handling: check if fileData is nil instead of checking error parameter (dataWithContentsOfFile:options:error: may not always set error) - Fix fallback behavior in draggingEntered: call super instead of returning NSDragOperationNone to allow default NSTextView handling for non-images Related to #243
Contributor
Code Coverage ReportCurrent Coverage: 51.47% Coverage Details (Summary) |
Tests for MPEditorView's private helper methods: - imageUTIForFilePath: tests for PNG, JPEG, GIF, WebP extensions - mimeTypeForUTI: tests for UTI to MIME type mapping - Round-trip tests (file path -> UTI -> MIME type) - Edge cases: uppercase extensions, unsupported types, nil/empty inputs Uses Testing category pattern to expose private methods for testing. Related to #243
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves the drag & drop image inlining feature in the editor:
insertText:replacementRange:for proper undo/redo functionalityNSFilenamesPboardType/base64EncodingtoNSPasteboardTypeFileURL/base64EncodedStringWithOptions:draggingEntered:now correctly filters for supported image typesRelated Issue
Related to #243
Changes
File:
MacDown/Code/View/MPEditorView.m<CoreServices/CoreServices.h>for UTI functionsawakeFromNibNSPasteboardTypeFileURLinstead of undefinedNSDragPboarddraggingEntered:performDragOperation:imageUTIForFilePath:mimeTypeForUTI:Manual Testing Plan
Basic Functionality
Undo/Redo
Edge Cases
Review Notes
draggingEntered: