-
Notifications
You must be signed in to change notification settings - Fork 505
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
8335547: Support multi-line prompt text for TextArea #1716
base: master
Are you sure you want to change the base?
Conversation
👋 Welcome back Ziad-Mid! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
if (isBound()) { | ||
unbind(); | ||
} | ||
if (isBound()) { |
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 think we might want to bypass the whole thing if it is a TextArea.
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.
Yes I did change the code a bit and now the tests do not fail
if (isBound()) { | ||
unbind(); | ||
} | ||
if (TextInputControl.this instanceof TextArea) { |
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.
Is this the right approach? One can always ask whether we should rely on the instanceof TextArea
here, for example in the context of a custom TextInputControl.
Also think of:
- Can a custom control override this behavior?
- Do we want to give this capability to the application?
- Should we create a public API instead? And if so, which kind?
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 purpose of this is to remove the stripping of new lines in TextArea only as that is normally how it should be,
but the default behavior will stay as it was before for other classes that extends TextInputControl.
And to give the capability to applications to modify this behavior is not necessary.
Also notice the github actions (GHA) are failing, meaning this PR breaks some tests
|
I have fixed the code for this , but there is still another fail |
also, you can try re-running failed tests (look for a button in the top right corner). |
What do you think of an alternative solution: instead of trying to fix the property value, we could leave it alone but change the way it's interpreted by the skin. Look at
This will remove all the logic from the control and place it where it needs to happen (TextFieldSkin). The TextAreaSkin is unchanged and will display newlines when all the cruft is removed from (We could also change the said property to be lazily initialized since in most cases it's not used). What do you think? |
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 idea is solid - you could make it ready for review (RFR) now.
I've left a number of general formatting suggestions, but the main concern is the decision to convert the tests to be specific to the TextField
and the TextArea
(omitting the PasswordField
). Since the only difference is the expected values, maybe we can keep the existing tests and introduce a function that computes the expected value based on the (parameter) type.
s = ""; | ||
s = s.replace("\n", ""); | ||
return s; | ||
}, getSkinnable().promptTextProperty())); |
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.
two minor problems:
- missing { } after
if
. (I would highly recommend always using { }) - when s is null you call replace() unnecessarily
suggestion:
String s = getSkinnable().getPromptText();
if (s == null) {
return "";
}
return s.replace("\n", "");
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.
You should consider using a fluent binding here, which is a more modern solution compared to the Bindings
class. It is also simpler because you don't need to check for null
:
promptNode.textProperty().bind(getSkinnable().promptTextProperty().map(s -> s.replace("\n", "")));
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.
Have you considered the suggestion?
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.
Yes I will push the new changes thanks for the suggestion @mstr2
modules/javafx.controls/src/test/java/test/javafx/scene/control/TextAreaTest.java
Show resolved
Hide resolved
txtArea.promptTextProperty().bind(promptProperty); | ||
root.getChildren().add(txtArea); | ||
Text promptNode = TextInputSkinShim.getPromptNode(txtArea); | ||
assertEquals("Prompt\nwith\nLineBreaks", promptNode.getText()); |
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.
here you can use promptWithLineBreaks
string declared earlier
(also applies to other tests)
txtArea.setPromptText(promptWithLineBreaks); | ||
root.getChildren().add(txtArea); | ||
Text promptNode = TextInputSkinShim.getPromptNode(txtArea); | ||
System.out.println(promptNode.getText()); |
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.
no need to print to stdout. please remove all System.out.println()'s
assertEquals("Prompt without LineBreaks", promptNode.getText()); | ||
txtField.setPromptText(promptWithLineBreaks); | ||
assertEquals("PromptwithLineBreaks", promptNode.getText()); | ||
|
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 remove extra newline
modules/javafx.controls/src/test/java/test/javafx/scene/control/TextAreaTest.java
Show resolved
Hide resolved
modules/javafx.controls/src/test/java/test/javafx/scene/control/TextInputControlTest.java
Show resolved
Hide resolved
you can make this PR ready for review (RFR) now. |
Webrevs
|
What happens if the text contains line breaks other than |
This is a good question.
@Ziad-Mid could you investigate please? |
Yes , this approach do not handle all the line Seperators only "\n" , I will change it to handle it all |
@Ziad-Mid please make sure we need to change - does the code (with no filtering) render other newline characters? |
I did test the mentioned line separators without filtering and the line separators are not rendered as newlines, so there is no need to add filtering for other line separators as they are already handled by default. |
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 think it currently looks good, even though PasswordField
lost its portion of tests. Since we know the PasswordField
implementation does not add any functionality in the area being tested, the TextFieldTest should be sufficient.
Left some minor comments.
I would like to have another pair of eyes though.
/reviewers 2
modules/javafx.controls/src/main/java/javafx/scene/control/skin/TextFieldSkin.java
Outdated
Show resolved
Hide resolved
modules/javafx.controls/src/test/java/test/javafx/scene/control/TextAreaTest.java
Show resolved
Hide resolved
@andy-goryachev-oracle |
I think that we should treat all usual line separators in the same way (that is, |
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.
@Ziad-Mid :
please do not resolve the conversations without the original commenter confirming that the conversation is resolved (it's really a bug in guthub, as only the originator of the comment can say if the conversation has been resolved). I think there are still some questions left unanswered, please check.
(I've started to use thumbs-up emoji to mark the comment as addressed, if you want my opinion).
Other than that, the changes look good to me.
I did unresolved them, and I will check the suggestions whenever possible and answer, |
modules/javafx.controls/src/main/java/javafx/scene/control/skin/TextFieldSkin.java
Show resolved
Hide resolved
modules/javafx.controls/src/main/java/javafx/scene/control/skin/TextFieldSkin.java
Outdated
Show resolved
Hide resolved
@@ -733,7 +732,7 @@ private void createPromptNode() { | |||
promptNode.visibleProperty().bind(usePromptText); | |||
promptNode.fontProperty().bind(getSkinnable().fontProperty()); | |||
|
|||
promptNode.textProperty().bind(getSkinnable().promptTextProperty()); | |||
promptNode.textProperty().bind(getSkinnable().promptTextProperty().map(s -> s.replace("\n", ""))); |
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 recommend to replace all usual newline characters with replaceAll("[\r\n]", "")
as I can't think of a compelling reason to remove only some, but leave others in the string.
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 tests show that only LF "\n" is rendered as a new line, there is no need to add more restrictions that is not needed
and the same was tested by @andy-goryachev-oracle previously in the comments and it confirms the same.
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.
That doesn't sound like a compelling reason to me. In fact, it makes it seems like a bug in JavaFX that a line break is only rendered with \n
, but not with \r\n
or \r
.
In any case, the goal here is to (semantically) transform a string such that it doesn't contain line breaks, and line breaks come in three different usual forms. Our goal should always be to do the right thing, and not stop half-way and rely on unspecified rendering quirks for the rest.
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.
We seem to have arrived at these two options:
- acknowledge and defend the status quo in which the text layout considers only '\n' as newlines
- enhance the text layout to handle other paragraph separators (as well as maybe add support for other symbols that impact layout, such as soft hyphen)
@kevinrushforth what do you think?
Added multi line prompt support for TextArea this will provide the ability to have multiple lines in textArea as expected,
Also fixed tests to meet the new changes
Progress
Issues
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/1716/head:pull/1716
$ git checkout pull/1716
Update a local copy of the PR:
$ git checkout pull/1716
$ git pull https://git.openjdk.org/jfx.git pull/1716/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 1716
View PR using the GUI difftool:
$ git pr show -t 1716
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/1716.diff
Using Webrev
Link to Webrev Comment