Skip to content

Commit 8a0a94f

Browse files
committed
improve the edit detection
1 parent 644f340 commit 8a0a94f

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

src/lib/enhancers/github/GitHubEditEnhancer.tsx

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,29 @@ export class GitHubEditEnhancer implements CommentEnhancer<GitHubEditSpot> {
2222
return null
2323
}
2424

25-
// Only enhance textareas that are for editing issue/PR body
26-
const isIssueBodyEdit = textarea.closest('.react-issue-body') // this works for root and appended comments
27-
const isPRBodyEdit =
28-
textarea.name === 'pull_request[body]' || textarea.name === 'issue_comment[body]'
29-
// ^this is the root pr comment ^this is the other pr comments (surprising!)
30-
31-
// Also detect comment editing textareas (have "Update comment" button)
32-
// Look for "Update comment" button in the same container as the textarea
33-
const container =
34-
textarea.closest('[class*="markdown"], [class*="comment"], .js-comment-edit-form') ||
35-
textarea.closest('form') ||
36-
textarea.parentElement?.parentElement?.parentElement
37-
const buttons = container ? Array.from(container.querySelectorAll('button')) : []
38-
const isCommentEdit = buttons.some((btn) => btn.textContent?.includes('Update comment'))
39-
40-
if (!isIssueBodyEdit && !isPRBodyEdit && !isCommentEdit) {
41-
return null
42-
}
43-
4425
// Parse GitHub URL structure: /owner/repo/issues/123 or /owner/repo/pull/456
4526
const match = location.pathname.match(/^\/([^/]+)\/([^/]+)\/(?:issues|pull)\/(\d+)/)
4627
if (!match) {
4728
return null
4829
}
49-
5030
const [, owner, repo, numberStr] = match
5131
const number = parseInt(numberStr!, 10)
5232
const unique_key = `github.com:${owner}/${repo}:${number}:edit-body`
5333

34+
// Only enhance textareas that are for editing issue/PR body
35+
const isIssueBodyRootEdit = textarea.closest('.react-issue-body')
36+
const isIssueBodyCommentEdit = textarea.closest('[data-wrapper-timeline-id]')
37+
const isPRBodyEdit =
38+
textarea.name === 'pull_request[body]' || textarea.name === 'issue_comment[body]'
39+
// ^this is the root pr comment ^this is the other pr comments (surprising!)
40+
41+
if (!isIssueBodyRootEdit && !isIssueBodyCommentEdit && !isPRBodyEdit) {
42+
return null
43+
}
44+
5445
logger.debug(`${this.constructor.name} enhanced issue/PR body textarea`, unique_key)
5546
return {
56-
isIssue: !!isIssueBodyEdit,
47+
isIssue: !!(isIssueBodyRootEdit || isIssueBodyCommentEdit),
5748
type: GH_EDIT,
5849
unique_key,
5950
}

tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ exports[`github detection > gh_issue_edit_multiple:should detect correct spots 1
5353
{
5454
"for": "id=:r8k: name=null className=prc-Textarea-TextArea-13q4j focus-visible overtype-input",
5555
"spot": {
56-
"isIssue": false,
56+
"isIssue": true,
5757
"type": "GH_EDIT",
5858
"unique_key": "github.com:diffplug/testing-deletable:3:edit-body",
5959
},

0 commit comments

Comments
 (0)