diff --git a/source/features/cmd-enter.tsx b/source/features/cmd-enter.tsx index 5ade773cbe78..0da91271cef4 100644 --- a/source/features/cmd-enter.tsx +++ b/source/features/cmd-enter.tsx @@ -2,6 +2,7 @@ import delegate, {type DelegateEvent} from 'delegate-it'; import * as pageDetect from 'github-url-detection'; import {$, $optional} from 'select-dom'; +import {legacyCommentField} from '../github-helpers/selectors.js'; import features from '../feature-manager.js'; function handleKeyDown(event: DelegateEvent): void { @@ -19,7 +20,7 @@ function handleKeyDown(event: DelegateEvent): void { } function init(signal: AbortSignal): void { - delegate('#new_comment_field', 'keydown', handleKeyDown, {signal}); + delegate(legacyCommentField, 'keydown', handleKeyDown, {signal}); } void features.add(import.meta.url, { diff --git a/source/features/quick-mention.tsx b/source/features/quick-mention.tsx index e18c047937f7..44828ffb9549 100644 --- a/source/features/quick-mention.tsx +++ b/source/features/quick-mention.tsx @@ -7,15 +7,17 @@ import ReplyIcon from 'octicons-plain-react/Reply'; import {$, $closest, elementExists} from 'select-dom'; import {insertTextIntoField} from 'text-field-edit'; -import features from '../feature-manager.js'; import {getLoggedInUser, isArchivedRepoAsync} from '../github-helpers/index.js'; import {is} from '../helpers/css-selectors.js'; +import {legacyCommentField} from '../github-helpers/selectors.js'; import {wrap} from '../helpers/dom-utils.js'; import observe, {waitForElement} from '../helpers/selector-observer.js'; +import features from '../feature-manager.js'; -const prFieldSelector = 'textarea#new_comment_field'; -const issueFieldSelector = '#react-issue-comment-composer textarea'; -const fieldSelector = [prFieldSelector, issueFieldSelector] as const; +const fieldSelector = [ + legacyCommentField, + '#react-issue-comment-composer textarea', +] as const; const loggedInUser = getLoggedInUser()!; diff --git a/source/features/unwrap-unnecessary-dropdowns.tsx b/source/features/unwrap-unnecessary-dropdowns.tsx index ceaa39ea298b..971be5553c58 100644 --- a/source/features/unwrap-unnecessary-dropdowns.tsx +++ b/source/features/unwrap-unnecessary-dropdowns.tsx @@ -1,8 +1,12 @@ -import * as pageDetect from 'github-url-detection'; +import React from 'dom-chef'; +import CopilotIcon from 'octicons-plain-react/Copilot'; import {$, $$optional, $closest} from 'select-dom'; +import {setFieldText} from 'text-field-edit'; +import * as pageDetect from 'github-url-detection'; -import features from '../feature-manager.js'; +import {legacyCommentField} from '../github-helpers/selectors.js'; import observe from '../helpers/selector-observer.js'; +import features from '../feature-manager.js'; // Replace dropdown while keeping its sizing/positioning classes function replaceDropdownInPlace(dropdown: Element, form: Element): void { @@ -35,15 +39,88 @@ function replaceNotificationsDropdown(): void { button.textContent = `Group by ${button.textContent.toLowerCase()}`; } -function init(signal: AbortSignal): void { +function initNotifications(signal: AbortSignal): void { observe('.js-check-all-container > :first-child', replaceNotificationsDropdown, {signal}); } +function insertCopilotInstruction(): void { + const textarea = $(legacyCommentField); + setFieldText(textarea, '@copilot resolve the merge conflicts in this pull request'); +} + +function createButtonGroup(): JSX.Element { + const agentButtonId = crypto.randomUUID(); + const agentTooltipId = crypto.randomUUID(); + + return ( +
+
+ + + + Resolve conflicts + + + +
+
+ + +
+
+ ); +} + +function replaceResolveConflictsDropdown(button: HTMLButtonElement): void { + if (button.textContent.trim() !== 'Resolve conflicts') { + return; + } + + const buttonGroup = createButtonGroup(); + button.replaceWith(buttonGroup); +} + +function initPrConversation(signal: AbortSignal): void { + observe( + '[aria-label="Conflicts"] [class^="MergeBoxSectionHeader-module__wrapper"] button[data-component="Button"]', + replaceResolveConflictsDropdown, + {signal}, + ); +} + void features.add(import.meta.url, { include: [ pageDetect.isNotifications, ], - init, + init: initNotifications, +}, { + include: [ + pageDetect.isPRConversation, + ], + init: initPrConversation, }); /* @@ -51,5 +128,6 @@ void features.add(import.meta.url, { Test URLs: - https://github.com/notifications +- https://github.com/refined-github/sandbox/pull/82 */ diff --git a/source/github-helpers/selectors.ts b/source/github-helpers/selectors.ts index 9db4215c166d..130393ce331b 100644 --- a/source/github-helpers/selectors.ts +++ b/source/github-helpers/selectors.ts @@ -145,6 +145,10 @@ export const newCommentField = [ export const newCommentField_ = requiresLogin; +export const legacyCommentField = 'textarea#new_comment_field'; +// Used on: PR conversations, gists and discussions +export const legacyCommentField_ = requiresLogin; + export const commitHashLinkInLists = [ '[data-testid="commit-row-browse-repo"]', // `isCommitList` 'a[id^="commit-details-"]', // `isPRCommitList`