diff options
| author | Dhravya Shah <[email protected]> | 2024-06-18 17:58:46 -0500 |
|---|---|---|
| committer | Dhravya Shah <[email protected]> | 2024-06-18 17:58:46 -0500 |
| commit | f4bb71e8f7e07bb2e919b7f222d5acb2905eb8f2 (patch) | |
| tree | 7310dc521ef3559055bbe71f50c3861be2fa0503 /apps/web/app/(editor)/ai.md | |
| parent | darkmode by default - so that the colors don't f up on lightmode devices (diff) | |
| parent | Create Embeddings for Canvas (diff) | |
| download | supermemory-default-darkmode.tar.xz supermemory-default-darkmode.zip | |
Diffstat (limited to 'apps/web/app/(editor)/ai.md')
| -rw-r--r-- | apps/web/app/(editor)/ai.md | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/apps/web/app/(editor)/ai.md b/apps/web/app/(editor)/ai.md new file mode 100644 index 00000000..1528a7bd --- /dev/null +++ b/apps/web/app/(editor)/ai.md @@ -0,0 +1,43 @@ +## to access the editor +``` +import { useEditor } from "novel"; +const editor = useEditor() +``` + +## to get previous text +``` +import { getPrevText } from "novel/utils"; +const pos = editor.state.selection.from; +const text = getPrevText(editor, pos); +``` + +## selected content into markdown format +``` +const slice = editor.state.selection.content(); +const text = editor.storage.markdown.serializer.serialize(slice.content); +``` + +## replace Selection +``` +const selection = editor.view.state.selection; +editor.chain().focus() + .insertContentAt( + { + from: selection.from, + to: selection.to, + }, + completion, + ) + .run(); +``` + + +## to insert after +``` +const selection = editor.view.state.selection; +editor + .chain() + .focus() + .insertContentAt(selection.to + 1, completion) + .run(); +``` |