Keyboard shortcuts in Windows and Linux
Closed this issue · 8 comments
Hi, me again!
I may be missing something very obvious, but I have been struggling to get a hang of keyboard shortcuts in P5LIVE.
In particular, I have been unable to get the following keyboard shortcuts (which I expect to be universal) to work:
- Copy (
Ctrl + C
) - Jump to line start (
Home
) - Jump to line end (
End
)
I have tested these on my own local hosted P5LIVE setup and http://p5live.org, on both Chrome and Firefox, as well as in both Linux and Windows environments.
In all environments tested so far, the 3 commands above do nothing. But strangely, their close relatives are working fine for me:
- Paste (
Ctrl + V
) works! - Selection to line start (
Shift + Home
) works! - Selection to line end (
Shift + End
) works!
Perhaps you're on Windows? Yeeeah.. I totally botched some basics on Windows.. CTRL + C
, is used to show/hide the cursor when the editor is hidden... thus it breaks a really crucial default copy function... (Q: are you allowed to copy+paste while live coding?! jk). I also use CTRL + T
for tidying the code.. but I think on Windows that opens a new Tab instead. I shooould use a VM for testing... I suppose the really nice thing to do, would be make the shortcuts editable and stored in the settings. Not sure how easy that would be to interpret in my keydown listener code. But I was also interested in letting Mac users switch to using 'CMD' though surely same issue, of ones that aren't allowed due to system/browser. I use CTRL + SHIFT + _
for adding snippets like audio and OSC... so I'd prefer to avoid that extra modifier.
Suggestions?
Wow, just found the mousetrap library = crazy cool.
hotkeys.js is equally nice.
I'll look into allowing shortcut customization, while leaving suggested defaults.
Wow those are indeed really cool libraries!
Hmmm as a heavy shortcut user on Linux and Windows, I would much prefer having my favorite shortcuts built in by default, and I think it would make the first impression for new users much smoother as well.
How about having separate Edit and Command modes, where different sets of shortcuts live? This is a tried and true approach of some other editors, like Vim (try Vim) and Jupyter Notebooks (try Jupyter).
So for example:
- At any point in time, the user can be in either Edit Mode or Command Mode.
- Enter Edit Mode either by pressing
Enter
or by clicking inside the editor box. - Enter Command Mode by pressing
Esc
or by clicking on the side panel / a small "Exit Edit Mode" button which appears while in Edit Mode. - While in Edit Mode, all the usual text editing shortcuts work as expected, there are no other shortcuts (except maybe
Ctrl+Enter
andCtrl+Shift+Enter
for soft/hard compile). - While in Command Mode, you can then pick any keybindings for all of the P5LIVE-specific commands, including snippets and sketch loading, etc.
Since there are two modes, you will have many more keybinding options available to you, and this way instead of using Ctrl+T
to Tidy, you can change it so that users go in command mode and use T
alone. This will be great so users don't have to change their usual shortcut habits.
The only downside I can think of from this is that it would break Vim compatibility in the Ace editor, which I had enabled previously because it was the only way I could get usable shortcuts... 😆 But that's probably a feature P5LIVE live without; having good keybindings for general users is much more important!
Many thanks for working out tthese various ideas. Gotta say, the Edit vs Command Mode doesn't sound so user friendly, unless one comes from a VIM background – which I myself don't, nor any of my students who have usually never touched code, let alone CLI. That openvim link was great and I see the speed advantages when one is used to it, but I want to keep it more accessible. Not to mention on a Mac.. at least for now with this dumb touchbar.. my ESC key is super volatile 🤪😭.
However, you bring up a great point – I kind of see the edit/command mode as being when one toggles the editor as being visible or hidden, so there's no reason shortcuts like CTRL + C
(toggle cursor when editor is hidden) should do anything while the editor is visible. Of course CTRL + T
tidying code is something for only while the editor is visible (since it's locked when hidden).. so that just might need a personal remapping from the user on a windows machine. To be honest, it is Mac biased, as I'm developing on (and 99% of my students) are on mac laptops = no home/end keys to even know I'm missing that start/end of line shortcut. Soooo maybe a shortcuts pref panel, which lets one remap would be a decent compromise. The request for allowing VIM already came up – but is def a special case and would kill all the other keybindings = with such a pref pan... could potentially work around them.
Please can you just change CTRL+C to CTRL+K or something (anything!) else. Also CTRL+A is a universal one.
The user defined custom keyboard shortcuts is glitchy and very hard to use on Windows.
I'd like to introduce this amazing environment to many people in workshops but this messy setting up business is putting me off.
Thanks
@geneticmoo – sure I'll look into changing these in the next release. Ran into this issue in the past two workshops, where indeed it breaks a few keys for PC/Linux users– though it was a quick fix by setting custom shortcut keys- shouldn't be necessary to do so (maybe need to analyse browser/OS and adjust metakeys). Did you try setting custom shortcuts within the settings panel? Curious what issues you run into when trying to manually set shortcut keys.. hopefully you can just click and create new ones, ie adding SHIFT.