Skip to content

Commit 28d2c58

Browse files
committed
TextareaRegistry now sends events with less verbosity.
1 parent 2f2431b commit 28d2c58

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

src/lib/registries.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import type { OverTypeInstance } from 'overtype'
22
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'
410
import { CommentEnhancerMissing } from './enhancers/CommentEnhancerMissing'
511
import { GitHubEditEnhancer } from './enhancers/github/GitHubEditEnhancer'
612
import { GitHubIssueAppendEnhancer } from './enhancers/github/GitHubIssueAppendEnhancer'
@@ -101,29 +107,32 @@ export class EnhancerRegistry {
101107

102108
export class TextareaRegistry {
103109
private textareas = new Map<HTMLTextAreaElement, EnhancedTextarea>()
104-
private sendEvent: (event: CommentEvent) => void = () => {}
110+
private eventSender: (event: CommentEvent) => void = () => {}
105111

106112
setCommentEventSender(sendEvent: (event: CommentEvent) => void): void {
107-
this.sendEvent = sendEvent
113+
this.eventSender = sendEvent
108114
}
109115

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({
113118
draft: enhanced.textarea.value,
114119
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)
116128
})
129+
this.sendEvent('ENHANCED', enhanced)
117130
}
118131

119132
unregisterDueToModification(textarea: HTMLTextAreaElement): void {
120133
const enhanced = this.textareas.get(textarea)
121134
if (enhanced) {
122-
this.sendEvent({
123-
draft: enhanced.textarea.value,
124-
spot: enhanced.spot,
125-
type: 'DESTROYED',
126-
})
135+
this.sendEvent('DESTROYED', enhanced)
127136
this.textareas.delete(textarea)
128137
}
129138
}

0 commit comments

Comments
 (0)