Codemirror panel demo : Cursor disappears on closing panel


#1

While checking out the Panel demo, I noticed that if there’s no content in the editor and we close any panel, the cursor at the starting position disappears.

I am trying to implement something similar where i close all the panels when user deletes all the content in the editor. However, as i mentioned above this removes the cursor and it is slightly inconvenient to click inside the editor to make the cursor re-appear.

On some trial and error, i found out that this occurs when we call panel.clear(), however i’m not able to understand why this is occurring. Is there any way to resolve this?

P.S. I tried to call setCursor({line:0, ch:1}) after the call to panel.clear() but it still doesn’t work.


#2

I think you’ll want to call editor.focus(). The click on the panel likely moves the focus away from the editor (unless you use mousedown events and call event.preventDefault()). I’ve updated the demo to fix the issue there.


#3

Thanks. This works.