a tool for shared writing and social publishing
0
fork

Configure Feed

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

add undo for setting inline link

+20 -1
+20 -1
components/Toolbar/InlineLinkToolbar.tsx
··· 9 9 import { setEditorState, useEditorStates } from "src/state/useEditorState"; 10 10 import { rangeHasMark } from "src/utils/prosemirror/rangeHasMark"; 11 11 import { Input } from "components/Input"; 12 + import { useReplicache } from "src/replicache"; 12 13 13 14 export function LinkButton(props: { setToolbarState: (s: "link") => void }) { 14 15 let focusedBlock = useUIState((s) => s.focusedEntity); ··· 52 53 let focusedEditor = useEditorStates((s) => 53 54 focusedBlock ? s.editorStates[focusedBlock.entityID] : null, 54 55 ); 56 + let { undoManager } = useReplicache(); 55 57 useEffect(() => { 56 58 if (focusedEditor) { 57 59 let isLink; ··· 103 105 let tr = editor.tr; 104 106 tr.addMark(start, end, schema.marks.link.create({ href })); 105 107 tr.setSelection(TextSelection.create(tr.doc, tr.selection.to)); 108 + 109 + let oldState = editor; 110 + let newState = editor.apply(tr); 111 + undoManager.add({ 112 + undo: () => { 113 + if (!focusedEditor?.view?.hasFocus()) focusedEditor?.view?.focus(); 114 + setEditorState(focusedBlock.entityID, { 115 + editor: oldState, 116 + }); 117 + }, 118 + redo: () => { 119 + if (!focusedEditor?.view?.hasFocus()) focusedEditor?.view?.focus(); 120 + setEditorState(focusedBlock.entityID, { 121 + editor: newState, 122 + }); 123 + }, 124 + }); 106 125 setEditorState(focusedBlock?.entityID, { 107 - editor: editor.apply(tr), 126 + editor: newState, 108 127 }); 109 128 props.onClose(); 110 129 };