MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / codeBlockModelText

Function codeBlockModelText

web/src/lib/components/editor/codeBlockCopy.ts:25–34  ·  view source on GitHub ↗
(
	view: { state: { doc: { nodeAt(pos: number): { type: { name: string }; textContent: string } | null } } },
	getPos: (() => number | undefined) | undefined,
)

Source from the content-addressed store, hash-verified

23 * view ProseMirror has since discarded answers null instead of stale text.
24 */
25export function codeBlockModelText(
26 view: { state: { doc: { nodeAt(pos: number): { type: { name: string }; textContent: string } | null } } },
27 getPos: (() => number | undefined) | undefined,
28): string | null {
29 const pos = typeof getPos === 'function' ? getPos() : undefined;
30 if (typeof pos !== 'number') return null;
31 const node = view.state.doc.nodeAt(pos);
32 if (!node || node.type.name !== 'codeBlock') return null;
33 return node.textContent;
34}
35
36/**
37 * A hover-to-reveal "Copy" button. `getText` is called on each click; null

Callers 1

createPlainCodeBlockViewFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected