Skip to content

Commit

Permalink
use : as suggested edge delimiter, fix issue with suggested edge doub…
Browse files Browse the repository at this point in the history
…le click handler
  • Loading branch information
wernst committed Aug 12, 2021
1 parent 7479c39 commit 78ce339
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/flow-graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -699,9 +699,6 @@ export default function FlowGraph({ prograph }: { prograph: ProGraph }) {
...props,
onDoubleClick: (conn) => {
prograph.addEdge(conn);
setSuggestedEdges((prev) =>
prev.filter((e) => e.id !== suggestedEdgeId(conn)),
);
},
});
},
Expand Down Expand Up @@ -852,11 +849,11 @@ export default function FlowGraph({ prograph }: { prograph: ProGraph }) {

const parseSuggestionInput = useCallback(
(input: string): [Edge, string] => {
const [handleA, handleB] = input.split("-");
const [handleA, handleB] = input.split(":");
if (!handleA || !handleB)
return [
undefined,
"Input must be of format <number>-<number> (eg. 6-18)",
"Input must be of format <number>:<number> (eg. 6:18)",
];
const idA = Number(handleA);
const idB = Number(handleB);
Expand Down Expand Up @@ -1015,7 +1012,12 @@ export default function FlowGraph({ prograph }: { prograph: ProGraph }) {
onDragOver={onDragOver}
onEdgeUpdate={onEdgeUpdate}
onSelectionChange={(elements) => {
setSelectedElements(elements || []);
const els = elements || [];
const isSuggestedEdge = (el: FlowElement) =>
isEdge(el) && el.type === "suggested";
// Selecting a suggested edge (occurs on click) should not trigger a change to selection
if (els.length && els.every(isSuggestedEdge)) return;
setSelectedElements(els.filter((el) => !isSuggestedEdge(el)));
}}
onNodeContextMenu={(event, node) => {
// @ts-ignore
Expand All @@ -1042,10 +1044,7 @@ export default function FlowGraph({ prograph }: { prograph: ProGraph }) {
onEdgeContextMenu={(event, edge) => {
event.preventDefault();

if (edge.type === "suggested") {
onConnect(edge);
return;
}
if (edge.type === "suggested") return;

const menu = (
<Menu>
Expand Down Expand Up @@ -1227,7 +1226,7 @@ export default function FlowGraph({ prograph }: { prograph: ProGraph }) {
}}
style={{ width: "400px" }}
inputRef={edgeSuggestionInputRef}
placeholder="Type an edge (eg. 4-10)"
placeholder="Type an edge (eg. 4:10)"
onKeyDown={(e) => {
if (e.key === "Enter") {
e.preventDefault();
Expand Down

0 comments on commit 78ce339

Please sign in to comment.