-
Notifications
You must be signed in to change notification settings - Fork 184
Corrected TextLayout to produce right number of lines when '\r\n' sequence comes. #1320
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
Conversation
Anyone testing this pr can use the below snippet.
|
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java
Outdated
Show resolved
Hide resolved
} | ||
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
@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.
...lipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Issue184_CarriageReturnHandled.java
Outdated
Show resolved
Hide resolved
...lipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Issue184_CarriageReturnHandled.java
Outdated
Show resolved
Hide resolved
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)?
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.
@HeikoKlare
As per your suggestion i have added new junit tests with TextLayout#getLineCount()
and TextLayout#getBounds()
.
Since this change is only with respect to windows, i have excluded mac, gtk for the tests to run.
I guess this makes it all complete as we discussed. If i missed out any, please do let me know.
Can you review it and take it forward please?
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 hold on, let me cross check and update you again.
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.
Hi @HeikoKlare
Sorry for the confusion caused.
I am successfull in adding only TextLayout#getLineCount() junit. I think we can go ahead with this pr now.
I have tried even TextLayout#getBounds() but had to withdraw as the behavior is not consistent across.
With the sample input taken,
- On master, getBounds() is returning {0, 0, 30, 220} where width and height are 30, 220 respectively. [junit is failing]
- On the branch where i committed my changes(fix_for_issue184), getBounds() is returning {0, 0, 43, 140}. [junit is passing]
- To cross check, i have pulled the pr 1320 to local, getBounds() is returning {0, 0, 43, 140}. [junit is passing]
- But on the build machine, getBounds() is returning {0, 0, 34, 105}. [junit is failing because it is getting 34 but expecting 43]. -> https://github.com/eclipse-platform/eclipse.platform.swt/actions/runs/12312890737/job/34365830603?pr=1320
Neither able to understand the reason for the failure(to fix) nor able to replicate the problem locally to debug further.
Can you please check 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.
@HeikoKlare : Need your time to take this forward please?
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.
@HeikoKlare : Need your inputs here please?
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.
Thank you for adding the regression test. That one, testing getLineCount()
, makes even more sense to me for testing the fix than testing the changed result of getBounds()
. 👍
The PR is ready to go from my side.
Just a small final remark regarding the added test: I am just wondering whether it may not be even better to use different expected line count values for the different platforms in the test instead of excluding the test for GTK and Cocoa. Since the functionality is not broken or non-existent on those other platform but just produces expected different results, testing for those other results seems to be more comprehensible 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.
@HeikoKlare
Thanks for your time. I have updated them now, can you take a look now. Assuming everything is done, can you take this forward please.
And one additional remark: since the |
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. |
a3510b6
to
7f93fcd
Compare
8a34eda
to
af452c1
Compare
sequence comes. Added some junit tests as well. Updated getStyle() and setStyle() accordingly. Added failing and success junits again. Fixes eclipse-platform#184
af452c1
to
55dc1f3
Compare
This looks good now and we also have Ed's approval, thus merging. |
Verified this issue on below build. Number of lines: 7 |
This PR introduced a regression #1714, please fix. |
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.