(options: ClickHandlerOptions)
| 39 | * Ctrl/Cmd + Click: Opens source note immediately |
| 40 | */ |
| 41 | export function createTaskClickHandler(options: ClickHandlerOptions) { |
| 42 | const { |
| 43 | task, |
| 44 | plugin, |
| 45 | excludeSelector, |
| 46 | onSingleClick, |
| 47 | onDoubleClick, |
| 48 | contextMenuHandler, |
| 49 | createBatchContextMenu, |
| 50 | } = options; |
| 51 | const clickExcludeSelector = excludeSelector |
| 52 | ? `${DEFAULT_EXCLUDE_SELECTOR}, ${excludeSelector}` |
| 53 | : DEFAULT_EXCLUDE_SELECTOR; |
| 54 | |
| 55 | let clickTimeout: number | null = null; |
| 56 | |
| 57 | const openNote = (newTab = false) => { |
| 58 | const file = plugin.app.vault.getAbstractFileByPath(task.path); |
| 59 | if (file instanceof TFile) { |
| 60 | if (newTab) { |
| 61 | void plugin.app.workspace.openLinkText(task.path, "", true); |
| 62 | } else { |
| 63 | void plugin.app.workspace.getLeaf(false).openFile(file); |
| 64 | } |
| 65 | } |
| 66 | }; |
| 67 | |
| 68 | const editTask = async () => { |
| 69 | await plugin.openTaskEditModal(task); |
| 70 | }; |
| 71 | |
| 72 | const handleSingleClick = async (e: MouseEvent) => { |
| 73 | if (onSingleClick) { |
| 74 | await onSingleClick(e); |
| 75 | return; |
| 76 | } |
| 77 | |
| 78 | if (e.ctrlKey || e.metaKey) { |
| 79 | openNote(true); // Open in new tab |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | const action = plugin.settings.singleClickAction; |
| 84 | if (action === "edit") { |
| 85 | await editTask(); |
| 86 | } else if (action === "openNote") { |
| 87 | openNote(false); // Open in current tab |
| 88 | } |
| 89 | }; |
| 90 | |
| 91 | const handleDoubleClick = async (e: MouseEvent) => { |
| 92 | if (onDoubleClick) { |
| 93 | await onDoubleClick(e); |
| 94 | return; |
| 95 | } |
| 96 | |
| 97 | const action = plugin.settings.doubleClickAction; |
| 98 | if (action === "edit") { |
no test coverage detected