Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: What is the strategy to implement Highlight All for found matches for modifiable text? #1227

Closed
PavelTurk opened this issue May 16, 2024 · 5 comments

Comments

@PavelTurk
Copy link
Contributor

PavelTurk commented May 16, 2024

I have a CodeArea with text that can be modified by user. Now, I want to implement Highlight All for all found matches (for search).

As I understand for all found matches I do codeArea. setStyle​(from, to, style). But, if the user updates some match so that it shouldn't be highlighted anymore then how should I control what text was modified to remove highlighting? What if user pastes some text inside found match or deletes large block of text? Could anyone say how such things are done with RichTextFX?

@PavelTurk
Copy link
Contributor Author

I was thinking about the following solution:

  1. For highlighting I do codeArea.setStyleClass(from, to, "highlighted");
  2. User makes changes in text
  3. I get event on textProperty. Using old value, new value and caret position I get information about text change.
  4. On both sides of the changed piece of text I do:
var styles = stycodeArea.getStyleAtPosition(position);
if styles contains my "highlighted" style class then 
var range = codeArea.getStyleRangeAtPosition(position)
update styles in this range ???

Is this a correct way?

@Jugen
Copy link
Collaborator

Jugen commented May 20, 2024

Yes that sounds about right .....

@PavelTurk
Copy link
Contributor Author

@Jugen Thank you very much for your answer. Do I understand it correctly that there is no low level API for getting text changes in RichTextFX? For example, I would like to get events - text added/removed/replaced with text and positions.

@Jugen
Copy link
Collaborator

Jugen commented May 20, 2024

You can use either plainTextChanges or richChanges which includes style changes.

@PavelTurk
Copy link
Contributor Author

@Jugen Yes, this is what I was looking for. Thank you very much for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants