@@ -7,7 +7,13 @@ import type {
77} from "@/lib/enhancer"
88import { logger } from "@/lib/logger"
99import { fixupOvertype , modifyDOM } from "../overtype-misc"
10- import { commonGitHubOptions , prepareGitHubHighlighter } from "./github-common"
10+ import {
11+ commonGitHubOptions ,
12+ isInProjectCommentBox ,
13+ isProjectUrl ,
14+ parseProjectIssueParam ,
15+ prepareGitHubHighlighter ,
16+ } from "./github-common"
1117
1218const GH_EDIT = "GH_EDIT" as const
1319
@@ -30,21 +36,14 @@ export class GitHubEditEnhancer implements CommentEnhancer<GitHubEditSpot> {
3036 }
3137
3238 // Check for project draft edit first
33- const isProjectDraftEdit = location . pathname . match (
34- / ^ \/ (?: o r g s | u s e r s ) \/ [ ^ / ] + \/ p r o j e c t s \/ \d + (?: \/ v i e w s \/ \d + ) ? /
35- )
36- if ( isProjectDraftEdit ) {
39+ if ( isProjectUrl ( location . pathname ) ) {
3740 const params = new URLSearchParams ( location . search )
3841 const itemId = params . get ( "itemId" )
39- const issueParam = params . get ( "issue" )
4042
4143 // Handle draft editing (itemId parameter)
4244 if ( itemId ) {
4345 // Exclude textareas within Shared-module__CommentBox (those are for adding new comments, not editing)
44- const isInCommentBox = textarea . closest (
45- '[class*="Shared-module__CommentBox"]'
46- )
47- if ( ! isInCommentBox ) {
46+ if ( ! isInProjectCommentBox ( textarea ) ) {
4847 const unique_key = `github.com:project-draft:${ itemId } :edit-body`
4948 logger . debug (
5049 `${ this . constructor . name } enhanced project draft body textarea` ,
@@ -59,27 +58,20 @@ export class GitHubEditEnhancer implements CommentEnhancer<GitHubEditSpot> {
5958 }
6059
6160 // Handle existing issue comment editing (issue parameter)
62- if ( issueParam ) {
63- // Parse issue parameter: "owner|repo|number"
64- const parts = issueParam . split ( "|" )
65- if ( parts . length === 3 ) {
66- const [ owner , repo , numberStr ] = parts
67- const slug = `${ owner } /${ repo } `
68- const number = parseInt ( numberStr ! , 10 )
69-
70- // Edit mode: empty placeholder
71- // Add new comment mode: has placeholder "Add your comment here..." or similar
72- if ( ! textarea . placeholder || textarea . placeholder . trim ( ) === "" ) {
73- const unique_key = `github.com:${ slug } :${ number } :edit-comment`
74- logger . debug (
75- `${ this . constructor . name } enhanced project issue comment edit textarea` ,
76- unique_key
77- )
78- return {
79- isIssue : true ,
80- type : GH_EDIT ,
81- unique_key,
82- }
61+ const issueInfo = parseProjectIssueParam ( params )
62+ if ( issueInfo ) {
63+ // Edit mode: empty placeholder
64+ // Add new comment mode: has placeholder "Add your comment here..." or similar
65+ if ( ! textarea . placeholder || textarea . placeholder . trim ( ) === "" ) {
66+ const unique_key = `github.com:${ issueInfo . slug } :${ issueInfo . number } :edit-comment`
67+ logger . debug (
68+ `${ this . constructor . name } enhanced project issue comment edit textarea` ,
69+ unique_key
70+ )
71+ return {
72+ isIssue : true ,
73+ type : GH_EDIT ,
74+ unique_key,
8375 }
8476 }
8577 }
0 commit comments