NSTextView scrolls to top when text storage changes

  • Dear List,

    I have a document managing app which has a project search feature for searching through the project's managed files (see thread "Dynamic modification of text search results" earlier this week).

    When I find search matches I add an attribute to the textstorage in which the search term was found. For the file/textstorage that is currently displayed in the editor (the NSTextView), this has the consequence of scrolling the text view to the top. The selection is not changed - just the scrollview jumps to the top.

    I assume this must be a bug. I've checked every place in the code where I respond to NSTextStorageDidProcessEditingNotification, and none of these is responsible for the scrolling.

    Has anyone else seen this behaviour? Is this a known issue? If so, is there a workaround?

    Many thanks,

    Martin
  • OK, I found the problem. Turns out I had left the textview associated with more than one textstorage. I'm surprised that this was the only symptom. In detail, when switching tabs in the editor, I forgot to remove the textview from all other text containers before assigning it to the file associated with the new tab. Silly.

    Martin

    On 7, Jul, 2012, at 06:47 AM, Martin Hewitson wrote:

    > Dear List,
    >
    > I have a document managing app which has a project search feature for searching through the project's managed files (see thread "Dynamic modification of text search results" earlier this week).
    >
    > When I find search matches I add an attribute to the textstorage in which the search term was found. For the file/textstorage that is currently displayed in the editor (the NSTextView), this has the consequence of scrolling the text view to the top. The selection is not changed - just the scrollview jumps to the top.
    >
    > I assume this must be a bug. I've checked every place in the code where I respond to NSTextStorageDidProcessEditingNotification, and none of these is responsible for the scrolling.
    >
    > Has anyone else seen this behaviour? Is this a known issue? If so, is there a workaround?
    >
    > Many thanks,
    >
    > Martin
    >
    >

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Martin Hewitson
    Albert-Einstein-Institut
    Max-Planck-Institut fuer
        Gravitationsphysik und Universitaet Hannover
    Callinstr. 38, 30167 Hannover, Germany
    Tel: +49-511-762-17121, Fax: +49-511-762-5861
    E-Mail: <martin.hewitson...>
    WWW: http://www.aei.mpg.de/~hewitson
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
previous month july 2012 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