Mark occurences

Questions on using RSyntaxTextArea should go here.

Moderator: robert

Mark occurences

Postby bob » Sat Dec 12, 2009 9:49 am

Hello Robert,

I would like to know if there's a way to mark occurences for all words (functions too) ?

In notepad++, when you select a word by clic, all the same occurences appears with a color. It's very pratice for searching words rapidly...

Is it possible to do that ?

THANKS
bob
 

Re: Mark occurences

Postby robert » Mon Dec 14, 2009 1:22 pm

Howdy bob,

Mark Occurrences currently doesn't do functions or methods, only identifiers. If you'd like it to work on more token types, or be configurable, please open a Feature Request here, so it's tracked:

https://sourceforge.net/projects/rsynta ... ea/support

Thanks!
User avatar
robert
 
Posts: 789
Joined: Sat May 10, 2008 5:16 pm

Re: Mark occurences

Postby Christian » Wed Apr 14, 2010 11:08 am

Hello Guys ..

Sorry, but what do I have to do if I want my RSTA to display all occurences of the selected text when selecting a keyword or s.th. like this?
I tried to solve this by adding Listeners to the RSTA, this worked well until I tried to select the text backwards and I failed to add my own "mark-all ...". So if saw that the RSTA still supports such a functionality but I failed again. I can do whatever I want - there is no text marked.

Do I have to add the keywords first? I called

this.textArea.setMarkOccurrences(true);
this.textArea.setMarkOccurrencesColor(Color.RED);

but it doesn't work .. Thanks for trying to understand me and my English ;)
Christian
 

Re: Mark occurences

Postby Guest » Fri Apr 16, 2010 7:17 am

Ok, I did it by my own with some Listeners ...

But I'm still interested if the RSTA does still support such a functionality and how to "install" it ..

Thanks.
Guest
 

Re: Mark occurences

Postby Christian » Mon Apr 19, 2010 2:30 pm

So now I saw this thing working ..

Thanks :)

I think it doesn't work in all syntax schemes, I saw it today as I tested one of my own syntax schemes.
Christian
 

Re: Mark occurences

Postby robert » Mon Apr 19, 2010 8:22 pm

Sorry Christian, I'm a little confused on what you're trying to accomplish. I think I'd have to see an example of what you're trying to do to give you a good response. Even though you say you have it working now, can you provide an example of what you're doing? Or if your code snippet is simple enough, you can post it here or send it to me.

Thanks
User avatar
robert
 
Posts: 789
Joined: Sat May 10, 2008 5:16 pm

Re: Mark occurences

Postby Christian » Tue Apr 20, 2010 9:01 am

No problem. I just wanted to implement a feature as you can see it in eclipse selecting a text and the text is highlighted wherever it is written in the field.

I just added a KeyListener for reacting on selections via keyboard and a MouseListener to react on selections made per mouse. If an event occures I call the following code:

Code: Select all
if(this.markAllOccurences) {
      final int start = this.textArea.getSelectionStart();
      final int ende = this.textArea.getSelectionEnd();
      final int carPos = this.textArea.getCaretPosition();
      final String text = this.textArea.getSelectedText();
      if(text != null && text.length() > 0) {
        if(this.textArea.markAll(text, true, false, false) == 1) {
          this.textArea.clearMarkAllHighlights();
        }
        if(carPos == ende) {
          this.textArea.setSelectionStart(start);
          this.textArea.setSelectionEnd(ende);
        } else { //for selection via keyboard press shift + arrow left
          this.textArea.setSelectionStart(ende);
          this.textArea.setSelectionEnd(start);
          this.textArea.moveCaretPosition(start);
        }
      } else {
        this.textArea.clearMarkAllHighlights();
      }
    }


And it works. Then I saw that the RSTA has a method setMarkOccurrences(boolean). I thought it was what I wanted to have but now I think I've found out, that this just highlights Token when the caret is on a special position. I'm not sure, whether to use this feature from RSTA because it seems not to work in some languages.

I hope now it is clear what I wanted ;)
Christian
 

Re: Mark occurences

Postby robert » Tue Apr 27, 2010 8:48 pm

I believe the built-in "mark occurrences" support will only mark occurrences for plain identifiers (plain black tokens in the default color scheme) and variables. It marks all matching tokens in the editor after a short delay. This is like the "Mark Occurrences" feature of the Eclipse Java editor.
User avatar
robert
 
Posts: 789
Joined: Sat May 10, 2008 5:16 pm


Return to Help

Who is online

Users browsing this forum: zöner and 1 guest