MCPcopy
hub / github.com/callumalpass/tasknotes / handleContextMenu

Function handleContextMenu

src/utils/clickHandlers.ts:185–232  ·  view source on GitHub ↗
(e: MouseEvent)

Source from the content-addressed store, hash-verified

183 };
184
185 const handleContextMenu = async (e: MouseEvent) => {
186 e.preventDefault();
187 e.stopPropagation(); // Prevent event from bubbling to parent cards
188
189 const selectionService = plugin.taskSelectionService;
190
191 // Shift+right-click adds to selection and opens batch context menu
192 if (e.shiftKey && selectionService) {
193 if (!selectionService.isSelectionModeActive()) {
194 selectionService.enterSelectionMode();
195 }
196 if (!selectionService.isSelected(task.path)) {
197 selectionService.addToSelection(task.path);
198 }
199
200 // Show batch context menu if we have selections
201 if (selectionService.getSelectionCount() > 0) {
202 const menu = createBatchContextMenu?.(selectionService.getSelectedPaths(), () => {});
203 menu?.show(e);
204 }
205 return;
206 }
207
208 // Check if multiple tasks are selected - show batch context menu
209 if (selectionService && selectionService.getSelectionCount() > 1) {
210 // Ensure the right-clicked task is in the selection
211 if (!selectionService.isSelected(task.path)) {
212 selectionService.addToSelection(task.path);
213 }
214
215 // Import and show batch context menu
216 const menu = createBatchContextMenu?.(selectionService.getSelectedPaths(), () => {
217 // Views will refresh via events
218 });
219 menu?.show(e);
220 return;
221 }
222
223 // Opening a single-task context menu exits selection mode
224 if (selectionService?.isSelectionModeActive()) {
225 selectionService.clearSelection();
226 selectionService.exitSelectionMode();
227 }
228
229 if (contextMenuHandler) {
230 await contextMenuHandler(e);
231 }
232 };
233
234 const contextmenuHandler = (event: MouseEvent) => {
235 void handleContextMenu(event);

Callers 1

contextmenuHandlerFunction · 0.85

Calls 9

isSelectionModeActiveMethod · 0.80
enterSelectionModeMethod · 0.80
isSelectedMethod · 0.80
addToSelectionMethod · 0.80
getSelectionCountMethod · 0.80
getSelectedPathsMethod · 0.80
clearSelectionMethod · 0.80
exitSelectionModeMethod · 0.80
showMethod · 0.65

Tested by

no test coverage detected