-
Notifications
You must be signed in to change notification settings - Fork 364
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
Disable editor shortcuts #6804
Comments
I don't know if maybe clicking on the stage (to focus it) first could prevent this from happening? Edit: it does not! I've also experienced this problem the other way around - shifting something in the costume editor doing something in the project. Wonder what we could do about that… Off-topic: Sometimes I use Backspace or Delete to delete blocks, but I did not know that x does too! (Apparently, it's actually Alt+x.) |
Ugh, and we thought Alt+X for pausing was a unique combination... |
Can anyone link to the relevant scratch-gui files that add the event listeners to the page? I believe we're looking for different event listeners for the code area and for the costume editor. Does the sound editor have keyboard shortcuts? |
Here is where it picks up Alt+X: Here's the call stack when deleting a block with the Delete key (from Scratch Desktop 3.27.0): |
Oh, I can explain this. When a key is pressed, one of the things Scratch checks for is if you're holding down Alt, Ctrl, or Command, then if you are, it checks if you're pressing C, X, or V. C copies, X cuts (copies and deletes), and V pastes. So what we're actually doing is cutting the block. Typically, this is done with Ctrl+X but Alt+X also works because that was in the if condition for some reason. Here's where that happens:
Blockly.onKeyDown_ = function(e) {
// ...
var deleteBlock = false;
if (e.keyCode == 27) {
// ...
} else if (e.altKey || e.ctrlKey || e.metaKey) {
// ...
if (Blockly.selected && Blockly.selected.isDeletable() && Blockly.selected.isMovable()) {
if (e.keyCode == 67) {
// 'c' for copy.
Blockly.hideChaff();
Blockly.copy_(Blockly.selected);
} else if (e.keyCode == 88 && !Blockly.selected.workspace.isFlyout) {
// 'x' for cut, but not in a flyout.
// Don't even copy the selected item in the flyout.
Blockly.copy_(Blockly.selected);
deleteBlock = true;
}
}
if (e.keyCode == 86) {
// 'v' for paste.
// ...
} else if (e.keyCode == 90) {
// 'z' for undo 'Z' is for redo.
Blockly.hideChaff();
Blockly.mainWorkspace.undo(e.shiftKey);
}
}
// Common code for delete and cut.
// Don't delete in the flyout.
if (deleteBlock && !Blockly.selected.workspace.isFlyout) {
Blockly.Events.setGroup(true);
Blockly.hideChaff();
Blockly.selected.dispose(/* heal */ true, true);
Blockly.Events.setGroup(false);
}
}; |
Wait... I thought you could only copy/cut/paste with DevTools? |
Yeah, Scratch has built-in copy, cut, delete, and paste functionality for the code area. You just need to focus the block you want to copy/cut/delete by clicking it (you can right-click or drag to avoid executing it) and then do the appropriate keyboard shortcut. |
I think the devtools addon just presses the shortcut on your behalf. |
I've been overestimating its power for years...
|
From what I've found, it looks like the code area is the only place where Alt+X does anything. Everywhere else I've seen, either it's Ctrl+X or cutting isn't available, so to resolve the problem of pausing the project cutting a block, that should do it, without the need for a new addon. The only other notable problem I can think of is how arrow keys shift objects in costumes. Not sure if that can be fixed without a new addon. Anything else to consider? |
I'm not an expert on trapping Scratch internals, but would trapping Blockly let us deactivate this feature? |
Related feedback, I believe it's a Scratch bug.
|
I think that might be intentional, as some users might not notice they need to click the stage... We should probably try to find a way to make this somewhat intuitive, plus making sure SA users enabling this new addon read the addon description, and it would also have the side-effect of making griffpatch's idea possible to implement. |
So, the Blockly export default async function ({ addon, console }) {
const Blockly = await addon.tab.traps.getBlockly();
console.log(Blockly.onKeyDown_);
} But I haven't figured out how to deactivate it yet. |
Multiple addons do this, basically you replace it with another function that only calls the original function if |
What if you could individually toggle keyboard shortcuts? For example, I could have backspace to delete enabled but turn off all of the Ctrl-key shortcuts which I never use in the Scratch code editor. |
+1 from feedback |
I created issue #7225 |
Here, |
Why this would be helpful
It's extremely frustrating when you press a key in a project and that key affects the editor.
For example, you surely experienced that when you have a selected object in the paint editor and press the arrow keys in the project, the object suddenly shifts around? Yes, that's because every part of the editor reacts to any key press.
Another very well-known thing is when the last block you interacted with gets deleted by pressing Alt+X to pause the project in the editor, as "X" is recognized as binding for deleting.
How this addon works
This addon disables key interactions for areas that are not hovered, as Unity does.
Possible alternatives
To address the Alt+X issue and similar things, we could also consider disabling those on-key bindings for the codespace. I don't know anybody who uses them, and they are annoying as you first need to execute the block by clicking on it.
Additional context
I was working on a game when I noticed a big bug that never occurred before. I looked for half an hour for a patch when I suddenly realized that an if-else block with a lot of nested code had mysteriously disappeared. I had to rebuild it from scratch, and that wasn't fun.
Please don't comment "I use those keybinds!" or stuff like that. Thanks.
The text was updated successfully, but these errors were encountered: