Skip to content

Commit 9323e1a

Browse files
committed
Merge branch 'main' into feat/table-styling
2 parents 43c4920 + 4df7b1b commit 9323e1a

File tree

8 files changed

+36
-8
lines changed

8 files changed

+36
-8
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { Options } from 'overtype'
2+
3+
export const commonGithubOptions: Options = {
4+
autoResize: true,
5+
lineHeight: 'var(--text-body-lineHeight-medium, 1.4285)',
6+
padding: 'var(--base-size-16)',
7+
}

browser-extension/src/lib/enhancers/github/githubIssueAddComment.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type React from 'react'
44
import type { CommentEnhancer, CommentSpot } from '@/lib/enhancer'
55
import { logger } from '@/lib/logger'
66
import { modifyDOM } from '../modifyDOM'
7+
import { commonGithubOptions } from './ghOptions'
78
import { githubHighlighter } from './githubHighlighter'
89

910
export interface GitHubIssueAddCommentSpot extends CommentSpot {
@@ -52,9 +53,8 @@ export class GitHubIssueAddCommentEnhancer implements CommentEnhancer<GitHubIssu
5253
enhance(textArea: HTMLTextAreaElement, _spot: GitHubIssueAddCommentSpot): OverTypeInstance {
5354
const overtypeContainer = modifyDOM(textArea)
5455
return new OverType(overtypeContainer, {
55-
autoResize: true,
56+
...commonGithubOptions,
5657
minHeight: '100px',
57-
padding: 'var(--base-size-16)',
5858
placeholder: 'Use Markdown to format your comment',
5959
})[0]!
6060
}

browser-extension/src/lib/enhancers/github/githubIssueNewComment.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import OverType, { type OverTypeInstance } from 'overtype'
22
import type { CommentEnhancer, CommentSpot } from '../../enhancer'
33
import { logger } from '../../logger'
44
import { modifyDOM } from '../modifyDOM'
5+
import { commonGithubOptions } from './ghOptions'
56
import { githubHighlighter } from './githubHighlighter'
67

78
interface GitHubIssueNewCommentSpot extends CommentSpot {
@@ -45,9 +46,8 @@ export class GitHubIssueNewCommentEnhancer implements CommentEnhancer<GitHubIssu
4546
enhance(textArea: HTMLTextAreaElement, _spot: GitHubIssueNewCommentSpot): OverTypeInstance {
4647
const overtypeContainer = modifyDOM(textArea)
4748
return new OverType(overtypeContainer, {
48-
autoResize: true,
49+
...commonGithubOptions,
4950
minHeight: '400px',
50-
padding: 'var(--base-size-16)',
5151
placeholder: 'Type your description here...',
5252
})[0]!
5353
}

browser-extension/src/lib/enhancers/github/githubPRAddComment.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type React from 'react'
33
import type { CommentEnhancer, CommentSpot } from '@/lib/enhancer'
44
import { logger } from '@/lib/logger'
55
import { modifyDOM } from '../modifyDOM'
6+
import { commonGithubOptions } from './ghOptions'
67
import { githubHighlighter } from './githubHighlighter'
78

89
export interface GitHubPRAddCommentSpot extends CommentSpot {
@@ -55,7 +56,7 @@ export class GitHubPRAddCommentEnhancer implements CommentEnhancer<GitHubPRAddCo
5556
enhance(textArea: HTMLTextAreaElement, _spot: GitHubPRAddCommentSpot): OverTypeInstance {
5657
const overtypeContainer = modifyDOM(textArea)
5758
return new OverType(overtypeContainer, {
58-
autoResize: true,
59+
...commonGithubOptions,
5960
minHeight: '102px',
6061
padding: 'var(--base-size-8)',
6162
placeholder: 'Add your comment here...',

browser-extension/src/lib/enhancers/github/githubPRNewComment.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import OverType, { type OverTypeInstance } from 'overtype'
22
import type { CommentEnhancer, CommentSpot } from '../../enhancer'
33
import { logger } from '../../logger'
44
import { modifyDOM } from '../modifyDOM'
5+
import { commonGithubOptions } from './ghOptions'
56
import { githubHighlighter } from './githubHighlighter'
67

78
interface GitHubPRNewCommentSpot extends CommentSpot {
@@ -50,9 +51,8 @@ export class GitHubPRNewCommentEnhancer implements CommentEnhancer<GitHubPRNewCo
5051
enhance(textArea: HTMLTextAreaElement, _spot: GitHubPRNewCommentSpot): OverTypeInstance {
5152
const overtypeContainer = modifyDOM(textArea)
5253
return new OverType(overtypeContainer, {
53-
autoResize: true,
54+
...commonGithubOptions,
5455
minHeight: '250px',
55-
padding: 'var(--base-size-16)',
5656
placeholder: 'Type your description here...',
5757
})[0]!
5858
}

browser-extension/src/lib/registries.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export class EnhancerRegistry {
7070
this.preparedEnhancers.add(enhancer)
7171
}
7272
const overtype = enhancer.enhance(textarea, spot)
73+
this.handleDelayedValueInjection(overtype)
7374
return { enhancer, overtype, spot, textarea }
7475
}
7576
} catch (error) {
@@ -79,6 +80,24 @@ export class EnhancerRegistry {
7980
return null
8081
}
8182

83+
private handleDelayedValueInjection(overtype: OverTypeInstance): void {
84+
// GitHub sometimes injects textarea content after a delay
85+
// We need to trigger OverType to update its preview after such injections
86+
// https://github.com/diffplug/gitcasso/issues/46
87+
setTimeout(() => {
88+
overtype.updatePreview()
89+
}, 100)
90+
setTimeout(() => {
91+
overtype.updatePreview()
92+
}, 200)
93+
setTimeout(() => {
94+
overtype.updatePreview()
95+
}, 400)
96+
setTimeout(() => {
97+
overtype.updatePreview()
98+
}, 8000)
99+
}
100+
82101
getEnhancerCount(): number {
83102
return this.enhancers.size
84103
}

browser-extension/tests/har-fixture.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ vi.mock('overtype', () => {
1818
preview: document.createElement('div'),
1919
setValue: vi.fn(),
2020
textarea: document.createElement('textarea'),
21+
updatePreview: vi.fn(),
2122
wrapper: document.createElement('div'),
2223
},
2324
])

packages/overtype

0 commit comments

Comments
 (0)