Thread:Kangaroopower/@comment-3508190-20120413185323/@comment-3508190-20120419013122

Here's what I would design the interface like:

FindReplace.Shadow.ready


 * takes a callback function as parameter; when the Shadow is ready for action it will execute the callback; you can use this to make sure the dialog cannot be opened before searching is possible

FindReplace.Shadow.setRegex


 * sets the regex for the highlighting and the replacements; passing null instead of a regex removes all highlights; you should set it to null, when the dialog is closed

FindReplace.Shadow.countMatches


 * tells you how often the regex matches the text

FindReplace.Shadow.next FindReplace.Shadow.prev


 * advance to the next/previous match; if it is not in view, it will be scrolled into view; the match is then selected; "next" and "prev" are relative to the current position of the caret; calling next at the end of the text will jump to the first match; calling prev at the beginning will jump to the last

FindReplace.Shadow.replace


 * replaces the currently selected match

FindReplace.Shadow.replaceAll


 * replace all matches

FindReplace.Shadow.isReplaceable


 * the user can deselect anything or select something different entirely; there's no certainty that a match is currently selected - even if you just called prev or next; this function tells you if a replacement would be possible (i.e. there's a match selected)

FindReplace.Shadow.getSelection


 * returns the currently selected text; you can you use this to initialize the dialog's "Search" field