File tree Expand file tree Collapse file tree 8 files changed +36
-8
lines changed Expand file tree Collapse file tree 8 files changed +36
-8
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import OverType, { type OverTypeInstance } from 'overtype'
2
2
import type { CommentEnhancer , CommentSpot } from '../../enhancer'
3
3
import { logger } from '../../logger'
4
4
import { modifyDOM } from '../modifyDOM'
5
+ import { commonGithubOptions } from './ghOptions'
5
6
import { githubHighlighter } from './githubHighlighter'
6
7
7
8
interface GitHubIssueAddCommentSpot extends CommentSpot {
@@ -47,9 +48,8 @@ export class GitHubIssueAddCommentEnhancer implements CommentEnhancer<GitHubIssu
47
48
enhance ( textArea : HTMLTextAreaElement , _spot : GitHubIssueAddCommentSpot ) : OverTypeInstance {
48
49
const overtypeContainer = modifyDOM ( textArea )
49
50
return new OverType ( overtypeContainer , {
50
- autoResize : true ,
51
+ ... commonGithubOptions ,
51
52
minHeight : '100px' ,
52
- padding : 'var(--base-size-16)' ,
53
53
placeholder : 'Use Markdown to format your comment' ,
54
54
} ) [ 0 ] !
55
55
}
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import OverType, { type OverTypeInstance } from 'overtype'
2
2
import type { CommentEnhancer , CommentSpot } from '../../enhancer'
3
3
import { logger } from '../../logger'
4
4
import { modifyDOM } from '../modifyDOM'
5
+ import { commonGithubOptions } from './ghOptions'
5
6
import { githubHighlighter } from './githubHighlighter'
6
7
7
8
interface GitHubIssueNewCommentSpot extends CommentSpot {
@@ -45,9 +46,8 @@ export class GitHubIssueNewCommentEnhancer implements CommentEnhancer<GitHubIssu
45
46
enhance ( textArea : HTMLTextAreaElement , _spot : GitHubIssueNewCommentSpot ) : OverTypeInstance {
46
47
const overtypeContainer = modifyDOM ( textArea )
47
48
return new OverType ( overtypeContainer , {
48
- autoResize : true ,
49
+ ... commonGithubOptions ,
49
50
minHeight : '400px' ,
50
- padding : 'var(--base-size-16)' ,
51
51
placeholder : 'Type your description here...' ,
52
52
} ) [ 0 ] !
53
53
}
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import OverType, { type OverTypeInstance } from 'overtype'
2
2
import type { CommentEnhancer , CommentSpot } from '../../enhancer'
3
3
import { logger } from '../../logger'
4
4
import { modifyDOM } from '../modifyDOM'
5
+ import { commonGithubOptions } from './ghOptions'
5
6
import { githubHighlighter } from './githubHighlighter'
6
7
7
8
interface GitHubPRAddCommentSpot extends CommentSpot {
@@ -51,7 +52,7 @@ export class GitHubPRAddCommentEnhancer implements CommentEnhancer<GitHubPRAddCo
51
52
enhance ( textArea : HTMLTextAreaElement , _spot : GitHubPRAddCommentSpot ) : OverTypeInstance {
52
53
const overtypeContainer = modifyDOM ( textArea )
53
54
return new OverType ( overtypeContainer , {
54
- autoResize : true ,
55
+ ... commonGithubOptions ,
55
56
minHeight : '102px' ,
56
57
padding : 'var(--base-size-8)' ,
57
58
placeholder : 'Add your comment here...' ,
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import OverType, { type OverTypeInstance } from 'overtype'
2
2
import type { CommentEnhancer , CommentSpot } from '../../enhancer'
3
3
import { logger } from '../../logger'
4
4
import { modifyDOM } from '../modifyDOM'
5
+ import { commonGithubOptions } from './ghOptions'
5
6
import { githubHighlighter } from './githubHighlighter'
6
7
7
8
interface GitHubPRNewCommentSpot extends CommentSpot {
@@ -50,9 +51,8 @@ export class GitHubPRNewCommentEnhancer implements CommentEnhancer<GitHubPRNewCo
50
51
enhance ( textArea : HTMLTextAreaElement , _spot : GitHubPRNewCommentSpot ) : OverTypeInstance {
51
52
const overtypeContainer = modifyDOM ( textArea )
52
53
return new OverType ( overtypeContainer , {
53
- autoResize : true ,
54
+ ... commonGithubOptions ,
54
55
minHeight : '250px' ,
55
- padding : 'var(--base-size-16)' ,
56
56
placeholder : 'Type your description here...' ,
57
57
} ) [ 0 ] !
58
58
}
Original file line number Diff line number Diff line change @@ -69,6 +69,7 @@ export class EnhancerRegistry {
69
69
this . preparedEnhancers . add ( enhancer )
70
70
}
71
71
const overtype = enhancer . enhance ( textarea , spot )
72
+ this . handleDelayedValueInjection ( overtype )
72
73
return { enhancer, overtype, spot, textarea }
73
74
}
74
75
} catch ( error ) {
@@ -78,6 +79,24 @@ export class EnhancerRegistry {
78
79
return null
79
80
}
80
81
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
+
81
100
getEnhancerCount ( ) : number {
82
101
return this . enhancers . size
83
102
}
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ vi.mock('overtype', () => {
18
18
preview : document . createElement ( 'div' ) ,
19
19
setValue : vi . fn ( ) ,
20
20
textarea : document . createElement ( 'textarea' ) ,
21
+ updatePreview : vi . fn ( ) ,
21
22
wrapper : document . createElement ( 'div' ) ,
22
23
} ,
23
24
] )
You can’t perform that action at this time.
0 commit comments