Closed lsei closed 4 years ago
@lsei thanks for the PR, but I'm pretty sure this is already addressed if you're referring to jumping to the line start and end? I had previously disabled those ace functions because of shortcut conflicts in the code here - but after a previous issue about exactly this, re-implemented them within the custom shortcuts here. At the moment it's CTRL + SHIFT + ←/→
, however that's kind of an annoying combo to press.. I avoided using CMD (on macos) to be fair to windows users.. even though I previously killed their copy function... and couldn't use just CTRL + arrows
since that's used by MacOS... anyways, since two releases ago, you can customize shortcuts in your settings panel, including these.. so feel free to set it to CMD + ←/→
or the Home
/End
keys as you wish. Just tested setting it to those and it worked fine. For start and end of entire script, Page Up
and Page Down
work, or on MacOS, CMD + ↑/↓
works.
Regarding those shortcuts... Realized it's in a funny order, having goToLineEnd
before the start... in small upcoming update, will be listing the `goToLineStart' first.
Thanks for the explanation. Completely forgot about the control / command shuffle between Windows and Mac. I wonder which key event.metaKey
maps to on Windows. Unfortunately I don't have access to a Windows computer to test.
It's great that these can be added using shortcuts. Personally I think the code editor should work exactly the same as any other text editor (whether it's VSCode, Google Docs or just a plain old textarea
) for the given OS so that there is no need for the user to setup or re-learn shortcuts only for p5live and can rely on muscle memory. I found that I use the Home
and End
keys and CMD + LeftArrow/RightArrow
automatically because it's the default interaction pattern for most input fields I use.
Which conflicts were being caused by the gotoLineStart
and gotoLineEnd
function in ace?
If you prefer to stick with the shortcuts I'm happy to leave it at that, otherwise I'd be happy to do a bit more research into making this work cross platform.
Seems the event.metaKey
is usually the windows key, but Firefox dropped it. I'm not on Windows either, so I just had students let me know when I killed their keys. Totally agree about trying to preserve as many of the key bindings as possible that one is used to from Sublime/VSCode/ace-editor... it was more of an issue when I first started P5LIVE and wanted to reserve certain keys for obvious shortcuts... CTRL + E
for toggling editor... CTRL + A
for toggling 'autocompile' (live-coding)... those two keys are exactly what caused me to disable the goToLineStart/End
. Here's the default ace-editor key bindings. You'll see in the marked code lines above (and that key binding page) that a handful of bindings has the obvous key Right Arrow
but also an extra, CTRL + F
... so i disabled it and re-enabled it without that extra binding (since one can't just remove a letter.. but had to re-declare it...). Now understanding more about how these work since starting the project.. I can simply re-introduce the goToLineStart/End
for both Windows + Mac using the Alt-Left
+ Cmd-Left
+ Home
(just removing the Ctrl-A
).
I think it's worth replacing (re-initializing) as many of those keyBindings that use keys otherwise used by P5LIVE core functionality... probably easiest for me to do since I know which ones are necessary.. but feel free to help having a look at the shortcuts list of keys that can be modified and that keybinding chart.. and the code where I re-introduce them. Save to say that this PR should be closed or at the least totally replaced by this method... Tricky is respecting Windows keyboard behaviors when not having one.. but should be mostly obvious for anything involving the CTRL key.
Decided I should go through this and clean it up myself.. I had also disabled a few keys (moveLineUp/Down) that didn't need to be and are really useful. Closing this – will apply the edits once ready and happy for PR of additional mods that are needed afterwards.
Fixed these in latest PR #45 – let me know if that clears up the issues you had with moving the cursor around. Should work as expected. Thanks again for bringing this up and the PR - though best in this case to stick with the ace-editor built in methods (especially now understanding them better...).
Cheers Ted. Glad the issue is solved even if in a different way. That's the process we need to go through when making software right? Definitely better to stick to the ace built in methods which already have a lot of cross-browser thought that has gone into them.
Keybindings are working for me now. 👍
I noticed that navigating to the beginning or end of the line did not seem to work. At least for me on OS X, Chrome.
The sample editor on the Ace website seems to handle this correctly so I'm assuming it's a case of keyup/down events not being propagated down to the editor or being gobbled up somewhere.
Added this small function in to handle it explicitly. Happy to get guidance from you if you think there's a better way to implement this with your code structure.