RichTextFX
RichTextFX copied to clipboard
"-fx-highlight-text-fill" CSS doesn't work due to JDK bug
Sorry for yet another issue, but...
I'm on 1.0.0-SNAPSHOT and it seems that setting -fx-highlight-fill
and -fx-highlight-text-fill
aren't working as expected. I'm following the instructions here: https://github.com/TomasMikula/RichTextFX/wiki/Styling-RichTextFX-and-a-CSS-Cheat-Sheet#cheat-sheet
The bottom part of the attached image is from a StyleClassedTextArea. You can see that the text is being styled correctly (it's got a class of "header"), but the highlight CSS isn't.
@radicaled Looking at the source code here, that's something else that needs to be fixed :-/
I've updated the CSS Guide with a note that highlighting doesn't currently work.
Thanks for looking into it! I'll... figure something out until this gets fixed.
The order of styles is already applied in this order:
- selection
- styled text
- default (style-less) values
The "selection style," if you will, overrides only the background and foreground of the text; all other style-related items (font, font size, weight, etc.) are not overridden. So, here's one way we could implement this:
- Determine the selection range
- Determine where the
Paragraph
's style segments overlap with that range - Construct the Text objects
- if no overlap, just apply the style
- if overlap covers all of the segment, apply style and selection style
- if overlap covers a portion of the segment, create multiple Text objects: apply the regular style and selection style to the selected portion and only the regular style to the unselected one(s).
So, given the following example where angle brackets represent the selection:
Some text here _that
There would be 5 Text objects:
- Some text here
- that
-
was selected
-
and
- whatnot
However, you'll notice that in the source code, the Text objects are only created once, not every time layoutChildren()
is called. So, I don't know what issues, if any, might arise if this approach was taken.
@radicaled Why not consider fixing the issue? It might save you more time overall anyways.
Why not consider fixing the issue? It might save you more time overall anyways.
My JavaFX skills are pretty poor: I'm coming back to Java (via Kotlin, actually) after a long, long absence -- since before JavaFX was a thing. I actually did have a look at the source code you referenced earlier, but couldn't identify the root problem based on the comment, nor a potential solution. Basically I don't know enough about RichTextFX and JavaFX yet to properly fix it.
Basically I don't know enough about RichTextFX and JavaFX yet to properly fix it.
Well, we can't do much about JavaFX, but I hear you about RichTextFX. I've only become more familiar with it due to all the PRs I've submitted in the past couple of months. Before that, it was just code that magically did what I needed :grinning: However, I wonder if others have had a similar issue: wanting to contribute, but finding that getting familiar with the project takes too much time. I wonder if it would be worth it to write a guide on how RichTextFX works internally so that others can have an easier time contributing. The only issue there is that such a guide would become outdated pretty fast and defeat the whole purpose of it.
I wonder if it would be worth it to write a guide on how RichTextFX works internally so that others can have an easier time contributing. The only issue there is that such a guide would become outdated pretty fast and defeat the whole purpose of it.
A high level overview might be useful, and live longer. For instance, the StyleSpan(s) API feels pretty awkward, but it looks to be that way for performance reasons, so any augmentations or changes to that API would have to be made carefully, I think. Knowing "why" can almost be as helpful as "how" in those circumstances.
hello,
have you any information about this issue ? It doesn't work on 0.7M-2
Any updates on that?
@synth3 See #398
Unfortunately the mentioned pull request #398 does not fix -fx-highlight-text-fill
..?
@eckig No, #398 it does not fix -fx-highlight-text-fill
.
I tried to fix -fx-highlight-text-fill
in commit https://github.com/JFormDesigner/RichTextFX/commit/0683c01aaf7e93657f1b4ae281a5aaf1abfc6f23, but it does not work 100% because of a bug in JavaFX. For details see commit message.
For Markdown Writer FX I'm going to workaround the problem with the unreadable selected text with a brighter background selection color:
.styled-text-area {
-fx-highlight-fill: derive(#1E90FF, 100%);
}
Current Status
#398 fixes the -fx-highlight-fill
issue.
#428 will fix the -fx-highlight-text-fill
issue when that JavaFX bug is resolved.
Did this change fixing -fx-highlight-fill
get reverted at some point? In 0.10.1
, these CSS attempts do not modify selected text color at all:
/* 1 */
.styled-text-area .text { -fx-highlight-fill: #999999; }
/* 2 */
.styled-text-area .selection { -fx-fill: #999999; }
/* 3 */
.styled-text-area { -fx-highlight-fill: #999999; }
Other CSS in this file is being applied, so I'm sure it's a re-appearance of this issue.
The last time this worked was in version 0.8.2
, so something in 0.9.0
broke this.
Fixed highlight fill not working with PR #844