Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

placeholder with HTMLElement, when shared between multiple views, is only visible on one view #1395

Open
ralismark opened this issue Jun 18, 2024 · 0 comments

Comments

@ralismark
Copy link

ralismark commented Jun 18, 2024

Describe the issue

If a single instance of the placeholder extension is created by passing a HTMLElement, then the extension is used in multiple views, the placeholder is only visible in one of them.

This is because when appendChild is used to add the placeholder element, it gets removed from the previous parent.

While there is a way to duplicate an element, I think it would be preferable if you fixed this by letting the user provide a way to create and destroy placeholder elements.

Browser and platform

No response

Reproduction link

https://codemirror.net/try/?c=aW1wb3J0IHttaW5pbWFsU2V0dXAsIEVkaXRvclZpZXd9IGZyb20gImNvZGVtaXJyb3IiCmltcG9ydCB7cGxhY2Vob2xkZXJ9IGZyb20gIkBjb2RlbWlycm9yL3ZpZXciCgpjb25zdCBwbGNFbGVtID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgiZGl2IikKcGxjRWxlbS5pbm5lclRleHQgPSAicGxhY2Vob2xkZXIgZWxlbWVudCEiCgpjb25zdCBwbGMgPSBwbGFjZWhvbGRlcihwbGNFbGVtKQoKZm9yIChjb25zdCBfIG9mIFswLCAxXSkgewogIGNvbnN0IHBhcmVudCA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoImRpdiIpCiAgZG9jdW1lbnQuYm9keS5hcHBlbmRDaGlsZChwYXJlbnQpCiAgbmV3IEVkaXRvclZpZXcoewogICAgZXh0ZW5zaW9uczogcGxjLAogICAgcGFyZW50OiBwYXJlbnQsCiAgfSkKfQ==

import {minimalSetup, EditorView} from "codemirror"
import {placeholder} from "@codemirror/view"

const plcElem = document.createElement("div")
plcElem.innerText = "placeholder element!"

const plc = placeholder(plcElem)

for (const _ of [0, 1]) {
  const parent = document.createElement("div")
  document.body.appendChild(parent)
  new EditorView({
    extensions: plc,
    parent: parent,
  })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant