11import OverType , { type OverTypeInstance } from 'overtype'
22import type React from 'react'
3- import type { CommentEnhancer , CommentSpot } from '@/lib/enhancer'
3+ import type { CommentEnhancer , CommentSpot , StrippedLocation } from '@/lib/enhancer'
44import { logger } from '@/lib/logger'
55import { modifyDOM } from '../modifyDOM'
66import { commonGithubOptions } from './ghOptions'
77import { prepareGitHubHighlighter } from './githubHighlighter'
88
99export interface GitHubEditCommentSpot extends CommentSpot {
1010 type : 'GH_EDIT_COMMENT'
11- title : string
12- domain : string
13- slug : string
14- number : number
1511}
1612
1713export class GitHubEditCommentEnhancer implements CommentEnhancer < GitHubEditCommentSpot > {
1814 forSpotTypes ( ) : string [ ] {
1915 return [ 'GH_EDIT_COMMENT' ]
2016 }
2117
22- tryToEnhance ( _textarea : HTMLTextAreaElement ) : GitHubEditCommentSpot | null {
23- if (
24- document . querySelector ( 'meta[name="hostname"]' ) ?. getAttribute ( 'content' ) !== 'github.com' ||
25- ! _textarea . matches ( '.TimelineItem textarea' )
26- ) {
18+ tryToEnhance (
19+ textarea : HTMLTextAreaElement ,
20+ location : StrippedLocation ,
21+ ) : GitHubEditCommentSpot | null {
22+ if ( location . host !== 'github.com' ) {
23+ return null
24+ }
25+
26+ // Only enhance textareas that are for editing issue/PR body
27+ const isIssueBodyEdit = textarea . closest ( '.react-issue-body' )
28+ const isPRBodyEdit =
29+ textarea . id ?. match ( / ^ i s s u e - \d + - b o d y $ / ) || textarea . name === 'pull_request[body]'
30+
31+ if ( ! isIssueBodyEdit && ! isPRBodyEdit ) {
2732 return null
2833 }
2934
3035 // Parse GitHub URL structure: /owner/repo/issues/123 or /owner/repo/pull/456
31- logger . info ( `${ this . constructor . name } examing url` , window . location . pathname )
36+ const match = location . pathname . match ( / ^ \/ ( [ ^ / ] + ) \/ ( [ ^ / ] + ) \/ (?: i s s u e s | p u l l ) \/ ( \d + ) / )
37+ if ( ! match ) {
38+ return null
39+ }
3240
33- const match = window . location . pathname . match ( / ^ \/ ( [ ^ / ] + ) \/ ( [ ^ / ] + ) (?: \/ ( p u l l | i s s u e s ) \/ ( \d + ) ) / )
34- logger . info ( `${ this . constructor . name } found match` , window . location . pathname )
35- if ( ! match ) return null
3641 const [ , owner , repo , numberStr ] = match
37- const slug = `${ owner } /${ repo } `
3842 const number = parseInt ( numberStr ! , 10 )
39- const unique_key = `github.com:${ slug } :${ number } `
40- const title = 'TODO_TITLE'
43+ const unique_key = `github.com:${ owner } /${ repo } :${ number } :edit-body`
44+
45+ logger . debug ( `${ this . constructor . name } enhanced issue/PR body textarea` , unique_key )
4146 return {
42- domain : 'github.com' ,
43- number,
44- slug,
45- title,
4647 type : 'GH_EDIT_COMMENT' ,
4748 unique_key,
4849 }
@@ -59,17 +60,11 @@ export class GitHubEditCommentEnhancer implements CommentEnhancer<GitHubEditComm
5960 } ) [ 0 ] !
6061 }
6162
62- tableUpperDecoration ( spot : GitHubEditCommentSpot ) : React . ReactNode {
63- const { slug, number } = spot
64- return (
65- < >
66- < span className = 'font-mono text-muted-foreground text-sm' > { slug } </ span >
67- < span className = 'ml-2 font-medium' > PR #{ number } </ span >
68- </ >
69- )
63+ tableUpperDecoration ( _spot : GitHubEditCommentSpot ) : React . ReactNode {
64+ return < span > N/A</ span >
7065 }
7166
7267 tableTitle ( _spot : GitHubEditCommentSpot ) : string {
73- return 'TITLE_TODO '
68+ return 'N/A '
7469 }
7570}
0 commit comments