Skip to content

Commit ffbaa24

Browse files
committed
fix: empty snippets were getting added when save button was clicked with no values
1 parent 4eca9e7 commit ffbaa24

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

src/extensionsIntegrated/CustomSnippets/src/driver.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ define(function (require, exports, module) {
1313
*/
1414
function handleSaveBtnClick() {
1515
const snippetData = Helper.getSnippetData();
16+
17+
if (!snippetData.abbreviation || !snippetData.abbreviation.trim()) {
18+
return;
19+
}
20+
if (!snippetData.templateText || !snippetData.templateText.trim()) {
21+
return;
22+
}
23+
1624
if (shouldAddSnippetToList(snippetData)) {
1725
Global.SnippetHintsList.push(snippetData);
1826
Helper.clearAllInputFields();
@@ -36,6 +44,13 @@ define(function (require, exports, module) {
3644
const originalSnippet = $editView.data("originalSnippet");
3745
const snippetIndex = $editView.data("snippetIndex");
3846

47+
if (!editedData.abbreviation || !editedData.abbreviation.trim()) {
48+
return;
49+
}
50+
if (!editedData.templateText || !editedData.templateText.trim()) {
51+
return;
52+
}
53+
3954
// check if abbreviation changed and if new abbreviation already exists
4055
if (editedData.abbreviation !== originalSnippet.abbreviation) {
4156
const existingSnippet = Global.SnippetHintsList.find(

src/extensionsIntegrated/CustomSnippets/src/helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ define(function (require, exports, module) {
3535
const $abbrInput = $("#abbr-box");
3636
const $templateInput = $("#template-text-box");
3737

38-
const $saveBtn = $("#save-custom-snippet-btn").find("button");
38+
const $saveBtn = $("#save-custom-snippet-btn button");
3939

4040
// make sure that the required fields has some value
4141
const hasAbbr = $abbrInput.val().trim().length > 0;

src/styles/Extn-CustomSnippets.less

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,21 @@
580580
.dark & {
581581
border-top: 1px solid @dark-bc-panel-separator;
582582
}
583+
584+
button:disabled {
585+
pointer-events: none !important;
586+
587+
&:hover,
588+
&:focus,
589+
&:active,
590+
&:visited {
591+
background: inherit !important;
592+
color: inherit !important;
593+
border-color: inherit !important;
594+
box-shadow: inherit !important;
595+
transform: none !important;
596+
}
597+
}
583598
}
584599
}
585600

@@ -745,5 +760,20 @@
745760
.dark & {
746761
border-top: 1px solid @dark-bc-panel-separator;
747762
}
763+
764+
button:disabled {
765+
pointer-events: none !important;
766+
767+
&:hover,
768+
&:focus,
769+
&:active,
770+
&:visited {
771+
background: inherit !important;
772+
color: inherit !important;
773+
border-color: inherit !important;
774+
box-shadow: inherit !important;
775+
transform: none !important;
776+
}
777+
}
748778
}
749779
}

0 commit comments

Comments
 (0)