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

Listening event of node selection #160

Closed
florianleux opened this issue Aug 17, 2021 · 1 comment
Closed

Listening event of node selection #160

florianleux opened this issue Aug 17, 2021 · 1 comment

Comments

@florianleux
Copy link

Hello

I was wondering if there is any way to catch the selection of node (when you click on it in the editor and outline it).
I looked into both .events and .hooks but did not find anything related to this event.

The doc does not mention any way to do it, is it even possible ?

Thanks for your help and you very good work on this project !

@newcat
Copy link
Owner

newcat commented Aug 17, 2021

It is possible, but with a little bit of a workaround:

  1. Add ref="editor" (or whatever name you want the ref to have) to the <baklava-editor> element in the HTML like this:
<baklava-editor ref="editor" :plugin="viewPlugin" />
  1. Now you can watch the selectedNodes change:
mounted() {
    this.$watch("$refs.editor.selectedNodes", () => {
        if (!this.$refs.editor) {
            return;
        }
        console.log(this.$refs.editor.selectedNodes.map(n => n.id));
    });
}

I have a full example here: https://codesandbox.io/s/baklavajs-example-selectevent-1klxj?file=/src/App.vue

And thanks for the kind words, appreciate it :)

@newcat newcat closed this as completed Aug 17, 2021
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

2 participants