Skip to content

Commit 2a12fd3

Browse files
committed
feat: replace reset button with cancel button in the edit snippets panel
1 parent 3191f02 commit 2a12fd3

File tree

4 files changed

+16
-44
lines changed

4 files changed

+16
-44
lines changed

src/extensionsIntegrated/CustomSnippets/driver.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,24 @@ define(function (require, exports, module) {
116116
}
117117

118118
/**
119-
* This function handles the reset button click for editing a snippet
120-
* It restores the original snippet data in the edit form
119+
* This function is responsible to handle the cancel button click in the edit-snippet panel
120+
* this resets the format to the last saved values and then moves back to the snippets-list panel
121121
*/
122-
function handleResetBtnClick() {
122+
function handleCancelEditBtnClick() {
123123
const $editView = $("#custom-snippets-edit");
124124
const originalSnippet = $editView.data("originalSnippet");
125125

126126
if (originalSnippet) {
127-
// restore original data in the form
127+
// restore original data in the form to reset any changes
128128
Helper.populateEditForm(originalSnippet);
129-
// update save button state
130-
Helper.toggleEditSaveButtonDisability();
131129
}
130+
131+
$editView.removeData("originalSnippet");
132+
$editView.removeData("snippetIndex");
133+
134+
// navigate back to snippets list
135+
UIHelper.showSnippetListMenu();
136+
SnippetsList.showSnippetsList();
132137
}
133138

134139
/**
@@ -183,5 +188,5 @@ define(function (require, exports, module) {
183188
exports.getWordBeforeCursor = getWordBeforeCursor;
184189
exports.handleSaveBtnClick = handleSaveBtnClick;
185190
exports.handleEditSaveBtnClick = handleEditSaveBtnClick;
186-
exports.handleResetBtnClick = handleResetBtnClick;
191+
exports.handleCancelEditBtnClick = handleCancelEditBtnClick;
187192
});

src/extensionsIntegrated/CustomSnippets/helper.js

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -479,38 +479,6 @@ define(function (require, exports, module) {
479479
const hasAbbr = $abbrInput.val().trim().length > 0;
480480
const hasTemplate = $templateInput.val().trim().length > 0;
481481
$saveBtn.prop("disabled", !(hasAbbr && hasTemplate));
482-
483-
// Also toggle the reset button state
484-
toggleResetButtonDisability();
485-
}
486-
487-
/**
488-
* This function checks if the snippet is in its default state and
489-
* disables the reset button if it is
490-
*/
491-
function toggleResetButtonDisability() {
492-
const $editView = $("#custom-snippets-edit");
493-
const originalSnippet = $editView.data("originalSnippet");
494-
const $resetBtn = $("#reset-snippet-btn");
495-
496-
if (!originalSnippet) {
497-
// If there's no original snippet data, disable the reset button
498-
$resetBtn.prop("disabled", true);
499-
return;
500-
}
501-
502-
// Get current values from the form
503-
const currentData = getEditSnippetData();
504-
505-
// Check if current values match original values
506-
const isDefault =
507-
currentData.abbreviation === originalSnippet.abbreviation &&
508-
currentData.description === (originalSnippet.description || "") &&
509-
currentData.templateText === originalSnippet.templateText &&
510-
currentData.fileExtension === originalSnippet.fileExtension;
511-
512-
// Disable reset button if in default state
513-
$resetBtn.prop("disabled", isDefault);
514482
}
515483

516484
/**
@@ -884,7 +852,6 @@ define(function (require, exports, module) {
884852
exports.populateEditForm = populateEditForm;
885853
exports.getEditSnippetData = getEditSnippetData;
886854
exports.toggleEditSaveButtonDisability = toggleEditSaveButtonDisability;
887-
exports.toggleResetButtonDisability = toggleResetButtonDisability;
888855
exports.clearEditInputFields = clearEditInputFields;
889856
exports.handleTextareaTabKey = handleTextareaTabKey;
890857
exports.validateAbbrInput = validateAbbrInput;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
</div>
164164

165165
<div id="edit-snippet-buttons">
166-
<button id="reset-snippet-btn" class="dialog-button btn">Reset</button>
166+
<button id="cancel-edit-snippet-btn" class="dialog-button btn">Cancel</button>
167167
<button id="save-edit-snippet-btn" class="dialog-button btn primary" disabled>Save</button>
168168
</div>
169169
</div>

src/extensionsIntegrated/CustomSnippets/main.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ define(function (require, exports, module) {
141141
const $editTemplateInput = $("#edit-template-text-box");
142142
const $editFileExtnInput = $("#edit-file-extn-box");
143143
const $saveEditSnippetBtn = $("#save-edit-snippet-btn");
144-
const $resetSnippetBtn = $("#reset-snippet-btn");
144+
const $cancelEditSnippetBtn = $("#cancel-edit-snippet-btn");
145145

146146
$addSnippetBtn.on("click", function () {
147147
UIHelper.showAddSnippetMenu();
@@ -237,8 +237,8 @@ define(function (require, exports, module) {
237237
Driver.handleEditSaveBtnClick();
238238
});
239239

240-
$resetSnippetBtn.on("click", function () {
241-
Driver.handleResetBtnClick();
240+
$cancelEditSnippetBtn.on("click", function () {
241+
Driver.handleCancelEditBtnClick();
242242
});
243243

244244
// filter input event handler

0 commit comments

Comments
 (0)