Created
August 30, 2019 04:13
-
-
Save simsaens/0720b978d92d217915823124e666d44a to your computer and use it in GitHub Desktop.
Responding to copy and paste
This file contains 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
- (BOOL) canPerformAction:(SEL)action withSender:(id)sender | |
{ | |
switch ( menuState ) | |
{ | |
case JAMCodeEditorMenuStateHidden: | |
{ | |
if( self.selectedRange.length == 0 ) | |
{ | |
if( action == @selector(select:) || | |
action == @selector(selectAll:) || | |
action == @selector(paste:) ) | |
{ | |
return YES; | |
} | |
} | |
else | |
{ | |
if( action == @selector(cut:) || | |
action == @selector(copy:) || | |
action == @selector(paste:) ) | |
{ | |
return YES; | |
} | |
} | |
return NO; | |
} | |
case JAMCodeEditorMenuStateCaret: | |
{ | |
if( action == @selector(select:) || | |
action == @selector(selectAll:) || | |
action == @selector(paste:) ) | |
{ | |
return YES; | |
} | |
} break; | |
case JAMCodeEditorMenuStateSelection: | |
{ | |
if( action == @selector(cut:) || | |
action == @selector(copy:) || | |
action == @selector(paste:) ) | |
{ | |
return YES; | |
} | |
} break; | |
default: | |
break; | |
} | |
return NO; | |
} | |
- (void) copy:(id)sender | |
{ | |
//Get selected text | |
NSString *text = self.selectedText; | |
if( text ) | |
{ | |
[[UIPasteboard generalPasteboard] setString:text]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment