Skip to content

Commit ea46a96

Browse files
authored
Handle textareas being initialized after initial page load (#47 bandaid for #46)
2 parents bf975b4 + 4dc0403 commit ea46a96

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

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
])

0 commit comments

Comments
 (0)