steven-tey / novel

Notion-style WYSIWYG editor with AI-powered autocompletion.
https://novel.sh
Apache License 2.0
13.25k stars 1.08k forks source link

fix: use per-editor instance of tunnel to render slash command popover #305

Closed miikebar closed 9 months ago

miikebar commented 9 months ago

This PR adds per-editor instances of tunnel to render slash command popover

Previously a global tunnel instance was used to render command popover. When using multiple instances of the Editor on the same page, this caused the "/" command to render all the popovers at once.

The proposed solution creates a new tunnel instance for each Editor instance, and passes it down to command components via context. The jotai store is also shared across instances, but it seems that it doesn't matter for now, as it stores the query and range which get reset every time a slash command menu is opened.

Before

https://github.com/steven-tey/novel/assets/9134970/68f886c2-aa06-4611-a753-1cefb77c0b18

After

https://github.com/steven-tey/novel/assets/9134970/68013cdc-25e3-464e-aa6a-25c86427b702

Closes #304

vercel[bot] commented 9 months ago

@miikebar is attempting to deploy a commit to the Elegance Team on Vercel.

A member of the Team first needs to authorize it.

andrewdoro commented 9 months ago

lgtm. Still not sure about the jotai atoms still being synced, I know we can just add a context instead but for now it's fine. I've also seen that we have different formatting rules. (I'll add a prettier config so we are consistent)