steven-tey / novel

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

Text range selected as prompt during AI autocomplete. #248

Open utautattaro opened 9 months ago

utautattaro commented 9 months ago

Hi! I have self-hosted novel and love it.

When using AI autocomplete, there was a problem that 5000 characters from the focused current location were called as a prompt due to the following location, which did not result in a proper prompt.

https://github.com/steven-tey/novel/blob/b4526fc63175caed02bdbfbee490e87b3466dd1c/packages/core/src/ui/editor/index.tsx#L114-L118

I tested this in my environment and was able to change the process so that only the paragraph in which the cursor is focused is recognized as a prompt by using document.getSelection().

let select = document.getSelection();
complete(
  (select as any).baseNode.textContent
);

I am considering sending you a PR if you would like to do so. Thank you in advance!