Skip to content

Instantly share code, notes, and snippets.

@simsaens
Created August 30, 2019 04:13
Show Gist options
  • Save simsaens/0720b978d92d217915823124e666d44a to your computer and use it in GitHub Desktop.
Save simsaens/0720b978d92d217915823124e666d44a to your computer and use it in GitHub Desktop.
Responding to copy and paste
- (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