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

cocoa

Solution

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.

Problem

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?

Original source