a tool for shared writing and social publishing

add highlight shortcut

+19 -5
+19 -5
components/SelectionManager.tsx
··· 186 186 handler: async () => { 187 187 let [sortedBlocks] = await getSortedSelectionBound(); 188 188 toggleMarkInBlocks( 189 - schema.marks.underline, 190 189 sortedBlocks.filter((b) => b.type === "text").map((b) => b.value), 190 + schema.marks.underline, 191 191 ); 192 192 }, 193 193 }, ··· 197 197 handler: async () => { 198 198 let [sortedBlocks] = await getSortedSelectionBound(); 199 199 toggleMarkInBlocks( 200 + sortedBlocks.filter((b) => b.type === "text").map((b) => b.value), 200 201 schema.marks.em, 201 - sortedBlocks.filter((b) => b.type === "text").map((b) => b.value), 202 202 ); 203 203 }, 204 204 }, ··· 208 208 handler: async () => { 209 209 let [sortedBlocks] = await getSortedSelectionBound(); 210 210 toggleMarkInBlocks( 211 + sortedBlocks.filter((b) => b.type === "text").map((b) => b.value), 211 212 schema.marks.strong, 213 + ); 214 + }, 215 + }, 216 + { 217 + metaAndCtrl: true, 218 + key: "h", 219 + handler: async () => { 220 + let [sortedBlocks] = await getSortedSelectionBound(); 221 + toggleMarkInBlocks( 212 222 sortedBlocks.filter((b) => b.type === "text").map((b) => b.value), 223 + schema.marks.highlight, 224 + { 225 + color: useUIState.getState().lastUsedHighlight, 226 + }, 213 227 ); 214 228 }, 215 229 }, ··· 219 233 handler: async () => { 220 234 let [sortedBlocks] = await getSortedSelectionBound(); 221 235 toggleMarkInBlocks( 222 - schema.marks.strikethrough, 223 236 sortedBlocks.filter((b) => b.type === "text").map((b) => b.value), 237 + schema.marks.strikethrough, 224 238 ); 225 239 }, 226 240 }, ··· 716 730 ]; 717 731 }; 718 732 719 - function toggleMarkInBlocks(mark: MarkType, blocks: string[]) { 733 + function toggleMarkInBlocks(blocks: string[], mark: MarkType, attrs?: any) { 720 734 let everyBlockHasMark = blocks.reduce((acc, block) => { 721 735 let editor = useEditorStates.getState().editorStates[block]; 722 736 if (!editor) return acc; ··· 739 753 if (everyBlockHasMark) { 740 754 tr.removeMark(from, to, mark); 741 755 } else { 742 - tr.addMark(from, to, mark.create()); 756 + tr.addMark(from, to, mark.create(attrs)); 743 757 } 744 758 745 759 view.dispatch(tr);