Strategies for dynamic modification of search results in NSTextViews
Martin Hewitson Strategies for dynamic modification of search results in NSTextViews Jan 03 2012, 12:05Dear list,
I have an app which managed a bunch of files and presents these text files for viewing and editing in NSTextViews. I have implemented a project-wide search functionality which works fine, but with one problem. If the user changes the text in one file after making a search, then the search results are no longer valid. A typical use-case is to make a search for a word or phrase, then go through each result and modify it. Problem is, after the first modification by the user, the subsequent results are no longer accurate/valid.
Does anyone have any good suggestions as to how to update my search results when the underlying source text changes? Do I have to listen for all changes from the underlying text objects and try to adapt, or is there a better pattern for doing this? Xcode does this nicely: no matter what changes you make in the editor, the search results are updated on the fly.