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

Tree.java: correctly escape & in default Tooltip #801

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Wittmaxi
Copy link

@Wittmaxi Wittmaxi commented Sep 5, 2023

Fix for
eclipse-platform/eclipse.platform.ui#238
eclipse-platform/eclipse.platform.ui#1075

grafik

When TreeColumn's are too small, a ToolTip is displayed on hover to reveal the whole Label of an Item (The WIN32-Docs call them In-Place Tooltips).
These ToolTips pass through the Composite-ToolTipText-generator which escapes all & in a Text - allowing to reuse Text from Buttons as Tooltips. This is a well documented Feature of setToolTipText. Since TreeItem's Label does not have Mnemonics, we do not assume that the & should require escaping by the User.

This Commit Escapes all & in default Tooltips that are handled by the default mechanism.

@Wittmaxi
Copy link
Author

Wittmaxi commented Sep 5, 2023

I am not sure wether using RegExes is an okay thing to do here.
I do not expect this method to be called a lot, hence why I am okay sacrificing a bit of Performance for better code clarity.

This bug might also exist in GTK- or Cocoa-based implementations. I suspect that they have similar fixes.

@@ -5639,7 +5639,8 @@ String toolTipText (NMTTDISPINFO hdr) {
if (findCell (pt.x, pt.y, item, index, cellRect, itemRect)) {
String text = null;
if (index [0] == 0) {
text = item [0].text;
text = new String(item [0].text);
text = text.replaceAll("&", "&&");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this needs to be replaceAll, where the first argument is interpreted as a regular expression rather than just a simple replace which also replaces all substrings using "literal" matching?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the feedback, I agree with you and changed my code accordingly

@github-actions
Copy link
Contributor

github-actions bot commented Sep 5, 2023

Test Results

0 files   -      299  0 suites   - 299   0s ⏱️ - 6m 7s
0 tests  -   4 090  0 ✔️  -   4 082  0 💤  -   8  0 ±0 
0 runs   - 12 182  0 ✔️  - 12 110  0 💤  - 72  0 ±0 

Results for commit 925be9e. ± Comparison against base commit d4a3dad.

♻️ This comment has been updated with latest results.

@Phillipus
Copy link
Contributor

Is that the right place to be changing the contents of the tooltip string? Something tells me that it's not, and perhaps ampersand escaping should be done further up the stack, or by the client.

@Wittmaxi
Copy link
Author

Wittmaxi commented Sep 5, 2023

@Phillipus Escaping the & definitely can't be done by the client since this ToolTip is automatically generated from the Text. I also don't think explicitly setting a ToolTip is a good idea since this ToolTip is only shown when the TreeColumn is too small - property that is checked for before drawing the ToolTip

@Phillipus
Copy link
Contributor

Phillipus commented Sep 5, 2023

@Phillipus Escaping the & definitely can't be done by the client since this ToolTip is automatically generated from the Text. I also don't think explicitly setting a ToolTip is a good idea since this ToolTip is only shown when the TreeColumn is too small - property that is checked for before drawing the ToolTip

Yeah, I can see the problem. It's just that when I look at the String toolTipText (NMTTDISPINFO hdr) code it seems to me to be the wrong place to actually change the string. But maybe there is no other place to change it.

Is this also happening on Mac and Linux? Edit - it's OK on Mac.

@@ -5639,7 +5639,8 @@ String toolTipText (NMTTDISPINFO hdr) {
if (findCell (pt.x, pt.y, item, index, cellRect, itemRect)) {
String text = null;
if (index [0] == 0) {
text = item [0].text;
text = new String(item [0].text);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is creating a new String necessary?

Copy link
Author

@Wittmaxi Wittmaxi Sep 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have addressed this issue. @Phillipus

This fixes eclipse-platform/eclipse.platform.ui#1075

When TreeColumn's are too small, a ToolTip is displayed on hover to
reveal the whole Label of an Item (The WIN32-Docs call them 'Inline
ToolTips').
These ToolTips pass through the Composite-ToolTipText-generator which
escapes all & in a Text - allowing to reuse Text from Buttons as
Tooltips. This is a well documented Feature of setToolTipText.
Since TreeItem's Label does not have Mnemonics, we do not assume that the
& needs escaping.

This Commit Escapes all & in default Tooltips that are handled by the
default mechanism.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants