RichTextFX icon indicating copy to clipboard operation
RichTextFX copied to clipboard

"-fx-highlight-text-fill" CSS doesn't work due to JDK bug

Open radicaled opened this issue 8 years ago • 17 comments

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. no-fill-no-chill

radicaled avatar May 01 '16 12:05 radicaled

@radicaled Looking at the source code here, that's something else that needs to be fixed :-/

JordanMartinez avatar May 02 '16 16:05 JordanMartinez

I've updated the CSS Guide with a note that highlighting doesn't currently work.

JordanMartinez avatar May 02 '16 16:05 JordanMartinez

Thanks for looking into it! I'll... figure something out until this gets fixed.

radicaled avatar May 02 '16 22:05 radicaled

The order of styles is already applied in this order:

  1. selection
  2. styled text
  3. 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:

  1. Determine the selection range
  2. Determine where the Paragraph's style segments overlap with that range
  3. 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 whatnot

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.

JordanMartinez avatar May 03 '16 00:05 JordanMartinez

@radicaled Why not consider fixing the issue? It might save you more time overall anyways.

JordanMartinez avatar May 03 '16 00:05 JordanMartinez

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.

radicaled avatar May 03 '16 00:05 radicaled

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.

JordanMartinez avatar May 03 '16 02:05 JordanMartinez

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.

radicaled avatar May 03 '16 04:05 radicaled

hello,

have you any information about this issue ? It doesn't work on 0.7M-2

firm1 avatar Nov 06 '16 22:11 firm1

Any updates on that?

synth3 avatar Nov 30 '16 11:11 synth3

@synth3 See #398

alt-grr avatar Nov 30 '16 12:11 alt-grr

Unfortunately the mentioned pull request #398 does not fix -fx-highlight-text-fill ..?

eckig avatar Dec 01 '16 12:12 eckig

@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%);
}

JFormDesigner avatar Dec 01 '16 14:12 JFormDesigner

Current Status

#398 fixes the -fx-highlight-fill issue. #428 will fix the -fx-highlight-text-fill issue when that JavaFX bug is resolved.

JordanMartinez avatar Jan 17 '17 23:01 JordanMartinez

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.

octylFractal avatar Aug 15 '19 00:08 octylFractal

The last time this worked was in version 0.8.2, so something in 0.9.0 broke this.

Jugen avatar Aug 19 '19 16:08 Jugen

Fixed highlight fill not working with PR #844

Jugen avatar Aug 21 '19 16:08 Jugen