Determining when an NSTextView is being edited?

  • I searched the archives and didn't find anything relevant to what I'm
    trying to do...

    I have an NSTextView subclass. I want to override -drawRect: so that
    it does some additional drawing, but I want the drawing operation to
    take place only if the text view is actually being edited. The
    problem is, I can't find out how to get the editing state of an
    NSTextView class.

    How do I get the editing state of the class? I already tried -
    selectedRange, but that appears to return a range even if the text
    view isn't being edited. I looked in the documentation, including the
    superclasses, and couldn't find an -isEditing method or something
    similar.

    Nick Zitzmann
    <http://www.chronosnet.com/>
  • At 7:43 PM -0600 10/12/07, Nick Zitzmann wrote:

    > I searched the archives and didn't find anything relevant to what
    > I'm trying to do...
    >
    > I have an NSTextView subclass. I want to override -drawRect: so that
    > it does some additional drawing, but I want the drawing operation to
    > take place only if the text view is actually being edited. The
    > problem is, I can't find out how to get the editing state of an
    > NSTextView class.
    >
    > How do I get the editing state of the class? I already tried
    > -selectedRange, but that appears to return a range even if the text
    > view isn't being edited. I looked in the documentation, including
    > the superclasses, and couldn't find an -isEditing method or
    > something similar.

    Just a WAG here, but what about checking the parent window's
    -firstResponder against self?
    --
    randy
  • On Oct 12, 2007, at 9:43 PM, Nick Zitzmann wrote:

    > I searched the archives and didn't find anything relevant to what
    > I'm trying to do...
    >
    > I have an NSTextView subclass. I want to override -drawRect: so
    > that it does some additional drawing, but I want the drawing
    > operation to take place only if the text view is actually being
    > edited. The problem is, I can't find out how to get the editing
    > state of an NSTextView class.
    >
    > How do I get the editing state of the class? I already tried -
    > selectedRange, but that appears to return a range even if the text
    > view isn't being edited. I looked in the documentation, including
    > the superclasses, and couldn't find an -isEditing method or
    > something similar.

    Hi,

    Notifications...

    http://developer.apple.com/documentation/Cocoa/Conceptual/TextEditing/
    Tasks/DelegatesAndNotif.html

    hth,

    Jaime Magiera
    Sensory Research Network
    http://www.sensoryresearch.net
  • On Oct 12, 2007, at 7:56 PM, Jaime Magiera wrote:

    > Notifications...
    >
    > http://developer.apple.com/documentation/Cocoa/Conceptual/
    > TextEditing/Tasks/DelegatesAndNotif.html

    OK, that might work, although it does seem sort of silly that a text
    view has to listen to itself to determine when it's being edited, no?
    That's why I was hoping there was another way...

    Nick Zitzmann
    <http://www.chronosnet.com/>
  • Who else might it listen to?

    On Oct 12, 2007, at 10:02 PM, Nick Zitzmann wrote:

    >
    > On Oct 12, 2007, at 7:56 PM, Jaime Magiera wrote:
    >
    >> Notifications...
    >>
    >> http://developer.apple.com/documentation/Cocoa/Conceptual/
    >> TextEditing/Tasks/DelegatesAndNotif.html
    >
    > OK, that might work, although it does seem sort of silly that a
    > text view has to listen to itself to determine when it's being
    > edited, no? That's why I was hoping there was another way...
  • On Oct 12, 2007, at 10:02 PM, Nick Zitzmann wrote:
    >
    > OK, that might work, although it does seem sort of silly that a
    > text view has to listen to itself to determine when it's being
    > edited, no? That's why I was hoping there was another way...

    In terms of MVC it might make sense. You're wanting something to
    happen when the user performs a specific action. So, you register the
    interface controller to listen for that action. When the notification
    is received, the controller tells the specific interface element to
    do something. This is good solution if you wanted to do multiple
    things in the interface spawned from one user action. The window
    controller or whatever can tweak multiple interface objects after
    receiving that notification.

    anyway, I hope everything works out,

    Jaime Magiera
    Sensory Research Network
    http://www.sensoryresearch.net
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today