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

Function handleOnKeyPress

packages/blocks/src/SubHeaderBlock.tsx:114–167  ·  view source on GitHub ↗
(event: { nativeEvent: { key: string; }; })

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

updateBlockV2Function · 0.85
removeBlockFunction · 0.85

Tested by

no test coverage detected