Skip to content

Commit bc3c684

Browse files
committed
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.
1 parent f8b5faa commit bc3c684

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/lib/enhancers/github/GitHubEditEnhancer.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { commonGitHubOptions, prepareGitHubHighlighter } from './github-common'
88
const GH_EDIT = 'GH_EDIT' as const
99

1010
export interface GitHubEditSpot extends CommentSpot {
11+
isIssue: boolean
1112
type: typeof GH_EDIT
1213
}
1314

@@ -22,9 +23,10 @@ export class GitHubEditEnhancer implements CommentEnhancer<GitHubEditSpot> {
2223
}
2324

2425
// Only enhance textareas that are for editing issue/PR body
25-
const isIssueBodyEdit = textarea.closest('.react-issue-body')
26+
const isIssueBodyEdit = textarea.closest('.react-issue-body') // this works for root and appended comments
2627
const isPRBodyEdit =
27-
textarea.id?.match(/^issue-\d+-body$/) || textarea.name === 'pull_request[body]'
28+
textarea.name === 'pull_request[body]' || textarea.name === 'issue_comment[body]'
29+
// ^this is the root pr comment ^this is the other pr comments (surprising!)
2830

2931
if (!isIssueBodyEdit && !isPRBodyEdit) {
3032
return null
@@ -42,20 +44,23 @@ export class GitHubEditEnhancer implements CommentEnhancer<GitHubEditSpot> {
4244

4345
logger.debug(`${this.constructor.name} enhanced issue/PR body textarea`, unique_key)
4446
return {
47+
isIssue: !!isIssueBodyEdit,
4548
type: GH_EDIT,
4649
unique_key,
4750
}
4851
}
4952

50-
enhance(textArea: HTMLTextAreaElement, _spot: GitHubEditSpot): OverTypeInstance {
53+
enhance(textArea: HTMLTextAreaElement, spot: GitHubEditSpot): OverTypeInstance {
5154
prepareGitHubHighlighter()
5255
const overtypeContainer = modifyDOM(textArea)
53-
return new OverType(overtypeContainer, {
56+
const overtype = new OverType(overtypeContainer, {
5457
...commonGitHubOptions,
55-
minHeight: '102px',
56-
padding: 'var(--base-size-8)',
57-
placeholder: 'Add your comment here...',
58+
padding: spot.isIssue ? 'var(--base-size-16)' : 'var(--base-size-8)',
5859
})[0]!
60+
if (!spot.isIssue) {
61+
// TODO: autoheight not working
62+
}
63+
return overtype
5964
}
6065

6166
tableUpperDecoration(_spot: GitHubEditSpot): React.ReactNode {

tests/lib/enhancers/__snapshots__/gh-detection.test.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ exports[`github detection > gh_issue_edit:should detect correct spots 1`] = `
2121
{
2222
"for": "id=:rc3: name=null className=prc-Textarea-TextArea-13q4j focus-visible overtype-input",
2323
"spot": {
24+
"isIssue": true,
2425
"type": "GH_EDIT",
2526
"unique_key": "github.com:diffplug/gitcasso:56:edit-body",
2627
},
@@ -80,6 +81,7 @@ exports[`github detection > gh_pr_edit:should detect correct spots 1`] = `
8081
{
8182
"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",
8283
"spot": {
84+
"isIssue": false,
8385
"type": "GH_EDIT",
8486
"unique_key": "github.com:diffplug/gitcasso:58:edit-body",
8587
},

0 commit comments

Comments
 (0)