0

Is there a way to create a NSTextField where the input of the user replaces the text under the cursor?

And in addition: is there a way to change the cursor to a block cursor?

Johann Horvat
  • 1,285
  • 1
  • 14
  • 18
  • What do you mean by text under the cursor? You want to add a bunch of text that follows the cursor? – TheAmateurProgrammer Jul 15 '14 at 12:39
  • I mean the character under the cursor. Just a bit like the replace mode of vim ([vim like a pro](http://vimlikeapro.blogspot.co.at/p/insert-overwrite-change.html)) – Johann Horvat Jul 15 '14 at 19:03
  • 1
    the cursor is a bar that goes between chars... if you want to emulate insert vs overwrite, like old timey Word Perfect you will have to use the controls delegate methods... or make a custom subclass – Grady Player Jul 16 '14 at 14:56

1 Answers1

2

For your first problem, get the selected range of the text view, then replace that text with the input. So something like

NSRange range = [textView selectedRange];
[textView.textStorage replaceCharactersInRange:range withString:input];

For your second problem, refer to this.

TheAmateurProgrammer
  • 9,252
  • 8
  • 52
  • 71