Skip to content

Commit 4df7b1b

Browse files
authored
fix github line-height (#45 closes #41)
GitHub line-height
2 parents 7bd45d8 + 4763d16 commit 4df7b1b

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.ts

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 GitHubIssueAddCommentSpot extends CommentSpot {
@@ -47,9 +48,8 @@ export class GitHubIssueAddCommentEnhancer implements CommentEnhancer<GitHubIssu
4748
enhance(textArea: HTMLTextAreaElement, _spot: GitHubIssueAddCommentSpot): OverTypeInstance {
4849
const overtypeContainer = modifyDOM(textArea)
4950
return new OverType(overtypeContainer, {
50-
autoResize: true,
51+
...commonGithubOptions,
5152
minHeight: '100px',
52-
padding: 'var(--base-size-16)',
5353
placeholder: 'Use Markdown to format your comment',
5454
})[0]!
5555
}

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

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.ts

Lines changed: 2 additions & 1 deletion
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 GitHubPRAddCommentSpot extends CommentSpot {
@@ -51,7 +52,7 @@ export class GitHubPRAddCommentEnhancer implements CommentEnhancer<GitHubPRAddCo
5152
enhance(textArea: HTMLTextAreaElement, _spot: GitHubPRAddCommentSpot): OverTypeInstance {
5253
const overtypeContainer = modifyDOM(textArea)
5354
return new OverType(overtypeContainer, {
54-
autoResize: true,
55+
...commonGithubOptions,
5556
minHeight: '102px',
5657
padding: 'var(--base-size-8)',
5758
placeholder: 'Add your comment here...',

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

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
@@ -69,6 +69,7 @@ export class EnhancerRegistry {
6969
this.preparedEnhancers.add(enhancer)
7070
}
7171
const overtype = enhancer.enhance(textarea, spot)
72+
this.handleDelayedValueInjection(overtype)
7273
return { enhancer, overtype, spot, textarea }
7374
}
7475
} catch (error) {
@@ -78,6 +79,24 @@ export class EnhancerRegistry {
7879
return null
7980
}
8081

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

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)