Skip to content

Commit 7d7067e

Browse files
committed
Use MutationObserver to make sure we update when pictures get dragged-on.
1 parent 9eb2fb3 commit 7d7067e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/lib/enhancers/modifyDOM.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,18 @@ export function fixupOvertype(instances: OverTypeInstance[]): OverTypeInstance {
77
`Expected OverType to return exactly 1 instance, got ${instances.length}`
88
)
99
}
10-
return instances[0]!
10+
const overtype = instances[0]!
11+
// this works, but we're now updating twice as often as we need to, because
12+
// overtype has a built-in update which usually works but not always (#101)
13+
// and we're doing this which does always work
14+
const updateOnChange = new MutationObserver(() => {
15+
overtype.updatePreview()
16+
})
17+
updateOnChange.observe(overtype.textarea, {
18+
attributes: true,
19+
characterData: true,
20+
})
21+
return overtype
1122
}
1223

1324
// Modify the DOM to trick overtype into adopting it instead of recreating it

0 commit comments

Comments
 (0)