* @deprecated * handleOnKeyPress is now handled within each block component for more flexibility.
(event: { nativeEvent: { key: string; }; })
| 100 | * handleOnKeyPress is now handled within each block component for more flexibility. |
| 101 | */ |
| 102 | function handleOnKeyPress (event: { nativeEvent: { key: string; }; }) { |
| 103 | const block = updateBlockData(blocks[blockId], { |
| 104 | properties: |
| 105 | { |
| 106 | title: valueRef.current |
| 107 | } |
| 108 | }); |
| 109 | |
| 110 | // This should be handled withing the PageBlock |
| 111 | if (blocksOrder[0] === blockId) return; |
| 112 | |
| 113 | const sourceBlock = block; |
| 114 | const prevTextBlock = findPrevTextBlockInContent(blockId, blocks, textBasedBlocks); |
| 115 | const prevBlock = getPreviousBlockInContent(blockId, blocks); |
| 116 | const targetBlockId = prevTextBlock === undefined ? sourceBlock.parent : prevTextBlock.id; |
| 117 | /** |
| 118 | * If the inmediate previous block is a textblock and that block is empty, |
| 119 | * remove it and keep focus on current block. |
| 120 | * |
| 121 | * Else, merge the current block with the previous block. |
| 122 | */ |
| 123 | if (blocks[targetBlockId].properties.title.length === 0 && targetBlockId !== sourceBlock.parent && prevBlock.type === defaultBlockType) { |
| 124 | requestAnimationFrame(() => { |
| 125 | removeBlock(targetBlockId); |
| 126 | }); |
| 127 | } else { |
| 128 | const { mergeResult } = mergeBlock(block, targetBlockId); |
| 129 | |
| 130 | inputRefs.current[mergeResult.id]?.current.setText(mergeResult.properties.title); |
| 131 | inputRefs.current[mergeResult.id]?.current.setSelection({ |
| 132 | start: mergeResult.properties.title.length - sourceBlock.properties.title.length, |
| 133 | end: mergeResult.properties.title.length - sourceBlock.properties.title.length |
| 134 | }); |
| 135 | inputRefs.current[mergeResult.id]?.current.focus(); |
| 136 | } |
| 137 | |
| 138 | return; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * @deprecated |
no test coverage detected