Skip to content

Commit b082c5a

Browse files
committed
feat: made description and file extension input as optional
1 parent 183f422 commit b082c5a

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

src/extensionsIntegrated/CustomSnippets/htmlContent/snippets-panel.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@
8080

8181
<div id="desc-box-wrapper">
8282
<label for="desc-box"
83-
title="Brief description of what this snippet does (e.g., 'console log shortcut', 'function template')."
83+
title="Brief description of what this snippet does. Leave empty if no description needed."
8484
data-placement="top">
85-
Description:
85+
Description (optional):
8686
</label>
87-
<input id="desc-box" type="text" placeholder="console log shortcut" autocomplete="off" />
87+
<input id="desc-box" type="text" placeholder="console log shortcut (optional)" autocomplete="off" />
8888
</div>
8989
</div>
9090

@@ -99,11 +99,11 @@
9999

100100
<div id="file-extn-box-wrapper">
101101
<label for="file-extn-box"
102-
title="Specify file types where this snippet should be available (e.g., '.js', '.html', '.css') or 'all' for all files."
102+
title="Specify file types where this snippet should be available (e.g., '.js', '.html', '.css'). Leave empty to make it available for all files."
103103
data-placement="top">
104-
File Extension:
104+
File Extension (optional):
105105
</label>
106-
<input id="file-extn-box" type="text" placeholder=".js, .html or all" autocomplete="off" />
106+
<input id="file-extn-box" type="text" placeholder="Leave empty for all files, or specify like .js, .html" autocomplete="off" />
107107
</div>
108108

109109
<div id="save-custom-snippet-btn">

src/extensionsIntegrated/CustomSnippets/main.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ define(function (require, exports, module) {
130130
});
131131

132132
$abbrInput.on("input", Helper.toggleSaveButtonDisability);
133-
$descInput.on("input", Helper.toggleSaveButtonDisability);
134133
$templateInput.on("input", Helper.toggleSaveButtonDisability);
135134

136135
$fileExtnInput.on("input", function () {

src/extensionsIntegrated/CustomSnippets/src/helper.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ define(function (require, exports, module) {
1717

1818
return {
1919
abbreviation: abbreviation,
20-
description: description,
20+
description: description || "", // allow empty description
2121
templateText: templateText,
22-
fileExtension: fileExtension
22+
fileExtension: fileExtension || "all" // default to "all" if empty
2323
};
2424
}
2525

@@ -30,20 +30,17 @@ define(function (require, exports, module) {
3030
* this is called inside the '_registerHandlers' function in the main.js file
3131
*/
3232
function toggleSaveButtonDisability() {
33-
// these are the required fields
33+
// abbreviation and template text are required fields
34+
// they both should have some value only then save button will be enabled
3435
const $abbrInput = $("#abbr-box");
35-
const $descInput = $("#desc-box");
3636
const $templateInput = $("#template-text-box");
37-
const $fileExtnInput = $("#file-extn-box");
3837

3938
const $saveBtn = $("#save-custom-snippet-btn").find("button");
4039

4140
// make sure that the required fields has some value
4241
const hasAbbr = $abbrInput.val().trim().length > 0;
43-
const hasDesc = $descInput.val().trim().length > 0;
4442
const hasTemplate = $templateInput.val().trim().length > 0;
45-
const hasFileExtn = $fileExtnInput.val().trim().length > 0;
46-
$saveBtn.prop("disabled", !(hasAbbr && hasDesc && hasTemplate && hasFileExtn));
43+
$saveBtn.prop("disabled", !(hasAbbr && hasTemplate));
4744
}
4845

4946
/**

src/extensionsIntegrated/CustomSnippets/src/snippetsList.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/*
32
* This file handles the display and management of the snippets list that is shown in the UI
43
* Note: when there are no snippets present, a message like no snippets are added yet is shown. refer to the html file
@@ -34,9 +33,18 @@ define(function (require, exports, module) {
3433
.attr("title", `Template: ${snippetItem.templateText}`);
3534

3635
const $snippetDescription = $("<div>")
37-
.text(snippetItem.description || "No description")
36+
.text(
37+
snippetItem.description && snippetItem.description.trim() !== ""
38+
? snippetItem.description
39+
: "No description"
40+
)
3841
.attr("id", "snippet-description")
39-
.attr("title", `Description: ${snippetItem.description}`);
42+
.attr(
43+
"title",
44+
snippetItem.description && snippetItem.description.trim() !== ""
45+
? `Description: ${snippetItem.description}`
46+
: "No description provided"
47+
);
4048

4149
const $snippetFiles = $("<div>")
4250
.text(snippetItem.fileExtension || "all")
@@ -90,7 +98,7 @@ define(function (require, exports, module) {
9098
UIHelper.showSnippetsListHeader(); // show header when there are snippets to display
9199

92100
// add each filtered snippet to the list
93-
filteredSnippets.forEach(function(snippetItem) {
101+
filteredSnippets.forEach(function (snippetItem) {
94102
_createSnippetItem(snippetItem);
95103
});
96104
}

0 commit comments

Comments
 (0)