Open dzmipt opened 10 months ago
@dzmipt You'd also want to remember the "original" caret position, so if they hit backspace in your search field enough, you can backtrack to the original position (or prior marches for the shorter partial), right?
Do you have this listener class as something you'd like to contribute to RSTA? I wonder if I could add it to either RSyntaxTextArea
or RSTAUI since that project has modals you can use to control SearchContext
actions.
Status quo I have a RSTA and search panel with a "what" text and "Find" button. I can type in a "what" text and click "Find" button. "Find" button performs
SearchEngine.find(rsta, searchContext)
. When I click the button multiple time, the next "what" word is selected. This scenario works perfectly.Describe the solution you'd like I want to modify searching - when I am typing "what" word, I want the search is being performed in the background.
For example, if I have rsta with the following content
abc abd
The caret is at offset 0.a
=> the first char "a" is selected.b
; "what" isab
=> the first 2 chars "ab" are selected.d
; "what" is nowabd
=> and only now "abd" is selected.What I did I added
whatTextField.getDocument().addDocumentListener()
with callingSearchEngine.find()
. However in the use-case above when I pressed on the 2nd stepb
, the second occurrence of "ab" is selected.What is proposed I think it is needed one more field to the
SearchContext
which controls if the search should start from the selectionStart or from the selectionEnd. And alsoSearchContext.forward
should be taken into account.