Skip to content

Commit 180b258

Browse files
author
ntwigg
committed
very small fixup - don't do the query if the thing is itself a textarea
1 parent 0f354d9 commit 180b258

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

browser-extension/src/entrypoints/content.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { logger } from './content/logger'
2-
import { injectStyles } from './content/styles'
31
import { HandlerRegistry } from '../datamodel/handler-registry'
42
import { TextareaRegistry } from '../datamodel/textarea-registry'
3+
import { logger } from './content/logger'
4+
import { injectStyles } from './content/styles'
55

66
const handlerRegistry = new HandlerRegistry()
77
const textareaRegistry = new TextareaRegistry()
@@ -31,12 +31,13 @@ function handleMutations(mutations: MutationRecord[]): void {
3131
const element = node as Element
3232
if (element.tagName === 'TEXTAREA') {
3333
initializeMaybeIsPageload(element as HTMLTextAreaElement)
34-
}
35-
// Also check for textareas within added subtrees
36-
const textareas = element.querySelectorAll?.('textarea')
37-
if (textareas) {
38-
for (const textarea of textareas) {
39-
initializeMaybeIsPageload(textarea)
34+
} else {
35+
// Also check for textareas within added subtrees
36+
const textareas = element.querySelectorAll?.('textarea')
37+
if (textareas) {
38+
for (const textarea of textareas) {
39+
initializeMaybeIsPageload(textarea)
40+
}
4041
}
4142
}
4243
}
@@ -48,12 +49,13 @@ function handleMutations(mutations: MutationRecord[]): void {
4849
const element = node as Element
4950
if (element.tagName === 'TEXTAREA') {
5051
textareaRegistry.unregisterDueToModification(element as HTMLTextAreaElement)
51-
}
52-
// Also check for textareas within removed subtrees
53-
const textareas = element.querySelectorAll?.('textarea')
54-
if (textareas) {
55-
for (const textarea of textareas) {
56-
textareaRegistry.unregisterDueToModification(textarea)
52+
} else {
53+
// Also check for textareas within removed subtrees
54+
const textareas = element.querySelectorAll?.('textarea')
55+
if (textareas) {
56+
for (const textarea of textareas) {
57+
textareaRegistry.unregisterDueToModification(textarea)
58+
}
5759
}
5860
}
5961
}
@@ -70,7 +72,7 @@ function initializeMaybeIsPageload(textarea: HTMLTextAreaElement) {
7072

7173
logger.debug('activating textarea {}', textarea)
7274
injectStyles()
73-
75+
7476
// Use registry to identify and handle this specific textarea
7577
const textareaInfo = handlerRegistry.identifyTextarea(textarea)
7678
if (textareaInfo) {

0 commit comments

Comments
 (0)