feat: add move up/down functionality for alternate greetings (#4676) * feat: add move up/down functionality for alternate greetings * Remove disabled cursor style

5c62c3a90d44f1692be75433f9277368b7ad7426

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
3 files changed, +63 -4Showing whitespace changes
public/index.html+8 -1
@@ -7216,11 +7216,18 @@
72167216 <div class="alternate_greeting">
72177217 <details open>
72187218 <summary>
72197219 <div class="title_restorable gap5px">
72207220 <div class="flex-container alignItemsCenter">
72217221 <strong><span data-i18n="Alternate Greeting #">Alternate Greeting #</span><span class="greeting_index"></span></strong>
72227222 <i class="editor_maximize fa-solid fa-maximize right_menu_button" title="Expand the editor" data-i18n="[title]Expand the editor"></i>
72237223 </div>
7224+ <span class="expander"></span>
7225+ <div class="menu_button menu_button_icon move_up_alternate_greeting" title="Move up" data-i18n="[title]Move up">
7226+ <i class="fa-solid fa-chevron-up"></i>
7227+ </div>
7228+ <div class="menu_button menu_button_icon move_down_alternate_greeting" title="Move down" data-i18n="[title]Move down">
7229+ <i class="fa-solid fa-chevron-down"></i>
7230+ </div>
72247231 <div class="menu_button menu_button_icon delete_alternate_greeting">
72257232 <i class="fa-solid fa-trash-alt"></i>
72267233 <span data-i18n="Delete">Delete</span>
public/script.js+47 -2
@@ -8450,6 +8450,8 @@ function openAlternateGreetings() {
84508450 array.push('');
84518451 addAlternateGreeting(template, '', index, getArray, popup);
84528452 updateAlternateGreetingsHintVisibility(template);
8453+ const list = template.find('.alternate_greetings_list');
8454+ list.scrollTop(list.prop('scrollHeight'));
84538455 });
84548456
84558457 popup.show();
@@ -8466,6 +8468,7 @@ function openAlternateGreetings() {
84668468 */
84678469function addAlternateGreeting(template, greeting, index, getArray, popup) {
84688470 const greetingBlock = $('#alternate_greeting_form_template .alternate_greeting').clone();
8471+ greetingBlock.attr('data-index', index);
84698472 greetingBlock.find('.alternate_greeting_text')
84708473 .attr('id', `alternate_greeting_${index}`)
84718474 .on('input', async function () {
@@ -8479,15 +8482,57 @@ function addAlternateGreeting(template, greeting, index, getArray, popup) {
84798482 event.preventDefault();
84808483 event.stopPropagation();
84818484
84828485 ifconst (confirm = await callGenericPopup(t`Are you sure you want to delete this alternate greeting?`)), {POPUP_TYPE.CONFIRM);
8486+ if (!confirm) {
8487+ return;
8488+ }
8489+
84838490 const array = getArray();
84848491 array.splice(index, 1);
84858492
84868493 // We need to reopen the popup to update the index numbers
84878494 await popup.complete(POPUP_RESULT.AFFIRMATIVE);
84888495 openAlternateGreetings();
8489- }
84908496 });
8497+ greetingBlock.find('.move_up_alternate_greeting').on('click', function (event) {
8498+ handleMoveAlternateGreeting(event, -1);
8499+ });
8500+ greetingBlock.find('.move_down_alternate_greeting').on('click', function (event) {
8501+ handleMoveAlternateGreeting(event, 1);
8502+ });
8503+
8504+ /**
8505+ * Handles moving an alternate greeting up or down in the list.
8506+ * @param {JQuery.ClickEvent} event - The click event
8507+ * @param {number} direction - Direction to move: -1 for up, 1 for down
8508+ */
8509+ function handleMoveAlternateGreeting(event, direction) {
8510+ event.preventDefault();
8511+ event.stopPropagation();
8512+
8513+ const array = getArray();
8514+ const index = Number(greetingBlock.attr('data-index'));
8515+ const newIndex = index + direction;
8516+
8517+ // Check bounds
8518+ if (direction === -1 && index <= 0) {
8519+ return;
8520+ }
8521+ if (direction === 1 && index >= array.length - 1) {
8522+ return;
8523+ }
8524+
8525+ // Swap the greetings
8526+ [array[index], array[newIndex]] = [array[newIndex], array[index]];
8527+
8528+ // Update current greeting
8529+ greetingBlock.find('.alternate_greeting_text').val(array[index]);
8530+
8531+ // Update adjacent greeting
8532+ const adjacentGreetingBlock = template.find(`.alternate_greeting[data-index="${newIndex}"]`);
8533+ adjacentGreetingBlock.find('.alternate_greeting_text').val(array[newIndex]);
8534+ }
8535+
84918536 template.find('.alternate_greetings_list').append(greetingBlock);
84928537}
84938538
public/style.css+8 -1
@@ -3464,10 +3464,17 @@ grammarly-extension {
34643464 padding: 2px;
34653465}
34663466
3467+.alternate_greeting:first-of-type .move_up_alternate_greeting,
3468+.alternate_greeting:last-of-type .move_down_alternate_greeting {
3469+ filter: brightness(75%) grayscale(1);
3470+ opacity: 0.5;
3471+ pointer-events: none;
3472+}
3473+
34673474.alternate_greeting summary {
34683475 list-style-position: outside;
34693476 margin-left: 1em;
34703477 padding-left: 1em5px;
34713478}
34723479
34733480.alternate_greeting textarea {