keydownNoteText()

in app/assets/javascripts/notes.js [228:280]


  keydownNoteText(e) {
    var $textarea,
      discussionNoteForm,
      editNote,
      myLastNote,
      myLastNoteEditBtn,
      newText,
      originalText;
    if (isMetaKey(e)) {
      return;
    }

    $textarea = $(e.target);
    // Edit previous note when UP arrow is hit
    switch (e.which) {
      case 38:
        if ($textarea.val() !== '') {
          return;
        }
        myLastNote = $(
          `li.note[data-author-id='${gon.current_user_id}'][data-editable]:last`,
          $textarea.closest('.note, .notes_holder, #notes'),
        );
        if (myLastNote.length) {
          myLastNoteEditBtn = myLastNote.find('.js-note-edit');
          return myLastNoteEditBtn.trigger('click', [true, myLastNote]);
        }
        break;
      // Cancel creating diff note or editing any note when ESCAPE is hit
      case 27:
        discussionNoteForm = $textarea.closest('.js-discussion-note-form');
        if (discussionNoteForm.length) {
          if ($textarea.val() !== '') {
            if (!window.confirm(__('Are you sure you want to cancel creating this comment?'))) {
              return;
            }
          }
          this.removeDiscussionNoteForm(discussionNoteForm);
          return;
        }
        editNote = $textarea.closest('.note');
        if (editNote.length) {
          originalText = $textarea.closest('form').data('originalNote');
          newText = $textarea.val();
          if (originalText !== newText) {
            if (!window.confirm(__('Are you sure you want to cancel editing this comment?'))) {
              return;
            }
          }
          return this.removeNoteEditForm(editNote);
        }
    }
  }