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

Fix pitch slider arrow key interaction #4547

Merged

Conversation

AnvitaPrasad
Copy link
Contributor

Fixes #4466

Description

Fixed the issue where the PitchSlider was overlapping with Blocks when using Up and Down arrow keys. The solution completely disables arrow key interactions when the pitch slider widget is open.

Changes

  • Added an isActive flag to the PitchSlider class to track when the slider is active
  • Added keyboard event listeners in PitchSlider.js to capture and prevent arrow key events
  • Modified __keyPressed method in activity.js to check if the pitch slider is open before processing arrow key events
  • Added user notification that arrow keys are disabled and to use the up/down buttons instead

Screenshot

Screen.Recording.2025-03-17.at.10.45.07.AM.mov

Copy link

✅ All Jest tests passed! This PR is ready to merge.

@Ubayed-Bin-Sufian
Copy link
Contributor

Ubayed-Bin-Sufian commented Mar 17, 2025

@AnvitaPrasad Great effort! As per the expected behavior in the issue description, 'When the PitchSlider widget is initialized, pressing the Up or Down arrow key should move only the slider'.

Currently, the PR disables the slider upon initialization, which differs from the intended design. Let's check with the maintainers on the best approach.

@walterbender @pikurasa, would you be able to review this? Thanks in advance!

@walterbender
Copy link
Member

Yes. We want to disable canvas scrolling with the arrow keys when the widget is open. The question remains, which of the multiple pitch slides is impacted by the arrow keys? Perhaps the last one selected? (or the first one -- left-most -- if none have been selected).

@AnvitaPrasad
Copy link
Contributor Author

Thanks for the feedback @Ubayed-Bin-Sufian and @walterbender

I disabled arrow key interactions entirely to avoid conflicts when multiple sliders exist. This ensures consistency, but I can adjust it if needed. Would you prefer directing input to the last selected slider (or the left-most if none are selected)? Let me know, and I’ll update the PR!

@walterbender
Copy link
Member

I think it would be nice to be able to use the arrows on the last selected slider.

Copy link

✅ All Jest tests passed! This PR is ready to merge.

@AnvitaPrasad
Copy link
Contributor Author

@walterbender I've updated the PR to enable arrow key control for the sliders. The implementation now:

  • Prevents canvas scrolling when arrow keys are pressed while the pitch slider is open
  • Controls the last selected slider with arrow keys (or the leftmost slider if none have been selected)
  • Allows users to click on any slider to make it the active one for arrow key control
Screen.Recording.2025-03-21.at.2.27.07.PM.mov

@walterbender
Copy link
Member

nice.

@walterbender
Copy link
Member

Your PR looks good. Just a few linting issues. Some lines with just spaces. Some extra new lines that are not needed.

Copy link

✅ All Jest tests passed! This PR is ready to merge.

@AnvitaPrasad
Copy link
Contributor Author

Your PR looks good. Just a few linting issues. Some lines with just spaces. Some extra new lines that are not needed.

I believe I have fixed the linting issues now.

js/activity.js Outdated
if (
docById("timbreName") !== null &&
docById("timbreName").classList.contains("hasKeyboard")
) {
return;
}
}

Copy link
Member

Choose a reason for hiding this comment

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

still some spaces on this line

Copy link
Member

Choose a reason for hiding this comment

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

and a few more below. L 3080, 3090, 3098


event.preventDefault();
event.stopPropagation();

Copy link
Member

Choose a reason for hiding this comment

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

maybe this can be double space instead of triple space?

// Move down by a semitone
slider.value = Math.max(currentValue / PitchSlider.SEMITONE, min);
}

Copy link
Member

Choose a reason for hiding this comment

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

same here... no need for so many empty lines between code blocks.

return false;
}
};

Copy link
Member

Choose a reason for hiding this comment

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

And here.

if (id == 0) {
this.activeSlider = id;
}

Copy link
Member

Choose a reason for hiding this comment

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

here and...

this.activeSlider = id;
}


Copy link
Member

Choose a reason for hiding this comment

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

here

slider.addEventListener("mousedown", () => {
this.activeSlider = id;
});

Copy link
Member

Choose a reason for hiding this comment

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

here too

Copy link

✅ All Jest tests passed! This PR is ready to merge.

@AnvitaPrasad
Copy link
Contributor Author

@walterbender Thanks for pointing out the extra blank lines. I think ive removed the unnecessary spaces now. Let me know if anything else needs fixing.

@walterbender walterbender merged commit 0d1fc83 into sugarlabs:master Mar 22, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PitchSlider overlaps with Blocks when using Up and Down arrow keys
3 participants