Skip to content

Commit faef782

Browse files
author
ntwigg
committed
The enhancers now create the Overtype (as they should).
1 parent 4d0ad6a commit faef782

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

browser-extension/src/datamodel/enhancer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { OverType } from '../overtype/mock-overtype'
2+
13
/**
24
* stores enough info about the location of a draft to:
35
* - display it in a table
@@ -16,7 +18,7 @@ export interface CommentEnhancer<T extends CommentSpot = CommentSpot> {
1618
* whenever a new `textarea` is added to any webpage, this method is called.
1719
* if we return non-null, then we become the handler for that text area.
1820
*/
19-
identifyContextOf(textarea: HTMLTextAreaElement): T | null
21+
tryToEnhance(textarea: HTMLTextAreaElement): [OverType, T] | null
2022

2123
generateIcon(context: T): string
2224
generateDisplayTitle(context: T): string

browser-extension/src/datamodel/handlers/github-handler.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { OverType } from '../../overtype/mock-overtype'
12
import type { CommentEnhancer, CommentSpot } from '../enhancer'
23

34
export type GitHubCommentType =
@@ -30,7 +31,7 @@ export class GitHubHandler implements CommentEnhancer<GitHubContext> {
3031
]
3132
}
3233

33-
identifyContextOf(textarea: HTMLTextAreaElement): GitHubContext | null {
34+
tryToEnhance(textarea: HTMLTextAreaElement): [OverType, GitHubContext] | null {
3435
// Only handle GitHub domains
3536
if (!window.location.hostname.includes('github')) {
3637
return null
@@ -103,7 +104,10 @@ export class GitHubHandler implements CommentEnhancer<GitHubContext> {
103104
unique_key,
104105
}
105106

106-
return context
107+
// Create OverType instance for this textarea
108+
const overtype = new OverType(textarea)
109+
110+
return [overtype, context]
107111
}
108112

109113
generateDisplayTitle(context: GitHubContext): string {

browser-extension/src/datamodel/handlers/reddit-handler.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { OverType } from '../../overtype/mock-overtype'
12
import type { CommentEnhancer, CommentSpot } from '../enhancer'
23

34
export type RedditCommentType = 'REDDIT_POST_NEW' | 'REDDIT_COMMENT_NEW' | 'REDDIT_COMMENT_EDIT'
@@ -14,7 +15,7 @@ export class RedditHandler implements CommentEnhancer<RedditContext> {
1415
return ['REDDIT_POST_NEW', 'REDDIT_COMMENT_NEW', 'REDDIT_COMMENT_EDIT']
1516
}
1617

17-
identifyContextOf(textarea: HTMLTextAreaElement): RedditContext | null {
18+
tryToEnhance(textarea: HTMLTextAreaElement): [OverType, RedditContext] | null {
1819
// Only handle Reddit domains
1920
if (!window.location.hostname.includes('reddit')) {
2021
return null
@@ -80,7 +81,10 @@ export class RedditHandler implements CommentEnhancer<RedditContext> {
8081
unique_key,
8182
}
8283

83-
return context
84+
// Create OverType instance for this textarea
85+
const overtype = new OverType(textarea)
86+
87+
return [overtype, context]
8488
}
8589

8690
generateDisplayTitle(context: RedditContext): string {

browser-extension/src/datamodel/registries.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { OverType } from '../overtype/mock-overtype'
12
import type { CommentEnhancer, CommentSpot } from './enhancer'
23
import { GitHubHandler as GitHubEnhancer } from './handlers/github-handler'
34
import { RedditHandler as RedditEnhancer } from './handlers/reddit-handler'
@@ -6,6 +7,7 @@ export interface EnhancedTextarea<T extends CommentSpot = CommentSpot> {
67
element: HTMLTextAreaElement
78
context: T
89
handler: CommentEnhancer<T>
10+
overtype: OverType
911
}
1012

1113
export class EnhancerRegistry {
@@ -33,9 +35,10 @@ export class EnhancerRegistry {
3335
identifyTextarea(textarea: HTMLTextAreaElement): EnhancedTextarea<any> | null {
3436
for (const handler of this.enhancers) {
3537
try {
36-
const context = handler.identifyContextOf(textarea)
37-
if (context) {
38-
return { context, element: textarea, handler }
38+
const result = handler.tryToEnhance(textarea)
39+
if (result) {
40+
const [overtype, context] = result
41+
return { context, element: textarea, handler, overtype }
3942
}
4043
} catch (error) {
4144
console.warn('Handler failed to identify textarea:', error)

browser-extension/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@
4242
},
4343
"exclude": ["node_modules", ".output", "dist"],
4444
"extends": "./.wxt/tsconfig.json",
45-
"include": ["src/entrypoints/**/*", "*.config.ts", ".wxt/wxt.d.ts", "tests/**/*"]
45+
"include": ["src/**/*", "*.config.ts", ".wxt/wxt.d.ts", "tests/**/*"]
4646
}

0 commit comments

Comments
 (0)