|
1 | 1 | import type { OverTypeInstance } from 'overtype' |
2 | 2 | import OverType from 'overtype' |
3 | | -import type { CommentEnhancer, CommentEvent, CommentSpot, StrippedLocation } from './enhancer' |
| 3 | +import type { |
| 4 | + CommentEnhancer, |
| 5 | + CommentEvent, |
| 6 | + CommentEventType, |
| 7 | + CommentSpot, |
| 8 | + StrippedLocation, |
| 9 | +} from './enhancer' |
4 | 10 | import { CommentEnhancerMissing } from './enhancers/CommentEnhancerMissing' |
5 | 11 | import { GitHubEditEnhancer } from './enhancers/github/GitHubEditEnhancer' |
6 | 12 | import { GitHubIssueAppendEnhancer } from './enhancers/github/GitHubIssueAppendEnhancer' |
@@ -101,29 +107,32 @@ export class EnhancerRegistry { |
101 | 107 |
|
102 | 108 | export class TextareaRegistry { |
103 | 109 | private textareas = new Map<HTMLTextAreaElement, EnhancedTextarea>() |
104 | | - private sendEvent: (event: CommentEvent) => void = () => {} |
| 110 | + private eventSender: (event: CommentEvent) => void = () => {} |
105 | 111 |
|
106 | 112 | setCommentEventSender(sendEvent: (event: CommentEvent) => void): void { |
107 | | - this.sendEvent = sendEvent |
| 113 | + this.eventSender = sendEvent |
108 | 114 | } |
109 | 115 |
|
110 | | - register<T extends CommentSpot>(enhanced: EnhancedTextarea<T>): void { |
111 | | - this.textareas.set(enhanced.textarea, enhanced) |
112 | | - this.sendEvent({ |
| 116 | + private sendEvent(eventType: CommentEventType, enhanced: EnhancedTextarea): void { |
| 117 | + this.eventSender({ |
113 | 118 | draft: enhanced.textarea.value, |
114 | 119 | spot: enhanced.spot, |
115 | | - type: 'ENHANCED', |
| 120 | + type: eventType, |
| 121 | + }) |
| 122 | + } |
| 123 | + |
| 124 | + register<T extends CommentSpot>(enhanced: EnhancedTextarea<T>): void { |
| 125 | + this.textareas.set(enhanced.textarea, enhanced) |
| 126 | + enhanced.textarea.addEventListener('blur', () => { |
| 127 | + this.sendEvent('LOST_FOCUS', enhanced) |
116 | 128 | }) |
| 129 | + this.sendEvent('ENHANCED', enhanced) |
117 | 130 | } |
118 | 131 |
|
119 | 132 | unregisterDueToModification(textarea: HTMLTextAreaElement): void { |
120 | 133 | const enhanced = this.textareas.get(textarea) |
121 | 134 | if (enhanced) { |
122 | | - this.sendEvent({ |
123 | | - draft: enhanced.textarea.value, |
124 | | - spot: enhanced.spot, |
125 | | - type: 'DESTROYED', |
126 | | - }) |
| 135 | + this.sendEvent('DESTROYED', enhanced) |
127 | 136 | this.textareas.delete(textarea) |
128 | 137 | } |
129 | 138 | } |
|
0 commit comments