a tool for shared writing and social publishing
298
fork

Configure Feed

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

ctrl/shift enter creates new textblock in codeblock

+47 -7
+43 -6
components/Blocks/BaseTextareaBlock.tsx
··· 5 5 import { BlockProps } from "./Block"; 6 6 import { getCoordinatesInTextarea } from "src/utils/getCoordinatesInTextarea"; 7 7 import { focusBlock } from "src/utils/focusBlock"; 8 + import { generateKeyBetween } from "fractional-indexing"; 9 + import { v7 } from "uuid"; 10 + import { elementId } from "src/utils/elementId"; 11 + import { Replicache } from "replicache"; 12 + import { ReplicacheMutators } from "src/replicache"; 8 13 9 - export function BaseTextareaBlock( 10 - props: AutosizeTextareaProps & { 11 - block: Pick<BlockProps, "previousBlock" | "nextBlock">; 12 - }, 13 - ) { 14 - let { block, ...passDownProps } = props; 14 + type BaseTextareaBlockProps = AutosizeTextareaProps & { 15 + block: Pick< 16 + BlockProps, 17 + "previousBlock" | "nextBlock" | "parent" | "position" | "nextPosition" 18 + >; 19 + rep?: Replicache<ReplicacheMutators> | null; 20 + permissionSet?: string; 21 + }; 22 + 23 + export function BaseTextareaBlock(props: BaseTextareaBlockProps) { 24 + let { block, rep, permissionSet, ...passDownProps } = props; 15 25 return ( 16 26 <AsyncValueAutosizeTextarea 17 27 {...passDownProps} 18 28 noWrap 19 29 onKeyDown={(e) => { 30 + // Shift-Enter or Ctrl-Enter: create new text block below and focus it 31 + if ( 32 + (e.shiftKey || e.ctrlKey || e.metaKey) && 33 + e.key === "Enter" && 34 + rep && 35 + permissionSet 36 + ) { 37 + e.preventDefault(); 38 + let newEntityID = v7(); 39 + rep.mutate.addBlock({ 40 + parent: block.parent, 41 + type: "text", 42 + factID: v7(), 43 + permission_set: permissionSet, 44 + position: generateKeyBetween( 45 + block.position, 46 + block.nextPosition || null, 47 + ), 48 + newEntityID, 49 + }); 50 + 51 + setTimeout(() => { 52 + document.getElementById(elementId.block(newEntityID).text)?.focus(); 53 + }, 10); 54 + return true; 55 + } 56 + 20 57 if (e.key === "ArrowUp") { 21 58 let selection = e.currentTarget.selectionStart; 22 59
+4 -1
components/Blocks/CodeBlock.tsx
··· 26 26 let focusedBlock = useUIState( 27 27 (s) => s.focusedEntity?.entityID === props.entityID, 28 28 ); 29 - let { permissions } = useEntitySetContext(); 29 + let entity_set = useEntitySetContext(); 30 + let { permissions } = entity_set; 30 31 const [html, setHTML] = useState<string | null>(null); 31 32 32 33 useLayoutEffect(() => { ··· 125 126 data-entityid={props.entityID} 126 127 id={elementId.block(props.entityID).input} 127 128 block={props} 129 + rep={rep} 130 + permissionSet={entity_set.set} 128 131 spellCheck={false} 129 132 autoCapitalize="none" 130 133 autoCorrect="off"