1
0
mirror of https://github.com/mastodon/mastodon-ios.git synced 2024-12-22 22:28:35 +01:00

Merge pull request #486 from NanoSector/feature/385-paste-from-clipboard

feat: handle paste event and insert images on the clipboard
This commit is contained in:
CMK 2022-11-13 22:46:20 +08:00 committed by GitHub
commit b1f03d397c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 0 deletions

View File

@ -87,6 +87,7 @@
62FD27D32893707B00B205C5 /* BookmarkViewController+DataSourceProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62FD27D22893707B00B205C5 /* BookmarkViewController+DataSourceProvider.swift */; };
62FD27D52893708A00B205C5 /* BookmarkViewModel+Diffable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62FD27D42893708A00B205C5 /* BookmarkViewModel+Diffable.swift */; };
87FFDA5D898A5C42ADCB35E7 /* Pods_Mastodon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A4ABE34829701A4496C5BB64 /* Pods_Mastodon.framework */; };
CD91FB31290EDA6F00BB9463 /* MetaTextView+PasteExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD91FB30290EDA6F00BB9463 /* MetaTextView+PasteExtensions.swift */; };
DB0009A626AEE5DC009B9D2D /* Intents.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = DB0009A926AEE5DC009B9D2D /* Intents.intentdefinition */; settings = {ATTRIBUTES = (codegen, ); }; };
DB0009A726AEE5DC009B9D2D /* Intents.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = DB0009A926AEE5DC009B9D2D /* Intents.intentdefinition */; };
DB0140CF25C42AEE00F9F3CF /* OSLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB0140CE25C42AEE00F9F3CF /* OSLog.swift */; };
@ -604,6 +605,7 @@
BB482D32A7B9825BF5327C4F /* Pods-Mastodon-MastodonUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Mastodon-MastodonUITests.release.xcconfig"; path = "Target Support Files/Pods-Mastodon-MastodonUITests/Pods-Mastodon-MastodonUITests.release.xcconfig"; sourceTree = "<group>"; };
BD7598A87F4497045EDEF252 /* Pods-Mastodon.asdk - release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Mastodon.asdk - release.xcconfig"; path = "Target Support Files/Pods-Mastodon/Pods-Mastodon.asdk - release.xcconfig"; sourceTree = "<group>"; };
C3789232A52F43529CA67E95 /* Pods-MastodonIntent.asdk - debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MastodonIntent.asdk - debug.xcconfig"; path = "Target Support Files/Pods-MastodonIntent/Pods-MastodonIntent.asdk - debug.xcconfig"; sourceTree = "<group>"; };
CD91FB30290EDA6F00BB9463 /* MetaTextView+PasteExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MetaTextView+PasteExtensions.swift"; sourceTree = "<group>"; };
CD92E0F10BDE4FE7C4B999F2 /* Pods_MastodonTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_MastodonTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
D7D7CF93E262178800077512 /* Pods-Mastodon-AppShared.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Mastodon-AppShared.debug.xcconfig"; path = "Target Support Files/Pods-Mastodon-AppShared/Pods-Mastodon-AppShared.debug.xcconfig"; sourceTree = "<group>"; };
DB0009A826AEE5DC009B9D2D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.intentdefinition; name = Base; path = Base.lproj/Intents.intentdefinition; sourceTree = "<group>"; };
@ -1865,6 +1867,7 @@
DB8190C52601FF0400020C08 /* AttachmentContainerView.swift */,
DB9A486B26032AC1008B817C /* AttachmentContainerView+EmptyStateView.swift */,
DBC7A671260C897100E57475 /* StatusContentWarningEditorView.swift */,
CD91FB30290EDA6F00BB9463 /* MetaTextView+PasteExtensions.swift */,
);
path = View;
sourceTree = "<group>";
@ -3293,6 +3296,7 @@
2D84350525FF858100EECE90 /* UIScrollView.swift in Sources */,
6213AF5A28939C8400BCADB6 /* BookmarkViewModel.swift in Sources */,
5B24BBDB262DB14800A9381B /* ReportStatusViewModel+Diffable.swift in Sources */,
CD91FB31290EDA6F00BB9463 /* MetaTextView+PasteExtensions.swift in Sources */,
DB4F0968269ED8AD00D62E92 /* SearchHistoryTableHeaderView.swift in Sources */,
0FB3D2FE25E4CB6400AAD544 /* OnboardingHeadlineTableViewCell.swift in Sources */,
5DA732CC2629CEF500A92342 /* UIView+Remove.swift in Sources */,

View File

@ -455,3 +455,33 @@ extension ComposeViewController: UIAdaptivePresentationControllerDelegate {
// }
//
//}
extension ComposeViewController {
public override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
// Enable pasting images
if (action == #selector(UIResponderStandardEditActions.paste(_:))) {
return UIPasteboard.general.hasStrings || UIPasteboard.general.hasImages;
}
return super.canPerformAction(action, withSender: sender);
}
override func paste(_ sender: Any?) {
logger.debug("Paste event received")
// Look for images on the clipboard
if (UIPasteboard.general.hasImages) {
if let images = UIPasteboard.general.images {
logger.warning("Got image paste event, however attachments are not yet re-implemented.");
// viewModel.attachmentServices = viewModel.attachmentServices + images.map({ image in
// MastodonAttachmentService(
// context: context,
// image: image,
// initialAuthenticationBox: viewModel.authenticationBox
// )
// })
}
}
}
}

View File

@ -0,0 +1,29 @@
//
// MetaTextView+PasteExtensions.swift
// Mastodon
//
// Created by Rick Kerkhof on 30/10/2022.
//
import Foundation
import MetaTextKit
import UIKit
extension MetaTextView {
public override func paste(_ sender: Any?) {
super.paste(sender)
var nextResponder = self.next;
// Force the event to bubble through ALL responders
// This is a workaround as somewhere down the chain the paste event gets eaten
while (nextResponder != nil) {
if let nextResponder = nextResponder {
if (nextResponder.responds(to: #selector(UIResponderStandardEditActions.paste(_:)))) {
nextResponder.perform(#selector(UIResponderStandardEditActions.paste(_:)), with: sender)
}
}
nextResponder = nextResponder?.next;
}
}
}