Skip to content
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

can now use shit plus ctrl to drag to deselect multiple nodes from se… #688

Merged
merged 1 commit into from
May 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions src/GraphRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,7 @@ export class GraphRenderer {

static mouseMove(eagle: Eagle, event: JQuery.TriggeredEvent) : void {
const e: MouseEvent = event.originalEvent as MouseEvent;
GraphRenderer.ctrlDrag = event.ctrlKey;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider renaming 'ctrlDrag' for clarity.

The variable name 'ctrlDrag' might be misleading as it suggests dragging with the control key. Consider renaming it to something more descriptive like 'isCtrlPressed' to better reflect its purpose.

Suggested change
GraphRenderer.ctrlDrag = event.ctrlKey;
GraphRenderer.isCtrlPressed = event.ctrlKey;


GraphRenderer.dragCurrentPosition = {x:e.pageX,y:e.pageY}
if (eagle.isDragging()){
Expand All @@ -1101,7 +1102,6 @@ export class GraphRenderer {
const node:Node = eagle.draggingNode()
$('.node.transition').removeClass('transition') //this is for the bubble jump effect which we dont want here

GraphRenderer.ctrlDrag = event.ctrlKey;

// move node
eagle.selectedObjects().forEach(function(obj){
Expand Down Expand Up @@ -1186,13 +1186,10 @@ export class GraphRenderer {

static endDrag(node: Node) : void {
const eagle = Eagle.getInstance();

GraphRenderer.ctrlDrag = false;

// if we dragged a selection region
if (GraphRenderer.isDraggingSelectionRegion){
const nodes: Node[] = GraphRenderer.findNodesInRegion(GraphRenderer.selectionRegionStart.x, GraphRenderer.selectionRegionEnd.x, GraphRenderer.selectionRegionStart.y, GraphRenderer.selectionRegionEnd.y);

//checking if there was no drag distance, if so we are clicking a single object and we will toggle its selection
if(Math.abs(GraphRenderer.selectionRegionStart.x-GraphRenderer.selectionRegionEnd.x)+Math.abs(GraphRenderer.selectionRegionStart.y - GraphRenderer.selectionRegionEnd.y)<3){
if(GraphRenderer.altSelect){
Expand All @@ -1203,22 +1200,36 @@ export class GraphRenderer {
const edges: Edge[] = GraphRenderer.findEdgesContainedByNodes(eagle.logicalGraph().getEdges(), nodes);
const objects: (Node | Edge)[] = [];

// only add those objects which are not already selected
for (const node of nodes){
if (!eagle.objectIsSelected(node)){
objects.push(node);
// depending on if its shift+ctrl or just shift we are either only adding or only removing nodes
if(!GraphRenderer.ctrlDrag){
for (const node of nodes){
if (!eagle.objectIsSelected(node)){
objects.push(node);
}
}
}
for (const edge of edges){
if (!eagle.objectIsSelected(edge)){
objects.push(edge);
for (const edge of edges){
if (!eagle.objectIsSelected(edge)){
objects.push(edge);
}
}
}else{
for (const node of nodes){
if (eagle.objectIsSelected(node)){
objects.push(node);
}
}
for (const edge of edges){
if (eagle.objectIsSelected(edge)){
objects.push(edge);
}
}
}

objects.forEach(function(element){
eagle.editSelection(Eagle.RightWindowMode.Hierarchy, element, Eagle.FileType.Graph )
})
}
GraphRenderer.ctrlDrag = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Reset 'ctrlDrag' earlier in the method.

Consider resetting 'ctrlDrag' earlier in the method to ensure it is always reset, even if an exception occurs later in the method.

Suggested change
GraphRenderer.ctrlDrag = false;
GraphRenderer.ctrlDrag = false;
try {
eagle.editSelection(Eagle.RightWindowMode.Hierarchy, element, Eagle.FileType.Graph)
} catch (error) {
// Handle error if necessary
}
GraphRenderer.selectionRegionStart.x = 0;


GraphRenderer.selectionRegionStart.x = 0;
GraphRenderer.selectionRegionStart.y = 0;
Expand Down