summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--org-roam-ui.el24
-rw-r--r--pages/index.tsx21
2 files changed, 39 insertions, 6 deletions
diff --git a/org-roam-ui.el b/org-roam-ui.el
index ce2eeec..e13349b 100644
--- a/org-roam-ui.el
+++ b/org-roam-ui.el
@@ -690,6 +690,30 @@ Optionally with ID (string), SPEED (number, ms) and PADDING (number, px)."
(padding . ,padding))))))
(message "No node found.")))
+
+(defun org-roam-ui-change-local-graph (&optional id manipulation)
+ "Add or remove current node to the local graph. If not in local mode, open local-graph for this node."
+ (interactive)
+ (if-let ((node (or id (org-roam-id-at-point))))
+ (websocket-send-text org-roam-ui-ws-socket
+ (json-encode `((type . "command")
+ (data . ((commandName . "change-local-graph")
+ (id . ,node)
+ (manipulation . ,(or manipulation "add")))))))
+ (message "No node found.")))
+
+;;;###autoload
+(defun org-roam-ui-add-to-local-graph (&optional id)
+ "Add current node to the local graph. If not in local mode, open local-graph for this node."
+ (interactive)
+ (org-roam-ui-change-local-graph id "add"))
+
+;;;###autoload
+(defun org-roam-ui-remove-from-local-graph (&optional id)
+ "Remove current node from the local graph. If not in local mode, open local-graph for this node."
+ (interactive)
+ (org-roam-ui-change-local-graph id "remove"))
+
;;;###autoload
(defun org-roam-ui-sync-theme ()
"Sync your current Emacs theme with org-roam-ui."
diff --git a/pages/index.tsx b/pages/index.tsx
index ddd3bb7..75b33d3 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -466,7 +466,10 @@ export function GraphPage() {
setEmacsNodeId(message.data.id)
break
}
- case 'add-node-local': {
+ case 'change-local-graph': {
+ console.log(message)
+ handleLocal(nodeByIdRef.current[message.data.id as string], message.data.manipulation)
+ break
}
default:
return console.error('unknown message type', message.type)
@@ -525,7 +528,7 @@ export function GraphPage() {
const handleLocal = (node: OrgRoamNode, command: string) => {
if (command === 'remove') {
setScope((currentScope: Scope) => ({
- ...currentScope,
+ nodeIds: currentScope.nodeIds.filter((id: string) => id !== node.id),
excludedNodeIds: [...currentScope.excludedNodeIds, node.id as string],
}))
return
@@ -538,7 +541,7 @@ export function GraphPage() {
return
}
setScope((currentScope: Scope) => ({
- ...currentScope,
+ excludedNodeIds: currentScope.excludedNodeIds.filter((id: string) => id !== node.id),
nodeIds: [...currentScope.nodeIds, node.id as string],
}))
return
@@ -974,7 +977,11 @@ export const Graph = function (props: GraphProps) {
const links = filteredLinksByNodeIdRef.current[node.id as string] ?? []
return links.some((link) => {
const [source, target] = normalizeLinkEnds(link)
- return scope.nodeIds.includes(source) || scope.nodeIds.includes(target)
+ return (
+ !scope.excludedNodeIds.includes(source) &&
+ !scope.excludedNodeIds.includes(target) &&
+ (scope.nodeIds.includes(source) || scope.nodeIds.includes(target))
+ )
})
}
return neighbs.includes(node.id as string)
@@ -1018,8 +1025,10 @@ export const Graph = function (props: GraphProps) {
}, [
local.neighbors,
filter,
- JSON.stringify(scope),
- JSON.stringify(graphData),
+ scope,
+ scope.excludedNodeIds,
+ scope.nodeIds,
+ graphData,
filteredGraphData.links,
filteredGraphData.nodes,
])