codemirror / dev

Development repository for the CodeMirror editor project
https://codemirror.net/
Other
5.94k stars 376 forks source link

codemirror/view's placeholder cloneNode loses its `onclick` #1457

Closed mscolnick closed 3 weeks ago

mscolnick commented 3 weeks ago

Describe the issue

Since codemirror/view 6.34.0, the cloneNode on placeholder will remove any event listeners. I think the workaround is to pass in a function, but this was a subtle regression

https://developer.mozilla.org/en-US/docs/Web/API/Node/cloneNode

Cloning a node copies all of its attributes and their values, including intrinsic (inline) listeners. It does not copy event listeners added using addEventListener() or those assigned to element properties (e.g., node.onclick = someFunction)

Browser and platform

No response

Reproduction link

No response

marijnh commented 3 weeks ago

I'm aware. But the old system had a worse problem, and I don't think there's a reasonable way to preserve event handlers on cloned nodes. Using a function is a much better solution anyway, since you'll actually have access to the view, which you probably need for most kinds of click interactions, and which was very awkward to get in the old style. So this is not something that's going to change.

mscolnick commented 3 weeks ago

Sounds good, totally ok with that path forward. Thanks for the great work on this library.