1

I'm stuck on something that should be very obvious but I've searched everywhere and haven't quite found what I was looking for. The task is simple; I have a NSTextField and I need to get the position of cursor whenever it changes (user starts writing, arrow keys, clicks etc).

On the internet everyone suggests:

override func controlTextDidChange(_ obj: Notification)

delegate method. which I used but it only responds when the text inside the textfield changes i.e user writes, deletes text etc not for anyother scenario.

I also tried adding a "NSClickGestureRecognizer" along with a controlTextDidChange to get the position of the cursor when it changes after a click but that didn't work either.

Does anyone know of any way to respond to and fetch the cursor position whenever it changes.

Any help would be greatly appreciated. thanks in advance.

Fabio Berger
  • 1,921
  • 2
  • 24
  • 29
Umer Hassam
  • 1,332
  • 5
  • 23
  • 42
  • whats your intention with this? – jegadeesh Aug 03 '17 at 06:01
  • I need to make an html parser. the html code will be loaded in the textfield and I have to show the attributes of which ever tag the cursor is currently pointing at in a separate view. – Umer Hassam Aug 03 '17 at 06:26
  • follow this link. It will help you I guess. https://stackoverflow.com/questions/21749049/perform-action-by-clicking-on-some-word-in-uitextview-or-uilabel. you can approach the problem this way. – jegadeesh Aug 03 '17 at 06:34
  • did u solve the problem? – jegadeesh Aug 03 '17 at 08:35
  • not yet. I think I might have to subclass the customEditor ... but I'd like to avoid that solution if possible. – Umer Hassam Aug 03 '17 at 09:28
  • Any idea on the link I referred? I thought thats what you needed. – jegadeesh Aug 03 '17 at 10:57
  • No sadly it doesn't work. mostly because its for cocoaTouch API not cocoa... I've already tried adding the NS equivalent of "UITapGestureRecognizer" as recommended in that link but that doesn't work either. – Umer Hassam Aug 03 '17 at 11:18

0 Answers0