-
Notifications
You must be signed in to change notification settings - Fork 236
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
Syntax highlighting disappears if you copy some code and immediately paste it back #135
Comments
Would it get highlighted again after if you make any other key entry, space
|
Yes, if you make another key entry after pasting, the highlighting reappears. In fact, the highlighting reappears even after pasting as long as you are not pasting back exactly the same code that is already there. This suggests that the highlighting is done by a ChangeListener of the textProperty of the CodeArea. Unfortunately, the ChangeListener does nothing if the old text matches the new text. |
Good catch! Syntax highlighting is listening to (plain) text changes, and in this case, the text content does not change. Combined with the fact that Copy&Paste does not preserve styling, you get a change in style which is not detected by the parser. |
Is there an easy fix for this problem? |
Yes, you can observe codeArea.richChanges().subscribe(change -> {
codeArea.setStyleSpans(0, computeHighlighting(codeArea.getText()));
}); |
I'm missing something. I replaced the code on lines 78-80 in JavaKeywords.java: codeArea.textProperty().addListener((obs, oldText, newText) -> {
codeArea.setStyleSpans(0, computeHighlighting(newText));
}); with the code you gave above: codeArea.richChanges().subscribe(change -> {
codeArea.setStyleSpans(0, computeHighlighting(codeArea.getText()));
}); and tried to run it, but got infinite recursion. |
You're not missing anything, it is a bug. codeArea.textProperty().addListener(obs -> {
codeArea.setStyleSpans(0, computeHighlighting(codeArea.getText()));
}); |
Run the Java Keywords Demo. Select some of the text, type Ctrl-C to copy the selected text, and then type Ctrl-V to paste all the selected text back over itself. The syntax highlighting disappears for the pasted text.
The text was updated successfully, but these errors were encountered: