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

Function handleOnKeyPress

packages/blocks/src/TextBlock.tsx:109–160  ·  view source on GitHub ↗
(event: { nativeEvent: { key: string; }; })

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

updateBlockV2Function · 0.85
removeBlockFunction · 0.85

Tested by

no test coverage detected