Skip to content

Commit 603b314

Browse files
committed
So for PR append, a single text box persists for each comment, it just gets cleared after submission. Listeningfor input doesn't work, but listening with MutationObserver does.
1 parent f0df91f commit 603b314

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/lib/enhancers/github/GitHubPrAppendEnhancer.tsx

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,33 @@ export class GitHubPrAppendEnhancer implements CommentEnhancer<GitHubPrAppendSpo
6161
enhance(textArea: HTMLTextAreaElement, _spot: GitHubPrAppendSpot): OvertypeWithCleanup {
6262
prepareGitHubHighlighter()
6363
const overtypeContainer = modifyDOM(textArea)
64+
const instance = new OverType(overtypeContainer, {
65+
...commonGitHubOptions,
66+
minHeight: '102px',
67+
padding: 'var(--base-size-8)',
68+
placeholder: 'Add your comment here...',
69+
})[0]!
70+
console.log('C')
71+
textArea.addEventListener('input', () => {
72+
if (textArea.value === '') {
73+
console.log('input event fired')
74+
instance.updatePreview()
75+
}
76+
})
77+
const observer = new MutationObserver(() => {
78+
if (textArea.value === '') {
79+
console.log('MutationObserver fired')
80+
instance.updatePreview()
81+
}
82+
})
83+
observer.observe(textArea, { attributes: true, characterData: true })
84+
const cleanup = () => {
85+
OverType.instances.delete(overtypeContainer)
86+
;(overtypeContainer as any).overTypeInstance = undefined
87+
}
6488
return {
65-
instance: new OverType(overtypeContainer, {
66-
...commonGitHubOptions,
67-
minHeight: '102px',
68-
padding: 'var(--base-size-8)',
69-
placeholder: 'Add your comment here...',
70-
})[0]!,
89+
cleanup,
90+
instance,
7191
}
7292
}
7393

0 commit comments

Comments
 (0)