Skip to content

Commit

Permalink
Allow ctrl+click to tug.
Browse files Browse the repository at this point in the history
  • Loading branch information
pfh committed Aug 20, 2023
1 parent ccefe5d commit cd17874
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion inst/htmlwidgets/lib/langevitour-pack.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inst/htmlwidgets/lib/langevitour-pack.js.map

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions lib/langevitour.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/langevitour.js.map

Large diffs are not rendered by default.

22 changes: 12 additions & 10 deletions src/langevitour.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export class Langevitour extends EventTarget {
mouseX = 0;
mouseY = 0;

rightMouseDown = false; // Used to directly interact with projection.
rightMouseDown = false; // Used to directly interact with projection. Note ctrl+left also triggers this, as right drag is difficult on trackpad.
rightMouseWentDown = false;
tugging = false;
tugX = 0; // Desired position in projection space.
Expand Down Expand Up @@ -359,12 +359,16 @@ export class Langevitour extends EventTarget {
this.rightMouseDown = false;
this.scheduleFrameIfNeeded();
});
plotDiv.addEventListener('mousemove', (e) => {

let handleMouseMove = (e) => {
[ this.mouseX, this.mouseY ] = locateEventInElement(e, this.canvas);
this.mouseDown = e.buttons == 1;
this.rightMouseDown = e.buttons == 2;
// Ctrl+left click and right click are treated the same
this.mouseDown = e.buttons == 1 && !e.ctrlKey;
this.rightMouseDown = e.buttons == 2 || (e.buttons == 1 && e.ctrlKey);
this.scheduleFrameIfNeeded();
});
};
plotDiv.addEventListener('mousemove', handleMouseMove);

plotDiv.addEventListener('mousedown', (e) => {
if (!(e.target as HTMLElement).classList.contains("overlay"))
return;
Expand All @@ -375,9 +379,7 @@ export class Langevitour extends EventTarget {
return;
}

[ this.mouseX, this.mouseY ] = locateEventInElement(e, this.canvas);
this.mouseDown = e.buttons == 1;
this.rightMouseDown = e.buttons == 2;
handleMouseMove(e);

if (this.mouseDown) {
this.mouseWentDown = true;
Expand Down Expand Up @@ -1400,7 +1402,7 @@ export class Langevitour extends EventTarget {
let hint = '';

if (this.tugging) {
hint = "right drag to tug\n";
hint = "drag to tug\n";
} else if (this.mouseInCheckbox && selected.length) {
if (selected[0].active)
hint = "click to hide\n";
Expand All @@ -1412,7 +1414,7 @@ export class Langevitour extends EventTarget {
if (this.selection)
hint = "shift+click to enlarge\n";
else
hint = "left click to select\nright drag to tug\n";
hint = "click to select\nctrl+drag to tug\n";
} else if (this.selection && this.mousing && !brushPoints.length && !this.mouseDown) {
hint = "click to clear\n";
}
Expand Down

0 comments on commit cd17874

Please sign in to comment.