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

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

Open
radicaled opened this issue May 1, 2016 · 17 comments
Open

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

radicaled opened this issue May 1, 2016 · 17 comments

Comments

@radicaled
Copy link

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

@JordanMartinez
Copy link
Contributor

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

@JordanMartinez
Copy link
Contributor

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

@radicaled
Copy link
Author

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

@JordanMartinez
Copy link
Contributor

JordanMartinez commented May 3, 2016

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
Copy link
Contributor

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

@radicaled
Copy link
Author

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.

@JordanMartinez
Copy link
Contributor

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 😀 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.

@radicaled
Copy link
Author

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.

@firm1
Copy link

firm1 commented Nov 6, 2016

hello,

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

@synth3
Copy link

synth3 commented Nov 30, 2016

Any updates on that?

@alt-grr
Copy link

alt-grr commented Nov 30, 2016

@synth3 See #398

@eckig
Copy link

eckig commented Dec 1, 2016

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

@JFormDesigner
Copy link
Contributor

@eckig No, #398 it does not fix -fx-highlight-text-fill.

I tried to fix -fx-highlight-text-fill in commit JFormDesigner@0683c01, 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%);
}

@JordanMartinez
Copy link
Contributor

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 JordanMartinez changed the title -fx-highlight-(text)-fill issues? "-fx-highlight-text-fill" CSS doesn't work due to JDK bug Mar 17, 2017
JFormDesigner pushed a commit to JFormDesigner/RichTextFX that referenced this issue Feb 19, 2019
…FXMisc#303)

instead of using Text.selectionFillProperty(), which does not work correctly, this workaround splits segments at selection bounds and uses Text.fillProperty() to assign text color (e.g. white) to selected text
@octylFractal
Copy link

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.

@Jugen
Copy link
Collaborator

Jugen commented Aug 19, 2019

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

@Jugen
Copy link
Collaborator

Jugen commented Aug 21, 2019

Fixed highlight fill not working with PR #844

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

No branches or pull requests

9 participants