()
| 143 | * handleSubmitEditing is now handled within each block component for more flexibility. |
| 144 | */ |
| 145 | const handleSubmitEditing = () => { |
| 146 | const block = updateBlockData( |
| 147 | blocks[blockId], |
| 148 | { |
| 149 | properties: |
| 150 | { |
| 151 | title: valueRef.current, |
| 152 | } |
| 153 | } |
| 154 | ); |
| 155 | const selection = selectionRef.current; |
| 156 | |
| 157 | /** |
| 158 | * This is a hack. |
| 159 | * When splitting a block into another block type, the current block must rerender to change to the corresponding block component. |
| 160 | * That rerender can make the keyboard flicker, so to prevent that we need to focus the ghost input and after the render, focus the block again. |
| 161 | * */ |
| 162 | if (block.type !== defaultBlockType) { |
| 163 | inputRefs.current["ghostInput"]?.current.focus(); |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * The timeout is bearly noticeable, but it is needed to prevent the keyboard from flickering. |
| 168 | * It gives times for the ghost input to be focused before rerendering any block, preventing |
| 169 | * keyboard flickering. |
| 170 | */ |
| 171 | |
| 172 | const { nextBlock } = splitBlock(block, selection); |
| 173 | |
| 174 | inputRefs.current[nextBlock.id]?.current.setText(nextBlock.properties.title); |
| 175 | setTimeout(() => { |
| 176 | inputRefs.current[nextBlock.id]?.current.setSelection({ |
| 177 | start: 0, |
| 178 | end: 0 |
| 179 | }); |
| 180 | inputRefs.current[nextBlock.id]?.current.focus(); |
| 181 | }, 0); |
| 182 | |
| 183 | return; |
| 184 | }; |
| 185 | |
| 186 | const handleOnFocus = () => { |
| 187 | setFocusedBlockId(blockId); |
nothing calls this directly
no test coverage detected