I have a custom button for the user to start a search interaction. How could I programmatically open the search panel in response to the user clicking on that button?
I found this answer that uses document.querySelector("#myButton").onclick = function(){ editor.execCommand("find"); };. But I couldn’t make this work, I suppose this not apply to my package versions:
I searched through the documentation for a way to execute this command but could not find how. I also did some trial and error but with no success.
// adapted from the real code: https://github.com/joaomelo/textorama/blob/main/src/view-editor.vue
import { openSearchPanel } from "@codemirror/search";
let editorView = null;
onMounted(() => {
editorView = new EditorView({ ... });
});
watch(
() => props.showSearch,
(newShowSearch) => {
console.log({ newShowSearch }); // this happens
// but none of these attempts work
openSearchPanel();
editorView.dispatch(openSearchPanel);
editorView.execCommand(openSearchPanel);
}
);
Can you give some direction on how to dispatch the openSearchPanel command programmatically?