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

Editor: Added a new panel for editing key bindings #12612

Merged
merged 8 commits into from
Dec 5, 2017

Conversation

TyLindberg
Copy link
Contributor

By adding this panel, users now have the ability to edit key bindings for the translate, rotate, scale, and undo buttons. This could be useful for those with different keyboard configurations and also allows more key bindings to be easily added without cluttering index.html. Currently, I called the panel 'CONTROLS' and didn't allow for the binding of modifier keys such as Command/Control.

Here is an image of what the panel looks like:
screenshot-2017-11-9 three js editor

There are a bunch of changes that can be made with this, so definitely let me know your thoughts. Hopefully we can leverage this to add more commands to the editor in the future.

Tyler Lindberg added 7 commits November 9, 2017 01:31
All input handling is now in Sidebar.Controls. In addition,
changed from using event.keyCode to event.key. This may cause
browser compatibility issues, but is more maintainable and
easier to read.
This prevents the user from unknowingly having keyboard focus
on an input field after changing a key binding.
When changing key bindings, will now check that the key entered is
valid. If not, then revert back to the key stored in config.
@mrdoob
Copy link
Owner

mrdoob commented Nov 9, 2017

Looking good!

'settings/history': false
'settings/history': false,

'controls/translate': 'w',
Copy link
Owner

Choose a reason for hiding this comment

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

Do you mind renaming these to settings/controls/translate...?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!


break;

case editor.config.getKey( 'controls/undo' ).toLowerCase(): // Register Ctrl/Command-Z for Undo and Ctrl/Command-Shift-Z for Redo
Copy link
Owner

Choose a reason for hiding this comment

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

I bet having caps locked messes with this...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh good call, I haven't tested how caps lock affects the controls. There is currently weird behavior where pressing CTRL+SHIFT+Z results in the key being 'Z' on Chrome and 'z' on Safari and Firefox hence why I'm checking for both upper and lower case for undo/redo. I'll test out caps lock and let you know what behavior I see.

@TyLindberg
Copy link
Contributor Author

So with the current implementation, having caps lock pressed will result in the translate/rotate/scale controls not being registered. This is because those controls are case sensitive. Undo/redo is not case sensitive, so it is unaffected by having caps lock pressed, and in addition, you still need to hold shift for a redo to be triggered instead of undo.

This is mostly a design decision whether we want to keep it like this or not. By allowing things like translate/rotate/scale to be case sensitive, it lets users bind those commands to SHIFT+ without much extra work. However, we could make bindings case insensitive if we felt that was more intuitive or a more consistent experience.

@mrdoob
Copy link
Owner

mrdoob commented Dec 5, 2017

Hmm, okay. I'll merge and experiment with this.

@mrdoob mrdoob merged commit 05c5288 into mrdoob:dev Dec 5, 2017
@mrdoob
Copy link
Owner

mrdoob commented Dec 5, 2017

Thanks!

@mrdoob
Copy link
Owner

mrdoob commented Dec 5, 2017

Ended up making it case-insensitive (forced to lowercase).

9dbe8d0

@mrdoob
Copy link
Owner

mrdoob commented Dec 5, 2017

Also, this makes it work in Safari.

d35ce01

@TyLindberg
Copy link
Contributor Author

Ah, perfect! I'm glad you were able to find a way to make that consistent between browsers.

And forcing to lowercase seems pretty smart to me. In the future it may make sense to add the ability to bind certain modifier keys such as shift or alt. However, keeping everything lowercase for now seems like it will cause the least issues.

Thanks for merging that in!

@mrdoob
Copy link
Owner

mrdoob commented Dec 5, 2017

🙌

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.

2 participants