MCPcopy Create free account
hub / github.com/PatoSala/react-native-blocks / handleOnKeyPress

Function handleOnKeyPress

packages/blocks/src/SubSubHeaderBlock.tsx:113–166  ·  view source on GitHub ↗
(event: { nativeEvent: { key: string; }; })

Source from the content-addressed store, hash-verified

111 }
112
113 const handleOnKeyPress = (event: { nativeEvent: { key: string; }; }) => {
114 const value = getValue();
115 const selection = getSelection();
116
117 if (event.nativeEvent.key === "Backspace" && selection.start === 0 && selection.end === 0) {
118 // findPrevTextBlock
119
120 inputRefs.current["ghostInput"]?.current.focus();
121
122 const previousTextBlock = findPrevTextBlockInContent(blockId, blocks, textBasedBlocks);
123
124 if (previousTextBlock === undefined) {
125 const parentBlock = blocks[blocks[blockId].parent];
126 const isTextBased = textBasedBlocks.includes(parentBlock.type);
127
128 if (isTextBased) {
129 updateBlockV2(parentBlock.id, {
130 properties: {
131 title: parentBlock.properties.title + value
132 }
133 });
134 removeBlock(blockId);
135
136
137
138 requestAnimationFrame(() => {
139 inputRefs.current[parentBlock.id]?.current.setText(parentBlock.properties.title + value);
140 inputRefs.current[parentBlock.id]?.current.setSelection({
141 start: parentBlock.properties.title.length,
142 end: parentBlock.properties.title.length
143 })
144 inputRefs.current[parentBlock.id]?.current.focus();
145 });
146 }
147 return;
148 }
149
150 updateBlockV2(previousTextBlock.id, {
151 properties: {
152 title: previousTextBlock.properties.title + value
153 }
154 });
155 removeBlock(blockId);
156
157 requestAnimationFrame(() => {
158 inputRefs.current[previousTextBlock.id]?.current.setText(previousTextBlock.properties.title + value);
159 inputRefs.current[previousTextBlock.id]?.current.setSelection({
160 start: previousTextBlock.properties.title.length,
161 end: previousTextBlock.properties.title.length
162 })
163 inputRefs.current[previousTextBlock.id]?.current.focus();
164 });
165 }
166 };
167
168 return (
169 <DragProvider blockId={blockId}>

Callers

nothing calls this directly

Calls 3

updateBlockV2Function · 0.85
removeBlockFunction · 0.85

Tested by

no test coverage detected