a tool for shared writing and social publishing
0
fork

Configure Feed

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

changed default highlight to use accent color

celine 9ccf38d5 36bef8ac

+40 -1
+40 -1
components/Blocks/TextBlock/useHandlePaste.ts
··· 16 16 import { TextSelection } from "prosemirror-state"; 17 17 import { FilterAttributes } from "src/replicache/attributes"; 18 18 import { addLinkBlock } from "src/utils/addLinkBlock"; 19 + import { UndoManager } from "src/undoManager"; 19 20 20 21 const parser = ProsemirrorDOMParser.fromSchema(schema); 21 22 export const useHandlePaste = ( ··· 23 24 propsRef: MutableRefObject<BlockProps>, 24 25 factID?: string, 25 26 ) => { 26 - let { rep } = useReplicache(); 27 + let { rep, undoManager } = useReplicache(); 27 28 let entity_set = useEntitySetContext(); 28 29 return useCallback( 29 30 (view: EditorView, e: ClipboardEvent) => { ··· 57 58 if (!(children.length === 1 && children[0].tagName === "IMG")) { 58 59 children.forEach((child, index) => { 59 60 createBlockFromHTML(child, { 61 + undoManager, 60 62 parentType: propsRef.current.pageType, 61 63 first: index === 0, 62 64 activeBlockProps: propsRef, ··· 128 130 last, 129 131 activeBlockProps, 130 132 rep, 133 + undoManager, 131 134 entity_set, 132 135 getPosition, 133 136 parent, ··· 139 142 last: boolean; 140 143 activeBlockProps?: MutableRefObject<BlockProps>; 141 144 rep: Replicache<ReplicacheMutators>; 145 + undoManager: UndoManager; 142 146 entity_set: { set: string }; 143 147 getPosition: () => string; 144 148 }, ··· 157 161 last: last && c === children[children.length - 1], 158 162 activeBlockProps, 159 163 rep, 164 + undoManager, 160 165 entity_set, 161 166 getPosition, 162 167 parent, ··· 380 385 last: last, 381 386 activeBlockProps, 382 387 rep, 388 + undoManager, 383 389 entity_set, 384 390 getPosition: () => { 385 391 currentPosition = generateKeyBetween(currentPosition, null); ··· 400 406 let newState = block.editor.apply(tr); 401 407 setEditorState(entityID, { 402 408 editor: newState, 409 + }); 410 + 411 + undoManager.add({ 412 + redo: () => { 413 + useEditorStates.setState((oldState) => { 414 + let view = oldState.editorStates[entityID]?.view; 415 + if (!view?.hasFocus()) view?.focus(); 416 + return { 417 + editorStates: { 418 + ...oldState.editorStates, 419 + [entityID]: { 420 + ...oldState.editorStates[entityID]!, 421 + editor: newState, 422 + }, 423 + }, 424 + }; 425 + }); 426 + }, 427 + undo: () => { 428 + useEditorStates.setState((oldState) => { 429 + let view = oldState.editorStates[entityID]?.view; 430 + if (!view?.hasFocus()) view?.focus(); 431 + return { 432 + editorStates: { 433 + ...oldState.editorStates, 434 + [entityID]: { 435 + ...oldState.editorStates[entityID]!, 436 + editor: block.editor, 437 + }, 438 + }, 439 + }; 440 + }); 441 + }, 403 442 }); 404 443 } 405 444 if (last && !hasChildren) {