bobbylight / RSyntaxTextArea

A syntax highlighting, code folding text editor for Java Swing applications.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Continues search

dzmipt opened this issue · comments

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.

  1. I type a => the first char "a" is selected.
  2. I press b; "what" is ab => the first 2 chars "ab" are selected.
  3. I press d; "what" is now abd => and only now "abd" is selected.

What I did
I added whatTextField.getDocument().addDocumentListener() with calling SearchEngine.find(). However in the use-case above when I pressed on the 2nd step b, 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 also SearchContext.forward should be taken into account.

@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.