Skip to content

Commit

Permalink
509163: Short description of different length in wizard vs. marketpla…
Browse files Browse the repository at this point in the history
…ce search

More accurate calculation for ellipsis: 
- clean up string before checking length
- avoid double ellipsis
- don't count promotion label towards cut-off

Bug: 509163
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=509163
  • Loading branch information
creckord committed Feb 1, 2017
1 parent ef9fddb commit d4d2eb8
Showing 1 changed file with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,21 @@ protected void createDescription(Composite parent) {
} else {
descriptionText = TextUtil.stripHtmlMarkup(descriptionText).trim();
}
descriptionText = descriptionText.replaceAll("(\\r\\n)|\\n|\\r|\\s{2,}", " "); //$NON-NLS-1$ //$NON-NLS-2$

String promotionLabel = null;
if (descriptionText.startsWith(Messages.DiscoveryItem_Promotion_Marker)) {
promotionLabel = Messages.DiscoveryItem_Promotion_Display;
descriptionText = promotionLabel + " - " //$NON-NLS-1$
+ descriptionText.substring(Messages.DiscoveryItem_Promotion_Marker.length());
maxDescriptionLength += promotionLabel.length() + 3;
}

boolean truncated = descriptionText.endsWith("..."); //$NON-NLS-1$
if (truncated) {
//avoid double elipsis
descriptionText = descriptionText.substring(0, descriptionText.length() - 3).trim();
}
if (descriptionText.length() > maxDescriptionLength) {
int truncationIndex = maxDescriptionLength;
for (int x = truncationIndex; x > 0; --x) {
Expand All @@ -251,13 +266,14 @@ protected void createDescription(Composite parent) {
}
descriptionText = descriptionText.substring(0, truncationIndex)
+ Messages.DiscoveryItem_truncatedTextSuffix;
truncated = true;
}
if (truncated && !descriptionText.endsWith(Messages.DiscoveryItem_truncatedTextSuffix)) {
descriptionText += Messages.DiscoveryItem_truncatedTextSuffix;
}
descriptionText = descriptionText.replaceAll("(\\r\\n)|\\n|\\r|\\s{2,}", " "); //$NON-NLS-1$ //$NON-NLS-2$
description.setText(descriptionText + " "); //$NON-NLS-1$
if (descriptionText.startsWith(Messages.DiscoveryItem_Promotion_Marker)) {
description.replaceTextRange(0, Messages.DiscoveryItem_Promotion_Marker.length(),
Messages.DiscoveryItem_Promotion_Display + " - "); //$NON-NLS-1$
StyleRange style = new StyleRange(0, Messages.DiscoveryItem_Promotion_Display.length(), null, null,
if (promotionLabel != null) {
StyleRange style = new StyleRange(0, promotionLabel.length(), null, null,
SWT.ITALIC | SWT.BOLD);
description.setStyleRange(style);
}
Expand Down

0 comments on commit d4d2eb8

Please sign in to comment.