How to insert text at cursor position in nstextview using cocoa programming?

I use this code to get the cursor position:

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

How to add selected text to the current cursor position rather than add text?

+3
source share
1 answer

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

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

At NSMakeRange()4 there is a place in the text view, and 0 is used for length, because you do not want to replace the text.

+4
source

All Articles