Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions browser-extension/src/lib/enhancers/github/ghOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { Options } from 'overtype'

export const commonGithubOptions: Options = {
autoResize: true,
lineHeight: 'var(--text-body-lineHeight-medium, 1.4285)',
padding: 'var(--base-size-16)',
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import OverType, { type OverTypeInstance } from 'overtype'
import type { CommentEnhancer, CommentSpot } from '../../enhancer'
import { logger } from '../../logger'
import { modifyDOM } from '../modifyDOM'
import { commonGithubOptions } from './ghOptions'
import { githubHighlighter } from './githubHighlighter'

interface GitHubIssueAddCommentSpot extends CommentSpot {
Expand Down Expand Up @@ -47,9 +48,8 @@ export class GitHubIssueAddCommentEnhancer implements CommentEnhancer<GitHubIssu
enhance(textArea: HTMLTextAreaElement, _spot: GitHubIssueAddCommentSpot): OverTypeInstance {
const overtypeContainer = modifyDOM(textArea)
return new OverType(overtypeContainer, {
autoResize: true,
...commonGithubOptions,
minHeight: '100px',
padding: 'var(--base-size-16)',
placeholder: 'Use Markdown to format your comment',
})[0]!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import OverType, { type OverTypeInstance } from 'overtype'
import type { CommentEnhancer, CommentSpot } from '../../enhancer'
import { logger } from '../../logger'
import { modifyDOM } from '../modifyDOM'
import { commonGithubOptions } from './ghOptions'
import { githubHighlighter } from './githubHighlighter'

interface GitHubIssueNewCommentSpot extends CommentSpot {
Expand Down Expand Up @@ -45,9 +46,8 @@ export class GitHubIssueNewCommentEnhancer implements CommentEnhancer<GitHubIssu
enhance(textArea: HTMLTextAreaElement, _spot: GitHubIssueNewCommentSpot): OverTypeInstance {
const overtypeContainer = modifyDOM(textArea)
return new OverType(overtypeContainer, {
autoResize: true,
...commonGithubOptions,
minHeight: '400px',
padding: 'var(--base-size-16)',
placeholder: 'Type your description here...',
})[0]!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import OverType, { type OverTypeInstance } from 'overtype'
import type { CommentEnhancer, CommentSpot } from '../../enhancer'
import { logger } from '../../logger'
import { modifyDOM } from '../modifyDOM'
import { commonGithubOptions } from './ghOptions'
import { githubHighlighter } from './githubHighlighter'

interface GitHubPRAddCommentSpot extends CommentSpot {
Expand Down Expand Up @@ -51,7 +52,7 @@ export class GitHubPRAddCommentEnhancer implements CommentEnhancer<GitHubPRAddCo
enhance(textArea: HTMLTextAreaElement, _spot: GitHubPRAddCommentSpot): OverTypeInstance {
const overtypeContainer = modifyDOM(textArea)
return new OverType(overtypeContainer, {
autoResize: true,
...commonGithubOptions,
minHeight: '102px',
padding: 'var(--base-size-8)',
placeholder: 'Add your comment here...',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import OverType, { type OverTypeInstance } from 'overtype'
import type { CommentEnhancer, CommentSpot } from '../../enhancer'
import { logger } from '../../logger'
import { modifyDOM } from '../modifyDOM'
import { commonGithubOptions } from './ghOptions'
import { githubHighlighter } from './githubHighlighter'

interface GitHubPRNewCommentSpot extends CommentSpot {
Expand Down Expand Up @@ -50,9 +51,8 @@ export class GitHubPRNewCommentEnhancer implements CommentEnhancer<GitHubPRNewCo
enhance(textArea: HTMLTextAreaElement, _spot: GitHubPRNewCommentSpot): OverTypeInstance {
const overtypeContainer = modifyDOM(textArea)
return new OverType(overtypeContainer, {
autoResize: true,
...commonGithubOptions,
minHeight: '250px',
padding: 'var(--base-size-16)',
placeholder: 'Type your description here...',
})[0]!
}
Expand Down
19 changes: 19 additions & 0 deletions browser-extension/src/lib/registries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class EnhancerRegistry {
this.preparedEnhancers.add(enhancer)
}
const overtype = enhancer.enhance(textarea, spot)
this.handleDelayedValueInjection(overtype)
return { enhancer, overtype, spot, textarea }
}
} catch (error) {
Expand All @@ -78,6 +79,24 @@ export class EnhancerRegistry {
return null
}

private handleDelayedValueInjection(overtype: OverTypeInstance): void {
// GitHub sometimes injects textarea content after a delay
// We need to trigger OverType to update its preview after such injections
// https://github.com/diffplug/gitcasso/issues/46
setTimeout(() => {
overtype.updatePreview()
}, 100)
setTimeout(() => {
overtype.updatePreview()
}, 200)
setTimeout(() => {
overtype.updatePreview()
}, 400)
setTimeout(() => {
overtype.updatePreview()
}, 8000)
}

getEnhancerCount(): number {
return this.enhancers.size
}
Expand Down
1 change: 1 addition & 0 deletions browser-extension/tests/har-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ vi.mock('overtype', () => {
preview: document.createElement('div'),
setValue: vi.fn(),
textarea: document.createElement('textarea'),
updatePreview: vi.fn(),
wrapper: document.createElement('div'),
},
])
Expand Down
2 changes: 1 addition & 1 deletion packages/overtype
Submodule overtype updated 1 files
+0 −1 src/styles.js