a tool for shared writing and social publishing
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

focus last block on deletion and focus text if text

+25 -5
+21 -4
components/SelectionManager.tsx
··· 22 22 if (e.key === "Backspace" || e.key === "Delete") { 23 23 if (moreThanOneSelected) { 24 24 let selectedBlocks = useUIState.getState().selectedBlock; 25 - for (let block of selectedBlocks) { 26 - useUIState.getState().closeCard(block.value); 27 - await rep?.mutate.removeBlock({ blockEntity: block.value }); 28 - } 29 25 let firstBlock = selectedBlocks.sort((a, b) => 30 26 a.position > b.position ? 1 : -1, 31 27 )[0]; ··· 34 30 scanIndex(tx).eav(firstBlock.parent, "card/block"), 35 31 ) 36 32 )?.sort((a, b) => (a.data.position > b.data.position ? 1 : -1)); 33 + for (let block of selectedBlocks) { 34 + useUIState.getState().closeCard(block.value); 35 + await rep?.mutate.removeBlock({ blockEntity: block.value }); 36 + } 37 37 let nextBlock = 38 38 siblings?.[ 39 39 siblings.findIndex((s) => s.data.value === firstBlock.value) - 1 ··· 44 44 position: nextBlock.data.position, 45 45 parent: nextBlock.entity, 46 46 }); 47 + let type = await rep?.query((tx) => 48 + scanIndex(tx).eav(nextBlock.data.value, "block/type"), 49 + ); 50 + if (!type?.[0]) return; 51 + if ( 52 + type[0]?.data.value === "text" || 53 + type[0]?.data.value === "heading" 54 + ) 55 + focusBlock( 56 + { 57 + value: nextBlock.data.value, 58 + type: "text", 59 + parent: nextBlock.entity, 60 + position: nextBlock.data.position, 61 + }, 62 + { type: "end" }, 63 + ); 47 64 } 48 65 } 49 66 }
+1 -1
components/TextBlock/index.tsx
··· 473 473 debounce.current = window.setTimeout(() => { 474 474 debounce.current = null; 475 475 476 - if (!view.state.selection) return; 476 + if (!view.state.selection.anchor || !view.docView) return; 477 477 const coords = view.coordsAtPos(view.state.selection.anchor); 478 478 useEditorStates.setState({ lastXPosition: coords.left }); 479 479
+3
components/TextBlock/keymap.ts
··· 168 168 repRef: MutableRefObject<Replicache<ReplicacheMutators> | null>, 169 169 ) => 170 170 (state: EditorState) => { 171 + if (useUIState.getState().selectedBlock.length > 1) { 172 + return false; 173 + } 171 174 if (state.selection.anchor > 1 || state.selection.content().size > 0) { 172 175 return false; 173 176 }