| 162 | } |
| 163 | |
| 164 | function handleMenuOpening({delegateTarget: menuButton}: DelegateEvent): void { |
| 165 | // Don't run if the menu has been closed |
| 166 | if (menuButton.ariaExpanded === 'false') { |
| 167 | return; |
| 168 | } |
| 169 | |
| 170 | // Track the file container for later removal |
| 171 | focusedFileContainer = closestElement('div[id^="diff-"]', menuButton); |
| 172 | |
| 173 | // Wait for the menu DOM to be created, but not rendered |
| 174 | requestAnimationFrame(() => { |
| 175 | const editFile = $('[class^="prc-ActionList-ActionListItem"]:has(.octicon-pencil)'); |
| 176 | const discardItem = editFile.cloneNode(true); |
| 177 | discardItem.classList.add('rgh-restore-file'); |
| 178 | const link = $('a', discardItem); |
| 179 | link.ariaKeyShortcuts = 'd'; |
| 180 | link.removeAttribute('href'); |
| 181 | link.removeAttribute('aria-labelledby'); |
| 182 | $('[class^="prc-ActionList-ItemLabel"]', discardItem).textContent = 'Discard changes'; |
| 183 | $('[class^="prc-ActionList-LeadingVisual"]', discardItem).replaceChildren(<UndoIcon />); |
| 184 | |
| 185 | editFile.after(discardItem); |
| 186 | }); |
| 187 | } |
| 188 | |
| 189 | async function init(signal: AbortSignal): Promise<void> { |
| 190 | // Legacy view |