Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I insert text at cursor position in a nstextview using cocoa programming?

Tags:

cocoa

I am using this code to get the cursor position:

NSInteger insertionPoint = [[[myTextView selectedRanges] objectAtIndex:0] rangeValue].location;

How to add selected text at the current cursor position and not by appending the text?

like image 258
user1295948 Avatar asked Apr 24 '12 13:04

user1295948


1 Answers

If I understand your problem correctly, this will work for you:

[textView setSelectedRange:NSMakeRange(4, 0)];
[textView insertText:@"my copied text"];

In the NSMakeRange() 4 is the location in the text view and 0 is used for the length because you don't want to replace any text.

like image 113
sud0 Avatar answered Nov 22 '22 07:11

sud0