-
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
Issue #594: Properly calculate the background and underline shapes fo… #595
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR.
There's a few things that can be cleaned up before merging this
import javafx.scene.text.Text; | ||
import javafx.scene.text.TextFlow; | ||
|
||
@RunWith(NestedRunner.class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NestedRunner is only necessary if you want to use a class to set up common things among multiple tests. Since you're not doing that here, you can remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. It was essentially a preparation for later enhancements, but it is indeed better to add it once it is really required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like NestedRunner because it reduces code duplication when setting up similar tests. However, it doesn't allow one to run tests within the nested classes in my IDE. I'm not sure how to fix that, but even if we did, I would think that such a thing should not need to be explained for the tests to work on someone else's computer.
Region paragraphBox = getParagraphBox(0); | ||
|
||
// get the ParagraphText (protected subclass of TextFlow) | ||
TextFlow tf = (TextFlow) paragraphBox.getChildrenUnmodifiable().get(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be changed to check for the instance first, only cast if it's valid and throw an exception if it's not? Otherwise, I am not sure it will be the first one if a selection is made.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. get(0) is not always correct - I need to iterate over the children and look up the TextFlow (for which there should be only one, though),
|
||
// expected: one text node which contains the complete text | ||
List<Text> textNodes = getTextNodes(); | ||
assertEquals(1, textNodes.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this should be its own test?
List<Text> textNodes = getTextNodes(); | ||
assertEquals(1, textNodes.size()); | ||
|
||
// Set word "World" to bold |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment forces me to look up what String object is equated with "World".
private final static String styledWord1 = "World"; | ||
private final static String moreText = " and also the "; | ||
private final static String styledWord2 = "Sun"; | ||
private final static String remainingLine = " and Moon"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relating to line 89's comment, since the string itself does not contain the style, it should equal to what the text it is assigned is. Otherwise, styledWord1
is unstyled in one moment and styled in a later moment.
// setup | ||
interact(() -> { | ||
area.replaceText(firstWord + styledWord1 + moreText + styledWord2 + remainingLine); | ||
// "Hello World and also the Sun and Moon" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the comment isn't necessary if we rename the strings to the text they represent
final int start2 = end1 + moreText.length(); | ||
final int end2 = start2 + styledWord2.length(); | ||
area.setStyle(start2, end2, | ||
"-rtfx-underline-color: red; -rtfx-underline-dash-array: 2 2; -rtfx-underline-width: 1; -rtfx-underline-cap: butt;"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be declared once in a variable and then just pass that variable in to both area.setStyle()
calls?
Yes, that is true. In general those methods rely on a particular order how the nodes are inserted into the text flow. It would be better if the node objects themselves know "what" they are. The straight forward solution would be to subclass Path as CaretPath, SelectionPath, BackgroundPath and UnderlinePath - and then use the sub classes instead of plain Path. This would make debugging and inspection of the scene graph (and writing scene related tests) MUCH simpler, since it is immediately visible what kind of path that particular node represents. Alternatively, we could set the id with a specific prefix for each path, but that would require unique id generation (like "bg1,", "bg2" etc.) and it would refer to the instance, not type. Finally, we could also subclass Path once and user a getter to retrieve the type attribute, something like
|
Very good points. I definitely like the subclass or path type approach better than setting the ID. However, which would be easier to use when writing tests and would scale well if we need to add more components to it? |
Actually, since we may never add more rtfx-specific components (YAGNI principle), which approach (and its API) will make reading through the tests easy? |
Looks like #596 is going to work soon. Once it gets merged, can you rebase this (with the changes mentioned) on top of that PR's work? |
Alright #596 has been merged. Looking forward to your update. |
Updated PR primarily for review of the path subclass approach. |
I still see your original commits at the start of this PR and a whole lot of "commit noise" from my other PR. Did you rebase your commits or is this a GitHub issue? Yeah... that test apparently failed in my PR, too. However, Travis had some backlog and it didn't report the issue correctly or something, so I thought it passed. They emailed me the failure later. The issue is that the first test fails, irregardless of which one is run first in that class. I'm not sure where it's timing out thought. Might need to add I'll look over the code later on this week (got other things to do today unfortunately...). However, could you move the test itself to |
Yes, I rebased but forgot that the rebased local branch needs to be force-pushed 🥇
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please amend your commit to fix the issue and force push it.
I'll merge it after that. The TimeoutException thrown in the Mac build isn't related to this at all, so we'll ignore it. That'll need to be addressed in another PR later.
|
||
/** | ||
* A path which describes a selection shape in the Scene graph. | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"selection" is written instead of what you actually meant: "caret."
Otherwise, everything looks good!
Ok. The Mac build issue has been resolved now. |
@afester Can you fix the javadoc issue and rebase on top of master? Then the mac build should pass. |
…pes for non-consecutive ranges
Thanks for your work! |
…r non-consecutive ranges