mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
[WIP] Quotes
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
|
||||
objc_library(
|
||||
name = "ChatInputTextViewImpl",
|
||||
enable_modules = True,
|
||||
module_name = "ChatInputTextViewImpl",
|
||||
srcs = glob([
|
||||
"Sources/**/*.m",
|
||||
"Sources/**/*.c",
|
||||
"Sources/**/*.h",
|
||||
]),
|
||||
hdrs = glob([
|
||||
"PublicHeaders/**/*.h",
|
||||
]),
|
||||
includes = [
|
||||
"PublicHeaders",
|
||||
],
|
||||
sdk_frameworks = [
|
||||
"Foundation",
|
||||
],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
],
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef ChatInputTextViewImpl_h
|
||||
#define ChatInputTextViewImpl_h
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface ChatInputTextViewImplTargetForAction: NSObject
|
||||
|
||||
@property (nonatomic, strong, readonly) id _Nullable target;
|
||||
|
||||
- (instancetype _Nonnull)initWithTarget:(id _Nullable)target;
|
||||
|
||||
@end
|
||||
|
||||
@interface ChatInputTextViewImpl : UITextView
|
||||
|
||||
@property (nonatomic, copy) bool (^ _Nullable shouldCopy)();
|
||||
@property (nonatomic, copy) bool (^ _Nullable shouldPaste)();
|
||||
@property (nonatomic, copy) ChatInputTextViewImplTargetForAction * _Nullable (^ _Nullable targetForActionImpl)(SEL _Nullable);
|
||||
@property (nonatomic, copy) bool (^ _Nullable shouldReturn)();
|
||||
@property (nonatomic, copy) void (^ _Nullable backspaceWhileEmpty)();
|
||||
|
||||
@end
|
||||
|
||||
#endif /* Lottie_h */
|
||||
@@ -0,0 +1,100 @@
|
||||
#import <ChatInputTextViewImpl/ChatInputTextViewImpl.h>
|
||||
|
||||
@implementation ChatInputTextViewImplTargetForAction
|
||||
|
||||
- (instancetype)initWithTarget:(id _Nullable)target {
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_target = target;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation ChatInputTextViewImpl
|
||||
|
||||
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
|
||||
{
|
||||
if (_targetForActionImpl) {
|
||||
ChatInputTextViewImplTargetForAction *result = _targetForActionImpl(action);
|
||||
if (result) {
|
||||
return result.target != nil;
|
||||
}
|
||||
}
|
||||
|
||||
if (action == @selector(paste:)) {
|
||||
NSArray *items = [UIMenuController sharedMenuController].menuItems;
|
||||
if (((UIMenuItem *)items.firstObject).action == @selector(toggleBoldface:)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wundeclared-selector"
|
||||
static SEL promptForReplaceSelector;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
promptForReplaceSelector = NSSelectorFromString(@"_promptForReplace:");
|
||||
});
|
||||
if (action == promptForReplaceSelector) {
|
||||
return false;
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
if (action == @selector(toggleUnderline:)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return [super canPerformAction:action withSender:sender];
|
||||
}
|
||||
|
||||
- (id)targetForAction:(SEL)action withSender:(id)__unused sender
|
||||
{
|
||||
if (_targetForActionImpl) {
|
||||
ChatInputTextViewImplTargetForAction *result = _targetForActionImpl(action);
|
||||
if (result) {
|
||||
return result.target;
|
||||
}
|
||||
}
|
||||
return [super targetForAction:action withSender:sender];
|
||||
}
|
||||
|
||||
- (void)copy:(id)sender {
|
||||
if (_shouldCopy == nil || _shouldCopy()) {
|
||||
[super copy:sender];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)paste:(id)sender
|
||||
{
|
||||
if (_shouldPaste == nil || _shouldPaste()) {
|
||||
[super paste:sender];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSArray *)keyCommands {
|
||||
UIKeyCommand *plainReturn = [UIKeyCommand keyCommandWithInput:@"\r" modifierFlags:kNilOptions action:@selector(handlePlainReturn:)];
|
||||
return @[
|
||||
plainReturn
|
||||
];
|
||||
}
|
||||
|
||||
- (void)handlePlainReturn:(id)__unused sender {
|
||||
if (_shouldReturn) {
|
||||
_shouldReturn();
|
||||
}
|
||||
}
|
||||
|
||||
- (void)deleteBackward {
|
||||
bool notify = self.text.length == 0;
|
||||
[super deleteBackward];
|
||||
if (notify) {
|
||||
if (_backspaceWhileEmpty) {
|
||||
_backspaceWhileEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user