import React from 'dom-chef'; import select from 'select-dom'; import {DelegateEvent} from 'delegate-it'; import * as pageDetect from 'github-url-detection'; import filterAlteredClicks from 'filter-altered-clicks'; import features from '../feature-manager.js'; import {onCommentFieldKeydown} from '../github-events/on-field-keydown.js'; function handleEscapeKey(event: DelegateEvent, targetField: HTMLTextAreaElement): void { // Cancel buttons have different classes for inline comments and editable comments const cancelButton = select(` button.js-hide-inline-comment-form, button.js-comment-cancel-button `, targetField.form!); // Cancel if there is a button, else blur the field if (cancelButton) { cancelButton.click(); } else { targetField.blur(); } event.stopImmediatePropagation(); event.preventDefault(); } function handleArrowUpKey(targetField: HTMLTextAreaElement): void { const currentConversationContainer = targetField.closest([ '.js-inline-comments-container', // Current review thread container '#discussion_bucket', // Or just ALL the comments in issues '#all_commit_comments', // Single commit comments at the bottom ])!; const lastOwnComment = select .all('.js-comment.current-user', currentConversationContainer) .reverse() .find(comment => { const collapsible = comment.closest('details'); return !collapsible || collapsible.open; }); if (!lastOwnComment) { return; } // Make the comment editable (the native edit button might not be available yet) const editButton =