From bc3c684607b4fc5c834f7b1039217af0e1f90b18 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 25 Sep 2025 11:16:05 -0700 Subject: [PATCH 1/5] When editing an existing comment, the necessary padding is different for issues than for prs. Also we weren't editing non-root comments on PRs, now we are. --- .../enhancers/github/GitHubEditEnhancer.tsx | 19 ++++++++++++------- .../__snapshots__/gh-detection.test.ts.snap | 2 ++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/lib/enhancers/github/GitHubEditEnhancer.tsx b/src/lib/enhancers/github/GitHubEditEnhancer.tsx index aff5c20..786535a 100644 --- a/src/lib/enhancers/github/GitHubEditEnhancer.tsx +++ b/src/lib/enhancers/github/GitHubEditEnhancer.tsx @@ -8,6 +8,7 @@ import { commonGitHubOptions, prepareGitHubHighlighter } from './github-common' const GH_EDIT = 'GH_EDIT' as const export interface GitHubEditSpot extends CommentSpot { + isIssue: boolean type: typeof GH_EDIT } @@ -22,9 +23,10 @@ export class GitHubEditEnhancer implements CommentEnhancer { } // Only enhance textareas that are for editing issue/PR body - const isIssueBodyEdit = textarea.closest('.react-issue-body') + const isIssueBodyEdit = textarea.closest('.react-issue-body') // this works for root and appended comments const isPRBodyEdit = - textarea.id?.match(/^issue-\d+-body$/) || textarea.name === 'pull_request[body]' + textarea.name === 'pull_request[body]' || textarea.name === 'issue_comment[body]' + // ^this is the root pr comment ^this is the other pr comments (surprising!) if (!isIssueBodyEdit && !isPRBodyEdit) { return null @@ -42,20 +44,23 @@ export class GitHubEditEnhancer implements CommentEnhancer { logger.debug(`${this.constructor.name} enhanced issue/PR body textarea`, unique_key) return { + isIssue: !!isIssueBodyEdit, type: GH_EDIT, unique_key, } } - enhance(textArea: HTMLTextAreaElement, _spot: GitHubEditSpot): OverTypeInstance { + enhance(textArea: HTMLTextAreaElement, spot: GitHubEditSpot): OverTypeInstance { prepareGitHubHighlighter() const overtypeContainer = modifyDOM(textArea) - return new OverType(overtypeContainer, { + const overtype = new OverType(overtypeContainer, { ...commonGitHubOptions, - minHeight: '102px', - padding: 'var(--base-size-8)', - placeholder: 'Add your comment here...', + padding: spot.isIssue ? 'var(--base-size-16)' : 'var(--base-size-8)', })[0]! + if (!spot.isIssue) { + // TODO: autoheight not working + } + return overtype } tableUpperDecoration(_spot: GitHubEditSpot): React.ReactNode { diff --git a/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap b/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap index 0e5891a..b903f76 100644 --- a/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap +++ b/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap @@ -21,6 +21,7 @@ exports[`github detection > gh_issue_edit:should detect correct spots 1`] = ` { "for": "id=:rc3: name=null className=prc-Textarea-TextArea-13q4j focus-visible overtype-input", "spot": { + "isIssue": true, "type": "GH_EDIT", "unique_key": "github.com:diffplug/gitcasso:56:edit-body", }, @@ -80,6 +81,7 @@ exports[`github detection > gh_pr_edit:should detect correct spots 1`] = ` { "for": "id=issue-3429313834-body name=pull_request[body] className=js-comment-field js-paste-markdown js-task-list-field js-quick-submit js-size-to-fit size-to-fit js-session-resumable CommentBox-input FormControl-textarea js-saved-reply-shortcut-comment-field focus-visible overtype-input", "spot": { + "isIssue": false, "type": "GH_EDIT", "unique_key": "github.com:diffplug/gitcasso:58:edit-body", }, From e0109ce434f15b3baf6a917876f5417fbfda7d5f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 25 Sep 2025 11:33:45 -0700 Subject: [PATCH 2/5] Add snapshots for the multi-edit case, which shows that actually edited non-root comments on issues are actually being registered as `GH_ISSUE_APPEND` --- tests/corpus/_corpus-index.ts | 14 +- tests/corpus/gh_issue_edit_multiple.html | 1532 ++++ tests/corpus/gh_pr_edit_multiple.html | 7501 +++++++++++++++++ .../__snapshots__/gh-detection.test.ts.snap | 72 + .../__snapshots__/gh-ui.test.ts.snap | 91 + 5 files changed, 9208 insertions(+), 2 deletions(-) create mode 100644 tests/corpus/gh_issue_edit_multiple.html create mode 100644 tests/corpus/gh_pr_edit_multiple.html diff --git a/tests/corpus/_corpus-index.ts b/tests/corpus/_corpus-index.ts index 156c547..592f198 100644 --- a/tests/corpus/_corpus-index.ts +++ b/tests/corpus/_corpus-index.ts @@ -14,10 +14,15 @@ export const CORPUS: Record = { }, // HAR corpus (initial page loads) gh_issue_edit: { - description: 'editing an existing comment on an issue', + description: 'edit an existing comment on an issue', type: 'html', url: 'https://github.com/diffplug/gitcasso/issues/56', }, + gh_issue_edit_multiple: { + description: 'edit an existing comment on an issue (root and appended)', + type: 'html', + url: 'https://github.com/diffplug/testing-deletable/issues/3', + }, gh_issue_new: { description: 'a new issue wiht some fields filled out', type: 'html', @@ -28,10 +33,15 @@ export const CORPUS: Record = { url: 'https://github.com/diffplug/selfie/pull/517', }, gh_pr_edit: { - description: 'editing an existing comment on a PR', + description: 'edit an existing comment on a PR', type: 'html', url: 'https://github.com/diffplug/gitcasso/pull/58', }, + gh_pr_edit_multiple: { + description: 'edit an existing comment on a PR (root and appended)', + type: 'html', + url: 'https://github.com/diffplug/testing-deletable/pull/5', + }, gh_pr_new: { type: 'har', url: 'https://github.com/diffplug/selfie/compare/main...cavia-porcellus:selfie:main?expand=1', diff --git a/tests/corpus/gh_issue_edit_multiple.html b/tests/corpus/gh_issue_edit_multiple.html new file mode 100644 index 0000000..ee1dcfc --- /dev/null +++ b/tests/corpus/gh_issue_edit_multiple.html @@ -0,0 +1,1532 @@ + + + + + + + + + + + + + + +Test 3 · Issue #3 · diffplug/testing-deletable + +
+
+ +
+ Skip to content + + + + + + + + +
+
+ + + + + + +
+
+
+ +
+ + + +
+
+
+ + + + + + + + + + + +

Test 3 #3

@cavia-porcellus

Description

Body input
Markdown input: edit mode selected.

Activity

cavia-porcellus

cavia-porcellus commented on Sep 24, 2025

Author

Okay, here is a comment that I will post for you

cavia-porcellus

cavia-porcellus commented on Sep 24, 2025

Author
Markdown Editor
Markdown input: edit mode selected.
cavia-porcellus

cavia-porcellus commented on Sep 24, 2025

Author

Let's try it.

cavia-porcellus

Add a comment

new Comment
Markdown input: edit mode selected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Notifications

        You're receiving notifications because you're subscribed to this thread.

        Participants

        @cavia-porcellus

        Issue actions

          +
          +
          +
          +
          +
          + + + + + + + + +
          +
          Test 3 · Issue #3 · diffplug/testing-deletable
          +
          4 results
          + + \ No newline at end of file diff --git a/tests/corpus/gh_pr_edit_multiple.html b/tests/corpus/gh_pr_edit_multiple.html new file mode 100644 index 0000000..3275532 --- /dev/null +++ b/tests/corpus/gh_pr_edit_multiple.html @@ -0,0 +1,7501 @@ + + + + + + + + + + +Update README.md by cavia-porcellus · Pull Request #5 · diffplug/testing-deletable + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          +
          + +
          + Skip to content + + + + + + + + +
          +
          + + + + + + +
          +
          +
          + +
          + + + +
          +
          +
          + + + + + + + + +
          + Open in github.dev + Open in a new github.dev tab + Open in codespace + + +
          +
          + +
          + + +
          + +
          + + +
          +
          +

          Conversation

          +
          + + +
          +
          +
          + cavia-porcellus + + +
          +
          +
          +
          +
          + + + + + + + + + + + + Copy link +
          +
          + + + + +
          +
          +
          +
          + + +
          +

          +
          + @cavia-porcellus + + cavia-porcellus + + + + commented + Sep 25, 2025 + +
          +

          +
          +
          +
          + + + +
          +
          +
          +
          +
          + + +
          +
          + + +
          + + +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          + +
          +
          +
          +
          +
          +
          + +
          +
          +
          +
          +
          +
          +
          +
          + + +
          + + + + + + +
          +
          +

          + The content you are editing has changed. + Please copy your edits and refresh the page. +

          + +
          + + + + + + +
          + +
          +
          + +
          + +
          + +
          +
          +
          + +
          + + + + + + + + + + + + +
          +
          +
          +
          + +
          +
          +
          +
          + +
          + +
          + + +
          +
          + +
          +
          +
          + +
          +
          +
          +
          + + +
          +
          + +
          +
          +
          + +
          +
          +
          +
          + +
          +
          + + @cavia-porcellus +
          +
          + +
          + + + + + + + + +
          +
          +
          + +
          +
          +
          + + 45bc218 + +
          +
          +
          +
          +
          +
          +
          +
          +
          + + +
          +
          + @cavia-porcellus +
          + +
          +
          +
          +
          +
          + + + + + + + + + + + + Copy link +
          +
          + + +
          + + Reference in new issue + + +
          + +

          Reference in new issue

          +
          + +
          + +
          +
          +
          +
          +
          + + + testing-deletable + + + +
          + Repositories +
          +
          +
          + + + +
          +
          + + + Loading + + + +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          + +
          + + + + + + +
          +
          +
          +
          + +
          +
          +
          +
          +
          + + + +
          + + +
          + +
          +
          +
          +
          + + + + Author + +
          +

          +
          + + + cavia-porcellus + + + + commented + Sep 25, 2025 + +
          +

          +
          +
          + + +
          + + +
          + +
          +
          +
          +
          +
          +
          + + +
          +
          + + +
          + + +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          + +
          +
          +
          +
          +
          +
          + +
          +
          +
          +
          +
          +
          +
          +
          + + +
          + + + + + + +
          +
          +

          + The content you are editing has changed. + Please copy your edits and refresh the page. +

          + +
          + + + + + + +
          + +
          +
          + +
          + +
          + +
          +
          +
          + +
          + + + + + + + + + + + + +
          +
          +
          +
          + +
          +
          +
          +
          + +
          + +
          + + +
          +
          + +
          +
          +
          +
          +
          + +
          +
          + +
          +
          +
          +
          +
          + + + + + +

          Merge info

          No conflicts with base branch

          Changes can be cleanly merged.

          +
          +
          +
          + + +
          +
          + @cavia-porcellus +
          +
          +
          + + +
          + +

          Add a comment

          + + + +
          +
          + + +
          + + +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          + +
          +
          +
          +
          +
          +
          + +
          +
          +
          +
          +
          +
          +
          +
          + + +
          + + + + + + +
          + + +
          + + + +
          + +
          +
          + +
          + +
          + + +
          +
          +
          + +
          + + + + + + + + + + + + +
          +
          +
          + +
          +
          + + +
          +
          +
          + +
          +
          +
          +
          +
          +
          + + +
          +
          +
          +
          +
          +
          +
          +
          + Remember, contributions to this repository should follow + our + GitHub Community Guidelines. +
          +
          + + ProTip! + Add .patch or .diff to the end of URLs for Git’s plaintext views. +
          +
          +
          +
          +
          +
          +
          +
          + + + +
          + +
          + Labels +
          +
          + None yet +
          +
          + +
          +
          +
          + Projects +
          +
          +
          + + None yet + +
          + + + + + +
          +
          +
          + +
          + +
          + Development +
          + +

          Successfully merging this pull request may close these issues.

          +
          +

          None yet

          +
          +
          +
          +
          +
          +
          + + +
          +
          +
          + 1 participant +
          +
          + + @cavia-porcellus +
          +
          +
          + + + +
          + +
          +
          + + + + + + + + + + + + + +
          +
          +
          +
          +
          + +
          +
          + +
          +
          +
          +
          +
          +
          + + + + + + + + +
          +
          +
          + + \ No newline at end of file diff --git a/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap b/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap index b903f76..1a251f6 100644 --- a/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap +++ b/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap @@ -40,6 +40,41 @@ exports[`github detection > gh_issue_edit:should detect correct spots 1`] = ` ] `; +exports[`github detection > gh_issue_edit_multiple:should detect correct spots 1`] = ` +[ + { + "for": "id=:r76: name=null className=prc-Textarea-TextArea-13q4j overtype-input", + "spot": { + "isIssue": true, + "type": "GH_EDIT", + "unique_key": "github.com:diffplug/testing-deletable:3:edit-body", + }, + }, + { + "for": "id=:r8k: name=null className=prc-Textarea-TextArea-13q4j focus-visible overtype-input", + "spot": { + "domain": "github.com", + "number": 3, + "slug": "diffplug/testing-deletable", + "title": "Test 3", + "type": "GH_ISSUE_APPEND", + "unique_key": "github.com:diffplug/testing-deletable:3", + }, + }, + { + "for": "id=:r5b: name=null className=prc-Textarea-TextArea-13q4j overtype-input", + "spot": { + "domain": "github.com", + "number": 3, + "slug": "diffplug/testing-deletable", + "title": "Test 3", + "type": "GH_ISSUE_APPEND", + "unique_key": "github.com:diffplug/testing-deletable:3", + }, + }, +] +`; + exports[`github detection > gh_issue_new:should detect correct spots 1`] = ` [ { @@ -102,6 +137,43 @@ exports[`github detection > gh_pr_edit:should detect correct spots 1`] = ` ] `; +exports[`github detection > gh_pr_edit_multiple:should detect correct spots 1`] = ` +[ + { + "for": "id=issue-3454672384-body name=pull_request[body] className=js-comment-field js-paste-markdown js-task-list-field js-quick-submit js-size-to-fit size-to-fit js-session-resumable CommentBox-input FormControl-textarea js-saved-reply-shortcut-comment-field overtype-input", + "spot": { + "isIssue": false, + "type": "GH_EDIT", + "unique_key": "github.com:diffplug/testing-deletable:5:edit-body", + }, + }, + { + "for": "id=convert-to-issue-body-3335416053 name=issue[body] className=form-control input-contrast comment-form-textarea js-comment-field js-paste-markdown js-task-list-field js-quick-submit js-size-to-fit size-to-fit js-session-resumable", + "spot": "NO_SPOT", + }, + { + "for": "id=issuecomment-3335416053-body name=issue_comment[body] className=js-comment-field js-paste-markdown js-task-list-field js-quick-submit js-size-to-fit size-to-fit js-session-resumable CommentBox-input FormControl-textarea js-saved-reply-shortcut-comment-field focus-visible overtype-input", + "spot": { + "isIssue": false, + "type": "GH_EDIT", + "unique_key": "github.com:diffplug/testing-deletable:5:edit-body", + }, + }, + { + "for": "id=new_comment_field name=comment[body] className=js-comment-field js-paste-markdown js-task-list-field js-quick-submit FormControl-textarea CommentBox-input js-size-to-fit size-to-fit js-session-resumable js-saved-reply-shortcut-comment-field overtype-input", + "spot": { + "domain": "github.com", + "number": 5, + "slug": "diffplug/testing-deletable", + "title": "Update README.md + #5", + "type": "GH_PR_APPEND", + "unique_key": "github.com:diffplug/testing-deletable:5", + }, + }, +] +`; + exports[`github detection > gh_pr_new:should detect correct spots 1`] = ` [ { diff --git a/tests/lib/enhancers/__snapshots__/gh-ui.test.ts.snap b/tests/lib/enhancers/__snapshots__/gh-ui.test.ts.snap index 5122750..0808b5d 100644 --- a/tests/lib/enhancers/__snapshots__/gh-ui.test.ts.snap +++ b/tests/lib/enhancers/__snapshots__/gh-ui.test.ts.snap @@ -59,6 +59,60 @@ exports[`github ui > gh_issue_edit:should render correct UI elements 1`] = ` ] `; +exports[`github ui > gh_issue_edit_multiple:should render correct UI elements 1`] = ` +[ + { + "for": "id=:r76: name=null className=prc-Textarea-TextArea-13q4j overtype-input", + "title": "N/A", + "upperDecoration": + N/A + , + }, + { + "for": "id=:r8k: name=null className=prc-Textarea-TextArea-13q4j focus-visible overtype-input", + "title": "Test 3", + "upperDecoration": + + + + # + 3 + + diffplug/testing-deletable + + , + }, + { + "for": "id=:r5b: name=null className=prc-Textarea-TextArea-13q4j overtype-input", + "title": "Test 3", + "upperDecoration": + + + + # + 3 + + diffplug/testing-deletable + + , + }, +] +`; + exports[`github ui > gh_issue_new:should render correct UI elements 1`] = ` [ { @@ -134,6 +188,43 @@ exports[`github ui > gh_pr_edit:should render correct UI elements 1`] = ` ] `; +exports[`github ui > gh_pr_edit_multiple:should render correct UI elements 1`] = ` +[ + { + "for": "id=issue-3454672384-body name=pull_request[body] className=js-comment-field js-paste-markdown js-task-list-field js-quick-submit js-size-to-fit size-to-fit js-session-resumable CommentBox-input FormControl-textarea js-saved-reply-shortcut-comment-field overtype-input", + "title": "N/A", + "upperDecoration": + N/A + , + }, + { + "for": "id=issuecomment-3335416053-body name=issue_comment[body] className=js-comment-field js-paste-markdown js-task-list-field js-quick-submit js-size-to-fit size-to-fit js-session-resumable CommentBox-input FormControl-textarea js-saved-reply-shortcut-comment-field focus-visible overtype-input", + "title": "N/A", + "upperDecoration": + N/A + , + }, + { + "for": "id=new_comment_field name=comment[body] className=js-comment-field js-paste-markdown js-task-list-field js-quick-submit FormControl-textarea CommentBox-input js-size-to-fit size-to-fit js-session-resumable js-saved-reply-shortcut-comment-field overtype-input", + "title": "Update README.md + #5", + "upperDecoration": + + diffplug/testing-deletable + + + PR # + 5 + + , + }, +] +`; + exports[`github ui > gh_pr_new:should render correct UI elements 1`] = ` [ { From 06ac583ed6b226cb2349cc659952ba2d8fef302f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 25 Sep 2025 12:21:00 -0700 Subject: [PATCH 3/5] Detection works (sloppy though). --- .../enhancers/github/GitHubEditEnhancer.tsx | 11 +++++++++- .../__snapshots__/gh-detection.test.ts.snap | 9 +++----- .../__snapshots__/gh-ui.test.ts.snap | 22 ++++--------------- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/lib/enhancers/github/GitHubEditEnhancer.tsx b/src/lib/enhancers/github/GitHubEditEnhancer.tsx index 786535a..f30934f 100644 --- a/src/lib/enhancers/github/GitHubEditEnhancer.tsx +++ b/src/lib/enhancers/github/GitHubEditEnhancer.tsx @@ -28,7 +28,16 @@ export class GitHubEditEnhancer implements CommentEnhancer { textarea.name === 'pull_request[body]' || textarea.name === 'issue_comment[body]' // ^this is the root pr comment ^this is the other pr comments (surprising!) - if (!isIssueBodyEdit && !isPRBodyEdit) { + // Also detect comment editing textareas (have "Update comment" button) + // Look for "Update comment" button in the same container as the textarea + const container = + textarea.closest('[class*="markdown"], [class*="comment"], .js-comment-edit-form') || + textarea.closest('form') || + textarea.parentElement?.parentElement?.parentElement + const buttons = container ? Array.from(container.querySelectorAll('button')) : [] + const isCommentEdit = buttons.some((btn) => btn.textContent?.includes('Update comment')) + + if (!isIssueBodyEdit && !isPRBodyEdit && !isCommentEdit) { return null } diff --git a/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap b/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap index 1a251f6..31c3152 100644 --- a/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap +++ b/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap @@ -53,12 +53,9 @@ exports[`github detection > gh_issue_edit_multiple:should detect correct spots 1 { "for": "id=:r8k: name=null className=prc-Textarea-TextArea-13q4j focus-visible overtype-input", "spot": { - "domain": "github.com", - "number": 3, - "slug": "diffplug/testing-deletable", - "title": "Test 3", - "type": "GH_ISSUE_APPEND", - "unique_key": "github.com:diffplug/testing-deletable:3", + "isIssue": false, + "type": "GH_EDIT", + "unique_key": "github.com:diffplug/testing-deletable:3:edit-body", }, }, { diff --git a/tests/lib/enhancers/__snapshots__/gh-ui.test.ts.snap b/tests/lib/enhancers/__snapshots__/gh-ui.test.ts.snap index 0808b5d..74331a9 100644 --- a/tests/lib/enhancers/__snapshots__/gh-ui.test.ts.snap +++ b/tests/lib/enhancers/__snapshots__/gh-ui.test.ts.snap @@ -70,24 +70,10 @@ exports[`github ui > gh_issue_edit_multiple:should render correct UI elements 1` }, { "for": "id=:r8k: name=null className=prc-Textarea-TextArea-13q4j focus-visible overtype-input", - "title": "Test 3", - "upperDecoration": - - - - # - 3 - - diffplug/testing-deletable - - , + "title": "N/A", + "upperDecoration": + N/A + , }, { "for": "id=:r5b: name=null className=prc-Textarea-TextArea-13q4j overtype-input", From 644f340aa23aa552fffd9eb863ea4e9af7376384 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 25 Sep 2025 13:02:09 -0700 Subject: [PATCH 4/5] workaround https://github.com/anthropics/claude-code/issues/8197 --- .claude/commands/corpus-loop.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.claude/commands/corpus-loop.md b/.claude/commands/corpus-loop.md index e2fdf9b..b669dcd 100644 --- a/.claude/commands/corpus-loop.md +++ b/.claude/commands/corpus-loop.md @@ -52,7 +52,7 @@ If you see `"title": "TODO_TITLE"` or similar hardcoded `TODO` values in the JSO ## Extraction code style -- Don't hedge your bets and write lots of fallback code or strings of `?.`. Have a specific piece of data you want to get, use non-null `!` assertions where necessary to be clear about getting. +- Don't hedge your bets and write lots of fallback code or strings of `?.`. Have a specific piece of data you want to get, use non-null ! assertions where necessary to be clear about getting. - If a field is empty, represent it with an empty string. Don't use placeholders when extracting data. - The pages we are scraping are going to change over time, and it's easier to fix broken ones if we know exactly what used to work. If the code has lots of branching paths, it's harder to tell what it was doing. From 8a0a94f3cef8993dae99a5fe3955ea6057eb8590 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 26 Sep 2025 08:24:26 -0700 Subject: [PATCH 5/5] improve the edit detection --- .../enhancers/github/GitHubEditEnhancer.tsx | 33 +++++++------------ .../__snapshots__/gh-detection.test.ts.snap | 2 +- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/src/lib/enhancers/github/GitHubEditEnhancer.tsx b/src/lib/enhancers/github/GitHubEditEnhancer.tsx index f30934f..d571783 100644 --- a/src/lib/enhancers/github/GitHubEditEnhancer.tsx +++ b/src/lib/enhancers/github/GitHubEditEnhancer.tsx @@ -22,38 +22,29 @@ export class GitHubEditEnhancer implements CommentEnhancer { return null } - // Only enhance textareas that are for editing issue/PR body - const isIssueBodyEdit = textarea.closest('.react-issue-body') // this works for root and appended comments - const isPRBodyEdit = - textarea.name === 'pull_request[body]' || textarea.name === 'issue_comment[body]' - // ^this is the root pr comment ^this is the other pr comments (surprising!) - - // Also detect comment editing textareas (have "Update comment" button) - // Look for "Update comment" button in the same container as the textarea - const container = - textarea.closest('[class*="markdown"], [class*="comment"], .js-comment-edit-form') || - textarea.closest('form') || - textarea.parentElement?.parentElement?.parentElement - const buttons = container ? Array.from(container.querySelectorAll('button')) : [] - const isCommentEdit = buttons.some((btn) => btn.textContent?.includes('Update comment')) - - if (!isIssueBodyEdit && !isPRBodyEdit && !isCommentEdit) { - return null - } - // Parse GitHub URL structure: /owner/repo/issues/123 or /owner/repo/pull/456 const match = location.pathname.match(/^\/([^/]+)\/([^/]+)\/(?:issues|pull)\/(\d+)/) if (!match) { return null } - const [, owner, repo, numberStr] = match const number = parseInt(numberStr!, 10) const unique_key = `github.com:${owner}/${repo}:${number}:edit-body` + // Only enhance textareas that are for editing issue/PR body + const isIssueBodyRootEdit = textarea.closest('.react-issue-body') + const isIssueBodyCommentEdit = textarea.closest('[data-wrapper-timeline-id]') + const isPRBodyEdit = + textarea.name === 'pull_request[body]' || textarea.name === 'issue_comment[body]' + // ^this is the root pr comment ^this is the other pr comments (surprising!) + + if (!isIssueBodyRootEdit && !isIssueBodyCommentEdit && !isPRBodyEdit) { + return null + } + logger.debug(`${this.constructor.name} enhanced issue/PR body textarea`, unique_key) return { - isIssue: !!isIssueBodyEdit, + isIssue: !!(isIssueBodyRootEdit || isIssueBodyCommentEdit), type: GH_EDIT, unique_key, } diff --git a/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap b/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap index 31c3152..b5b8f6c 100644 --- a/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap +++ b/tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap @@ -53,7 +53,7 @@ exports[`github detection > gh_issue_edit_multiple:should detect correct spots 1 { "for": "id=:r8k: name=null className=prc-Textarea-TextArea-13q4j focus-visible overtype-input", "spot": { - "isIssue": false, + "isIssue": true, "type": "GH_EDIT", "unique_key": "github.com:diffplug/testing-deletable:3:edit-body", },