MCPcopy
hub / github.com/steven-tey/novel / getPrevText

Function getPrevText

packages/core/src/lib/editor.ts:3–21  ·  view source on GitHub ↗
(
  editor: Editor,
  {
    chars,
    offset = 0,
  }: {
    chars: number;
    offset?: number;
  }
)

Source from the content-addressed store, hash-verified

1import { Editor } from "@tiptap/core";
2
3export const getPrevText = (
4 editor: Editor,
5 {
6 chars,
7 offset = 0,
8 }: {
9 chars: number;
10 offset?: number;
11 }
12) => {
13 // for now, we're using textBetween for now until we can figure out a way to stream markdown text
14 // with proper formatting: https://github.com/steven-tey/novel/discussions/7
15 return editor.state.doc.textBetween(
16 Math.max(0, editor.state.selection.from - chars),
17 editor.state.selection.from - offset,
18 "\n"
19 );
20 // complete(editor.storage.markdown.getMarkdown());
21};

Callers 2

EditorFunction · 0.90
CommandListFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected