Allow de-selecting of nodes.

This commit is contained in:
Tom Alexander 2024-01-28 01:11:21 -05:00
parent 5d31d50863
commit f89e62b9e1
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 11 additions and 4 deletions

View File

@ -38,7 +38,6 @@
.OrgAstNode.hovered:not(.selected) {
> .OrgAstNodeType {
background: #70f8ba;
cursor: pointer;
}
}
@ -46,6 +45,7 @@
background: #6ccff6;
padding: 3px;
overflow: hidden;
cursor: pointer;
> span:first-child {
font-size: 1.1rem;

View File

@ -14,10 +14,17 @@ const OrgAst = (props: {
const [hoveredNode, setHoveredNode] = useState<OrgNodeReference | null>(null);
function selectNode(uid: string, start: number, end: number) {
if (selectedNode !== null && selectedNode.uid === uid) {
props.setHighlight([hoveredNode].filter((node) => node !== null));
setSelectedNode(null);
} else {
const new_node: OrgNodeReference = { uid: uid, start: start, end: end };
props.setHighlight([new_node, hoveredNode].filter((node) => node !== null));
props.setHighlight(
[new_node, hoveredNode].filter((node) => node !== null),
);
setSelectedNode({ uid: uid, start: start, end: end });
}
}
function startHoverNode(uid: string, start: number, end: number) {
const new_node: OrgNodeReference = { uid: uid, start: start, end: end };