-
Notifications
You must be signed in to change notification settings - Fork 17
Fix: Support Multi-selection in ctrl
way
#125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ export function useNodesStateSynced(nodeList) { | |
const getPod = useStore(store, (state) => state.getPod); | ||
const deletePod = useStore(store, (state) => state.deletePod); | ||
const updatePod = useStore(store, (state) => state.updatePod); | ||
const setSelected = useStore(store, (state) => state.setSelected); | ||
const setPodSelected = useStore(store, (state) => state.setPodSelected); | ||
const role = useStore(store, (state) => state.role); | ||
const ydoc = useStore(store, (state) => state.ydoc); | ||
const nodesMap = ydoc.getMap<Node>("pods"); | ||
|
@@ -35,17 +35,17 @@ export function useNodesStateSynced(nodeList) { | |
} | ||
|
||
changes.forEach((change) => { | ||
if (!isNodeAddChange(change) && !isNodeResetChange(change)) { | ||
if (!isNodeAddChange(change)) { | ||
if (isNodeRemoveChange(change)) { | ||
nodesMap.delete(change.id); | ||
return; | ||
} | ||
const node = nextNodes.find((n) => n.id === change.id); | ||
|
||
if (!node) return; | ||
|
||
if (change.type === "select" && change.selected) { | ||
// FIXME: consider the case where only unselect is called | ||
setSelected(node.id); | ||
if (isNodeResetChange(change) || change.type === "select") { | ||
setPodSelected(node.id, change.selected as boolean); | ||
return; | ||
} | ||
|
||
|
@@ -98,10 +98,11 @@ export function useNodesStateSynced(nodeList) { | |
|
||
// TOFIX: a node may be shadowed behind its parent, due to the order to render reactflow node, to fix this, comment out the following sorted method, which brings in a large overhead. | ||
setNodes( | ||
Array.from(nodesMap.values()).sort( | ||
(a: Node & { level }, b: Node & { level }) => a.level - b.level | ||
) | ||
Array.from(nodesMap.values()) | ||
.sort((a: Node & { level }, b: Node & { level }) => a.level - b.level) | ||
.map((node) => ({ ...node, selected: getPod(node.id)?.selected })) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the only way to un-sync the Managing the field in Zustand state sounds a bit over-complicated to me. And it looks like we have to implement the de-select logic when we do this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only ground truth source is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I got what you meant. I realized its cons just now: new selection change will not be applied if no update in the remote I have an idea about the possible solution: stop writing |
||
); | ||
|
||
// setNodes(Array.from(nodesMap.values())); | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not work on Mac, because
control
triggers right-click context menu. The default"Meta"
works better (which is the command key).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose to disable option 1 and use "shift" for option 2, i.e.,
Ref: #112 (comment)