user1295948
user1295948

Reputation: 303

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

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?

Upvotes: 7

Views: 3705

Answers (1)

sud0
sud0

Reputation: 547

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.

Upvotes: 9

Related Questions