({ blockId } : Props)
| 25 | } |
| 26 | |
| 27 | export function TextBlock({ blockId } : Props) { |
| 28 | const { getTextInputProps, getValue, getSelection } = useTextInput(blockId); |
| 29 | const { inputRefs, textBasedBlocks } = useTextBlocksContext(); |
| 30 | const { |
| 31 | blocks, |
| 32 | insertBlock, |
| 33 | updateBlockV2, |
| 34 | removeBlock |
| 35 | } = useBlocksContext(); |
| 36 | |
| 37 | const handleSubmitEditing = () => { |
| 38 | const value = getValue(); |
| 39 | const selection = getSelection(); |
| 40 | |
| 41 | if (selection.start === 0 && selection.end === 0) { |
| 42 | const newBlock = createBlock({ |
| 43 | type: "text", |
| 44 | properties: { |
| 45 | title: "" |
| 46 | }, |
| 47 | parent: blocks[blockId].parent, |
| 48 | content: [] |
| 49 | }); |
| 50 | |
| 51 | insertBlock(newBlock, { |
| 52 | nextBlockId: blockId |
| 53 | }); |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | if (selection.start === value.length && selection.end === value.length) { |
| 58 | const newBlock = createBlock({ |
| 59 | type: "text", |
| 60 | properties: { |
| 61 | title: "" |
| 62 | }, |
| 63 | parent: blocks[blockId].parent, |
| 64 | content: [] |
| 65 | }); |
| 66 | |
| 67 | insertBlock(newBlock, { |
| 68 | prevBlockId: blockId |
| 69 | }); |
| 70 | |
| 71 | requestAnimationFrame(() => { |
| 72 | inputRefs.current[newBlock.id]?.current.focus(); |
| 73 | }); |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | const textBeforeSelection = value.substring(0, selection.start); |
| 78 | const textAfterSelection = value.substring(selection.end); |
| 79 | |
| 80 | const newBlock = createBlock({ |
| 81 | type: "text", |
| 82 | properties: { |
| 83 | title: textAfterSelection |
| 84 | }, |
nothing calls this directly
no test coverage detected