Skip to content

Commit 3ac55f7

Browse files
Fixes #4063 and add select button (#4064)
* Fixes #4063 Canvas is scrolling on drag and select * add left-click to scroll and right-click to select * add select button * add select to right-hand menu * change the color of select button * add textMsg * add a period to the end of alert message.
1 parent 5201066 commit 3ac55f7

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

js/activity.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ class Activity {
260260
// Flag to indicate whether the user is performing a 2D drag operation.
261261
this.isDragging = false;
262262

263+
// Flag to indicate whether user is selecting
264+
this.isSelecting = false;
265+
263266
// Flag to indicate the selection mode is on
264267
this.selectionModeOn = false;
265268

@@ -5716,6 +5719,9 @@ class Activity {
57165719

57175720
if (!this.helpfulWheelItems.find(ele => ele.label === "Grid"))
57185721
this.helpfulWheelItems.push({label: "Grid", icon: "imgsrc:data:image/svg+xml;base64," + window.btoa(base64Encode(CARTESIANBUTTON)), display: true, fn: piemenuGrid});
5722+
5723+
if (!this.helpfulWheelItems.find(ele => ele.label === "Select"))
5724+
this.helpfulWheelItems.push({label: "Select", icon: "imgsrc:data:image/svg+xml;base64," + window.btoa(base64Encode(SELECTBUTTON)), display: true, fn: this.selectMode });
57195725

57205726
if (!this.helpfulWheelItems.find(ele => ele.label === "Clean"))
57215727
this.helpfulWheelItems.push({label: "Clean", icon: "imgsrc:data:image/svg+xml;base64," + window.btoa(base64Encode(CLEARBUTTON)), display: true, fn: () => this._allClear(false)});
@@ -6062,6 +6068,8 @@ class Activity {
60626068
document.addEventListener(
60636069
"mousedown",
60646070
(event) => {
6071+
if (!this.isSelecting) return;
6072+
this.moving = false;
60656073
// event.preventDefault();
60666074
// event.stopPropagation();
60676075
if (event.target.id === "myCanvas") {
@@ -6082,6 +6090,12 @@ class Activity {
60826090
// end the drag on navbar
60836091
document.getElementById("toolbars").addEventListener("mouseover", () => {this.isDragging = false;});
60846092

6093+
this.selectMode = () => {
6094+
this.moving = false;
6095+
this.isSelecting = !this.isSelecting;
6096+
(this.isSelecting) ? this.textMsg(_("Select is enabled.")) : this.textMsg(_("Select is disabled."));
6097+
}
6098+
60856099
this._create2Ddrag = () => {
60866100
this.dragArea = {};
60876101
this.selectedBlocks = [];
@@ -6099,7 +6113,7 @@ class Activity {
60996113
this.hasMouseMoved = true;
61006114
// event.preventDefault();
61016115
// this.selectedBlocks = [];
6102-
if (this.isDragging){
6116+
if (this.isDragging && this.isSelecting){
61036117
this.currentX = event.clientX;
61046118
this.currentY = event.clientY;
61056119
if (!this.blocks.isBlockMoving && !this.turtles.running()) {
@@ -6114,6 +6128,7 @@ class Activity {
61146128

61156129
document.addEventListener("mouseup", (event) => {
61166130
// event.preventDefault();
6131+
if (!this.isSelecting) return;
61176132
this.isDragging = false;
61186133
this.selectionArea.style.display = "none";
61196134
this.startX = 0;

js/artwork.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)