MCPcopy Create free account
hub / github.com/FormidableLabs/use-editable / toString

Function toString

src/useEditable.ts:30–51  ·  view source on GitHub ↗
(element: HTMLElement)

Source from the content-addressed store, hash-verified

28 (event.metaKey || event.ctrlKey) && !event.altKey && event.code === 'KeyZ';
29
30const toString = (element: HTMLElement): string => {
31 const queue: Node[] = [element.firstChild!];
32
33 let content = '';
34 let node: Node;
35 while ((node = queue.pop()!)) {
36 if (node.nodeType === Node.TEXT_NODE) {
37 content += node.textContent;
38 } else if (node.nodeType === Node.ELEMENT_NODE && node.nodeName === 'BR') {
39 content += '\n';
40 }
41
42 if (node.nextSibling) queue.push(node.nextSibling);
43 if (node.firstChild) queue.push(node.firstChild);
44 }
45
46 // contenteditable Quirk: Without plaintext-only a pre/pre-wrap element must always
47 // end with at least one newline character
48 if (content[content.length - 1] !== '\n') content += '\n';
49
50 return content;
51};
52
53const setStart = (range: Range, node: Node, offset: number) => {
54 if (offset < node.textContent!.length) {

Callers 6

updateFunction · 0.85
moveFunction · 0.85
getStateFunction · 0.85
trackStateFunction · 0.85
flushChangesFunction · 0.85
onKeyDownFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…