11import { IssueOpenedIcon } from '@primer/octicons-react'
2- import OverType , { type OverTypeInstance } from 'overtype'
2+ import OverType from 'overtype'
33import type React from 'react'
44import type {
55 CommentEnhancer ,
@@ -8,7 +8,6 @@ import type {
88 StrippedLocation ,
99} from '@/lib/enhancer'
1010import { logger } from '@/lib/logger'
11- import { oncePerRefresh } from '@/lib/once-per-refresh'
1211import { modifyDOM } from '../modifyDOM'
1312import { commonGitHubOptions , prepareGitHubHighlighter } from './github-common'
1413
@@ -69,44 +68,22 @@ export class GitHubIssueAppendEnhancer implements CommentEnhancer<GitHubIssueApp
6968 }
7069 }
7170
72- instance : OverTypeInstance | undefined
73-
7471 enhance ( textArea : HTMLTextAreaElement , _spot : GitHubIssueAppendSpot ) : OvertypeWithCleanup {
7572 prepareGitHubHighlighter ( )
7673 const overtypeContainer = modifyDOM ( textArea )
77- if ( this . instance ) {
78- OverType . instances . delete ( overtypeContainer )
79- ; ( overtypeContainer as any ) . overTypeInstance = undefined
80- }
81- this . registerSubmitHandler ( textArea , _spot )
82- const thing = new OverType ( overtypeContainer , {
74+ const instance = new OverType ( overtypeContainer , {
8375 ...commonGitHubOptions ,
8476 minHeight : '100px' ,
8577 placeholder : 'Use Markdown to format your comment' ,
8678 } ) [ 0 ] !
87- this . instance = thing
88- return { instance : thing }
89- }
90-
91- private registerSubmitHandler ( textArea : HTMLTextAreaElement , _spot : GitHubIssueAppendSpot ) {
92- oncePerRefresh ( 'gh-issue-append-events' , ( ) => {
93- document . addEventListener ( 'click' , ( e ) => {
94- const target = e . target
95- if ( target ) {
96- const btn = ( e . target as HTMLElement ) . closest ( 'button' )
97- if ( btn ) {
98- if (
99- btn . textContent . trim ( ) === 'Comment' ||
100- btn . matches ( 'button[data-variant="primary"]' )
101- ) {
102- this . enhance ( textArea , _spot )
103- return true
104- }
105- }
106- }
107- return false
108- } )
109- } )
79+ const cleanup = ( ) => {
80+ OverType . instances . delete ( overtypeContainer )
81+ ; ( overtypeContainer as any ) . overTypeInstance = undefined
82+ }
83+ return {
84+ cleanup,
85+ instance,
86+ }
11087 }
11188
11289 tableUpperDecoration ( spot : GitHubIssueAppendSpot ) : React . ReactNode {
0 commit comments