-
Notifications
You must be signed in to change notification settings - Fork 137
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
Corrected TextLayout to produce right number of lines when '\r\n' sequence comes. #1320
base: master
Are you sure you want to change the base?
Conversation
Anyone testing this pr can use the below snippet.
|
Test Results 483 files ±0 483 suites ±0 8m 28s ⏱️ +15s For more details on these failures, see this check. Results for commit 514957c. ± Comparison against base commit fdb2fa5. ♻️ This comment has been updated with latest results. |
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java
Outdated
Show resolved
Hide resolved
@@ -2952,8 +2952,11 @@ StyleItem[] merge (long items, int itemCount) { | |||
linkBefore = false; | |||
} | |||
char ch = segmentsText.charAt(start); | |||
if(ch == '\r') { | |||
ch = segmentsText.charAt(start+1); |
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 a boundcheck required here maybe? Just assume a single \r
at end of line would read bejond the end
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 agree
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 am checking on further if the string in full is just a "\r", what needs to be done.
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.
Done.
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.
If you agree to my changes, i can squash the commits.
89bd04a
to
aae8e16
Compare
@niraj-modi @merks @laeubi : Do you have any additional comments on this fix? or are we good to merge this? |
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 don't have time for a more detailed for the next days. But some comments generally follow a for or if keyword with a space.
String text, segmentsText; | ||
int lineSpacingInPoints; | ||
String text, segmentsText, originalText; | ||
int lineSpacingInPoints, previousCountNextLine = 0, previousEnd = -1; |
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.
Initializing to 0 is pointless and actually generates more byte code.
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.
Updated initialization as part of constructor.
case '\t': | ||
item.tab = true; | ||
break; | ||
if(ch == '\r' && (start+1 < end)) { |
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 formatting of if(
is poor. The () around the < condition is redundant and odd that it's not used for the == test
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.
corrected it.
loop = previousEnd+1; | ||
else | ||
loop = previousEnd; | ||
for(int i = loop; i < end; i++) { |
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 for(
is not nice format.
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.
corrected it.
0740eef
to
26a2d76
Compare
this.originalText = text; | ||
String[] strings = text.split("\r"); | ||
text = ""; | ||
for(int i = 0; i < strings.length; i++) |
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 formatting of this for loop could also be improved.
e60de1d
to
223b000
Compare
this.originalText = text; | ||
String[] strings = text.split("\r"); | ||
text = ""; | ||
for (int i = 0; i < strings.length; i++) |
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.
This can be done using a map reduction. Anyway, please add braces to the for loop
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.
It's this a complicated and poorly performance way of doing test.replace("\r", "")?
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.
@merks yes, looks like it. Your approach is the best to me!
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.
let me test and update here back.
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 @merks for your feedback, after updating this i found a better way of fixing the issue. So new change is updated, you may please review now.
else | ||
loop = previousEnd; | ||
for (int i = loop; i < end; i++) { | ||
if (originalText.charAt(i) == '\r' && originalText.charAt(i+1) =='\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.
Is i + 1 necessarily < end?
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.
let me check 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.
you are correct, when string ends with \r, it is resulting OOB exception. So corrected it.
223b000
to
4f760cf
Compare
79bb600
to
52e92e2
Compare
@niraj-modi @merks @laeubi @Wittmaxi : Do you have any additional comments on this fix? or are we good to merge this? |
2e2b765
to
4d7e7e8
Compare
4d7e7e8
to
48b7ea7
Compare
Could you please squash this to a single commit? |
48b7ea7
to
e500d29
Compare
Done. |
e500d29
to
d53e86e
Compare
Font font2 = new Font(shell.getDisplay(), fontData2); | ||
|
||
final TextLayout layout = new TextLayout(display); | ||
//layout.setText(text); |
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.
Looks good, but why is there this much commented-out code?
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.
Those are the various test cases tried and the respective outputs against them, if required anyone can rerun depending on their need so i have retained in commented section. The possible combinations i can think of with \r and \n are put in the string, out of which 3 test cases are showcased in this snippet.
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.
Looks good, but why is there this much commented-out code?
Apart from the manual test case, the fix is reviewed and approved? do you mean that?
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.
Deepika please remove the comment code and update the PR
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.
Done.
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, looks good now :)
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 alot for the review.
3f1ae4a
to
6bf85bb
Compare
6bf85bb
to
c378aa1
Compare
@merks : All review suggestions are implemented, can you take a look please? if it can be approved. |
c378aa1
to
b5dc868
Compare
Wouldn't it be better for there to be actual tests that run with every build? |
Apart from this manual test(tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Issue184_CarriageReturnHandled.java) which is already added, please let me know what else needs to be done, so that this can be taken forward. Can you point me to a sample kind of instance? to refer. |
8b4764a
to
63a46d7
Compare
@merks : I have added some junits for the fix. Can you check now please? |
is this only an issue on Windows? May the macOS and Linux implementation have the same issue? |
@BeckerWdf : Atleast from the parent #184 => this is marked as only windows issue and i have implemented the fix only for windows. In the past i remember vaguely but when tested with mac, the behavior on mac Vs behavior on windows (before the fix) were different. So took it up as windows specific issue. |
Thanks. |
63a46d7
to
048b496
Compare
@merks : |
048b496
to
e05f6fc
Compare
@merks |
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.
It looks okay to me.
That being said, I would prefer that at least one other person deeply involved in SWT reviews this too.
Do you know who else might be good to review this? |
@sratz @jukzi @laeubi @HeikoKlare |
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 have not worked on TextLayout so far. Thus, unfortunately, I cannot say with high confidence whether the overall change is okay. Still, from what I understand, the conceptual change and the code for it looks sound to me. I've tested the proposed change with the snippet in the original issue and it indeed fixes it.
I have remarks regarding the automated and manual test. In particular the automated test does not seem to be an adequate regression test, as the same test succeeds on master
, thus it does not seem to cover the addressed issue.
@@ -0,0 +1,68 @@ | |||
package org.eclipse.swt.tests.manual; |
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 add missing copyright header
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.
Updated.
TextStyle style3 = new TextStyle(font2, null, null); | ||
layout.setStyle(style3, 21, 24); // iri in bold | ||
|
||
int[] offsets = layout.getLineOffsets(); |
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.
This variable is unused and thus produces a warning. It should be safe to just delete this line of code.
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.
Removed.
@@ -547,6 +547,60 @@ public void test_setStyle() { | |||
assertNull(layout.getStyle(4)); | |||
assertNull(layout.getStyle(5)); | |||
layout.dispose(); | |||
|
|||
layout = new TextLayout (display); |
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 test with these changes succeeds on master, so it's not a regression test for the changes made in this PR. Can you adapt the test so that it serves as a regression test for the addressed issue?
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 we have not changed the behavior of the api's. The original behavior of the api's still work the same. We are internally detecting, correcting and passing the corrected content in specific cases only. We dint even add new api's. It is only the look and feel by which you can make out if some extra lines are expected or not expected varies. - is my understanding.
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.
Okay, I mistakenly expected the added test to be a regression test for the fix because of #1320 (comment)
Still, this change is no refactoring but affects the behavior of public APIs (e.g., TextLayout#draw(...)
behaves differently). I guess that, e.g., also TextLayout#getBounds()
now behaves differently, so wouldn't it be possible to have a regression test comparing the bounds of two configurations that should actually result in the bounds but did not do before this change (or vice versa)?
And one additional remark: since the |
e05f6fc
to
c368f7f
Compare
sequence comes. Added some junit tests as well. Updated getStyle() and setStyle() accordingly. Fixes eclipse-platform#184
c368f7f
to
514957c
Compare
Thanks for your opinion. Since it is already tested now by various people, i feel we are safe to merge this. Considering the M3 deadline is 8th Nov(2 weeks far and not away like 2days or so) and we can give it a try. If something is breaking we'll revert it immediately and rectify to make it to next M1? Atleast this risk we can take to improve SWT - i feel so in particularly such long standing issues when they passed all the stages of fixing, review, successfully verified. |
Corrected TextLayout to produce right number of lines when '\r\n' sequence comes.
Fixes #184
@sravanlakkimsetti
@niraj-modi
@merks
Can one of you review this fix please.