Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 8ce9221

Browse files
committed
Merge pull request #8282 from le717/issue-8216
Truncate extension descriptions
2 parents f4d1e71 + 2bd4f7b commit 8ce9221

7 files changed

Lines changed: 106 additions & 22 deletions

File tree

src/extensibility/ExtensionManager.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,31 @@ define(function (require, exports, module) {
575575
}, []);
576576
}
577577

578+
/**
579+
* Toggles between truncated and full length extension descriptions
580+
* @param {string} id The id of the extension clicked
581+
* @param {JQueryElement} $element The DOM element of the extension clicked
582+
* @param {boolean} showFull true if full length description should be shown, false for shorten version.
583+
*/
584+
function toggleDescription(id, $element, showFull) {
585+
var description, linkTitle,
586+
entry = extensions[id];
587+
588+
// Toggle between appropriate descriptions and link title,
589+
// depending on if extension is installed or not
590+
if (showFull) {
591+
description = entry.installInfo ? entry.installInfo.metadata.description : entry.registryInfo.metadata.description;
592+
linkTitle = Strings.VIEW_TRUNCATED_DESCRIPTION;
593+
} else {
594+
description = entry.installInfo ? entry.installInfo.metadata.shortdescription : entry.registryInfo.metadata.shortdescription;
595+
linkTitle = Strings.VIEW_COMPLETE_DESCRIPTION;
596+
}
597+
598+
$element.attr("data-toggle-desc", showFull ? "trunc-desc" : "expand-desc")
599+
.attr("title", linkTitle)
600+
.prev(".ext-full-description").html(description);
601+
}
602+
578603
// Listen to extension load and loadFailed events
579604
$(ExtensionLoader)
580605
.on("load", _handleExtensionLoad)
@@ -600,7 +625,7 @@ define(function (require, exports, module) {
600625
exports.updateExtensions = updateExtensions;
601626
exports.getAvailableUpdates = getAvailableUpdates;
602627
exports.cleanAvailableUpdates = cleanAvailableUpdates;
603-
628+
exports.toggleDescription = toggleDescription;
604629
exports.ENABLED = ENABLED;
605630
exports.START_FAILED = START_FAILED;
606631

src/extensibility/ExtensionManagerView.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ define(function (require, exports, module) {
3535
InstallExtensionDialog = require("extensibility/InstallExtensionDialog"),
3636
LocalizationUtils = require("utils/LocalizationUtils"),
3737
itemTemplate = require("text!htmlContent/extension-manager-view-item.html");
38-
38+
3939
/**
4040
* Creates a view enabling the user to install and manage extensions. Must be initialized
4141
* with initialize(). When the view is closed, dispose() must be called.
@@ -110,7 +110,7 @@ define(function (require, exports, module) {
110110
* The individual views for each item, keyed by the extension ID.
111111
*/
112112
ExtensionManagerView.prototype._itemViews = null;
113-
113+
114114
/**
115115
* @private
116116
* Attaches our event handlers. We wait to do this until we've fully fetched the extension list.
@@ -154,6 +154,10 @@ define(function (require, exports, module) {
154154
ExtensionManager.markForRemoval($target.attr("data-extension-id"), true);
155155
} else if ($target.hasClass("undo-update")) {
156156
ExtensionManager.removeUpdate($target.attr("data-extension-id"));
157+
} else if ($target.attr("data-toggle-desc") === "expand-desc") {
158+
ExtensionManager.toggleDescription($target.attr("data-extension-id"), $target, true);
159+
} else if ($target.attr("data-toggle-desc") === "trunc-desc") {
160+
ExtensionManager.toggleDescription($target.attr("data-extension-id"), $target, false);
157161
}
158162
})
159163
.on("click", "button.install", function (e) {
@@ -206,7 +210,11 @@ define(function (require, exports, module) {
206210
// (or registry is offline). These flags *should* always be ignored in that scenario, but just in case...
207211
context.isCompatible = context.isCompatibleLatest = true;
208212
}
209-
213+
214+
if (info.metadata.description !== undefined) {
215+
info.metadata.shortdescription = StringUtils.truncate(info.metadata.description, 200);
216+
}
217+
210218
context.isMarkedForRemoval = ExtensionManager.isMarkedForRemoval(info.metadata.name);
211219
context.isMarkedForUpdate = ExtensionManager.isMarkedForUpdate(info.metadata.name);
212220

src/htmlContent/extension-manager-view-item.html

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,25 @@
2626
{{/isCompatibleLatest}}
2727
{{/isCompatible}}
2828
{{/showInstallButton}}
29-
{{metadata.description}}
30-
{{^metadata.description}}
31-
<p class="muted"><em>{{Strings.EXTENSION_NO_DESCRIPTION}}</em></p>
32-
{{/metadata.description}}
29+
<span class="ext-full-description">
30+
{{#metadata.shortdescription}}
31+
{{metadata.shortdescription}}
32+
{{/metadata.shortdescription}}
33+
{{^metadata.shortdescription}}
34+
{{#metadata.description}}
35+
{{metadata.description}}
36+
{{/metadata.description}}
37+
{{^metadata.description}}
38+
<p class="muted"><em>{{Strings.EXTENSION_NO_DESCRIPTION}}</em></p>
39+
{{/metadata.description}}
40+
{{/metadata.shortdescription}}
41+
</span>
42+
{{#metadata.shortdescription}}
43+
<a data-extension-id="{{metadata.name}}" data-toggle-desc="expand-desc" title="{{Strings.VIEW_COMPLETE_DESCRIPTION}}" href="#">...</a>
44+
{{/metadata.shortdescription}}
3345
{{#metadata.homepage}}
3446
<p><a title="{{metadata.homepage}}" href="{{metadata.homepage}}">{{Strings.EXTENSION_MORE_INFO}}</a></p>
3547
{{/metadata.homepage}}
36-
{{#metadata.keywords.length}}
37-
<br/>
38-
<span class="ext-keywords">{{Strings.EXTENSION_KEYWORDS}}:
39-
{{#metadata.keywords}}
40-
{{.}}
41-
{{/metadata.keywords}}
42-
</span>
43-
{{/metadata.keywords.length}}
4448
{{#translated}}
4549
<br/>
4650
<span class="ext-translated" title="{{translatedLangs}}">{{extensionTranslated}}</span>

src/nls/root/strings.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,8 @@ define({
448448
"CANCELING_INSTALL" : "Canceling\u2026",
449449
"CANCELING_HUNG" : "Canceling the install is taking a long time. An internal error may have occurred.",
450450
"INSTALL_CANCELED" : "Installation canceled.",
451+
"VIEW_COMPLETE_DESCRIPTION" : "View complete description",
452+
"VIEW_TRUNCATED_DESCRIPTION" : "View truncated description",
451453
// These must match the error codes in ExtensionsDomain.Errors.* :
452454
"INVALID_ZIP_FILE" : "The downloaded content is not a valid zip file.",
453455
"INVALID_PACKAGE_JSON" : "The package.json file is not valid (error was: {0}).",

src/styles/brackets_patterns_override.less

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -972,9 +972,6 @@ a[href^="http"] {
972972
.user-select(text);
973973
cursor: text;
974974
}
975-
.ext-keywords {
976-
color: @tc-input-placeholder-text;
977-
}
978975
.ext-translated {
979976
color: @tc-input-placeholder-text;
980977
}

src/utils/StringUtils.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,27 @@ define(function (require, exports, module) {
198198
return returnVal;
199199
}
200200

201+
/**
202+
* Truncate strings to specified length.
203+
* @param {string} str Text to be truncated.
204+
* @param {number} len Length to which text should be limited.
205+
* @return {string} Returns truncated text only if it was changed.
206+
*/
207+
function truncate(str, len) {
208+
// Truncate the description if it is too long
209+
if (str.length > len) {
210+
str = str.substr(0, len);
211+
212+
// To prevent awkward addition of ellipsis, try to truncate
213+
// at the end of the last whole word
214+
var lastSpaceChar = str.lastIndexOf(" ");
215+
if (lastSpaceChar < len && lastSpaceChar > -1) {
216+
str = str.substr(0, lastSpaceChar);
217+
}
218+
return str;
219+
}
220+
}
221+
201222
// Define public API
202223
exports.format = format;
203224
exports.htmlEscape = htmlEscape;
@@ -209,4 +230,5 @@ define(function (require, exports, module) {
209230
exports.breakableUrl = breakableUrl;
210231
exports.endsWith = endsWith;
211232
exports.prettyPrintBytes = prettyPrintBytes;
233+
exports.truncate = truncate;
212234
});

test/spec/ExtensionManager-test.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,7 @@ define(function (require, exports, module) {
770770

771771
// Simple fields
772772
[item.metadata.version,
773-
item.metadata.author && item.metadata.author.name,
774-
item.metadata.description]
773+
item.metadata.author && item.metadata.author.name]
775774
.forEach(function (value) {
776775
if (value) {
777776
expect(view).toHaveText(value);
@@ -782,7 +781,7 @@ define(function (require, exports, module) {
782781
}
783782

784783
// Array-valued fields
785-
[item.metadata.keywords, item.metadata.categories].forEach(function (arr) {
784+
[item.metadata.categories].forEach(function (arr) {
786785
if (arr) {
787786
arr.forEach(function (value) {
788787
expect(view).toHaveText(value);
@@ -793,6 +792,33 @@ define(function (require, exports, module) {
793792
});
794793
});
795794

795+
it("should display original description", function () {
796+
setupViewWithMockData(ExtensionManagerViewModel.RegistryViewModel);
797+
runs(function () {
798+
_.forEach(mockRegistry, function (item) {
799+
if (item.metadata.description) {
800+
if (StringUtils.truncate(item.metadata.description, 200) === undefined) {
801+
expect(view).toHaveText(item.metadata.description);
802+
}
803+
}
804+
});
805+
});
806+
});
807+
808+
it("should display shortened description", function () {
809+
setupViewWithMockData(ExtensionManagerViewModel.RegistryViewModel);
810+
runs(function () {
811+
_.forEach(mockRegistry, function (item) {
812+
if (item.metadata.description) {
813+
var shortDescription = StringUtils.truncate(item.metadata.description, 200);
814+
if (shortDescription !== undefined) {
815+
expect(view).toHaveText(shortDescription);
816+
}
817+
}
818+
});
819+
});
820+
});
821+
796822
it("should display owner even for installed items", function () {
797823
ExtensionManager._setExtensions(JSON.parse(mockExtensionList));
798824
setupViewWithMockData(ExtensionManagerViewModel.InstalledViewModel);

0 commit comments

Comments
 (0)