Bonzomatic icon indicating copy to clipboard operation
Bonzomatic copied to clipboard

Ctrl + Slash will now comment and uncomment your selected lines of code

Open sacredbanana opened this issue 5 years ago • 22 comments

This was one of the things that Bonzomatic lacked which most IDE's have.

You can comment or uncomment your current line of code or all lines you have selected with Ctrl/Cmd + /

sacredbanana avatar May 18 '19 14:05 sacredbanana

whats that on non-US keyboards

wayfu avatar May 18 '19 21:05 wayfu

whats that on non-US keyboards

I haven't tested it but it should work for any keyboard layout. Wherever your "/" is on your keyboard it should work. GLFW abstracts away keys and scan codes and knows how to map keys across different layouts. If it doesn't work though then let me know

sacredbanana avatar May 18 '19 22:05 sacredbanana

Doesn't seem to work on my Mac Fench AZERTY layout. I tried (note: the / is on the : key, and to do a / you need to do MAJ+:) :

  • CTRL + MAJ + : (= /)
  • CTRL + :
  • CMD + MAJ + :
  • CMD + :

All of which to no avail.

EDIT: Ok, I found, it work with the "+" key next to the maj key. So CTRL+"+" or CTRL+MAJ+"+" works.

Looking at the code, it seem to be a GLFW issue, so I don't know if there is a possible fix in Bonzo. I will try to test directly GLFW, but it's not the first time I ran into issues like this with this layout.

maeln avatar May 19 '19 09:05 maeln

Just FYI, Visual Assist adds/removes single-line comments on / and multiline comments on *.

Gargaj avatar May 19 '19 10:05 Gargaj

I chose Ctrl/Cmd + / because that's what I am used to from Xcode and Visual Studio Code. We can add a different keyboard shortcut that works universally across keyboard layouts, but I'd like to keep Ctrl + / in there. Or maybe someone can figure out why Ctrl + / isn't working universally like I thought it would.

Just FYI, Visual Assist adds/removes single-line comments on / and multiline comments on *.

Nice. I haven't tried Visual Assist. Reading about it now. Sounds great.

sacredbanana avatar May 19 '19 10:05 sacredbanana

I could add the same shortcuts that visual assist has

sacredbanana avatar May 19 '19 10:05 sacredbanana

To be honest I'm not sure about this, it's something I'd personally enjoy but it sounds too specific to be useful across the board in competitions and the fact that it's geared towards a smaller group of people makes it slide into the "add neovim" territory.

Gargaj avatar May 19 '19 10:05 Gargaj

In my opinion this feature is good because it's a standard feature in any good code editor. It's not geared towards a limited group of people. Contestants of shader coding competitions would all be exposed to IDEs with this same feature (and I'd bet most of them have used this feature). In competitions, the ability to very speedily comment and uncomment out blocks of code is useful when you're experimenting trying to create the best code for good effects by turning things on and off and seeing what looks good.

We could get an additional key mapping for the feature by having Ctrl + K for example rather than a symbol or even use one of the function keys

sacredbanana avatar May 19 '19 13:05 sacredbanana

Also I doubt anyone would dislike this feature so it’s definitely worth considering. I mainly added it because it’s the one thing that the code editor was lacking

sacredbanana avatar May 19 '19 16:05 sacredbanana

I just added Ctrl/Cmd K to comment out code too. This should work for everyone :)

sacredbanana avatar May 25 '19 09:05 sacredbanana

I feel if we add this, we'd be better off supporting // and /**/ just like VS does.

Gargaj avatar Jun 01 '19 13:06 Gargaj

So in other words, /**/ when multiple lines are selected and // for a single line?

Or separate key combos for /**/ and // (where // will be inserted at the beginning of every line selected)?

I'm happy to implement the feature to how you'd like it, but I'd like to know exactly what your expected behaviour of this feature is.

Thanks

sacredbanana avatar Jun 02 '19 11:06 sacredbanana

The way it works in VS/VAX is that:

  • They are triggered by a single / or * stroke (no Ctrl)
  • They only act when there's a selection, not on single cursor
  • / triggers the entire line to be commented or uncommented, * triggers a block comment or uncomment

I suggest you try it before you write more code.

Gargaj avatar Jun 02 '19 11:06 Gargaj

OK no problem. Can we have this as an addition to the current commenting behaviour? Just so that it caters for people used to other IDEs

sacredbanana avatar Jun 02 '19 12:06 sacredbanana

Catering to too many things is a slippery slope - this is not a general purpose editor, it's a tool for a very specific live coding compo. This is already pushing it.

Gargaj avatar Jun 02 '19 13:06 Gargaj

I have added the behaviour as described. Now since the '/' button doesn't seem to work for non US keyboard layouts, I have not removed the old functionality yet. I can remove the old functionality if you want, but I'd like to know how to solve the '/' issue. For now, with the old functionality, I have also added support to use 'K' instead of '/' so you can use Ctrl + K to comment lines of code.

Please have a play around with it to see if you like it and provide feedback if you'd like anything changed. :)

sacredbanana avatar Jun 08 '19 12:06 sacredbanana

Hi, it's been a while since this was last commented on. I was just using the release build of Bonzomatic and tried to mass comment out my selected text and remembered my feature hadn't been merged yet. I was wondering if we could get this useful feature merged or if it needs work let me know what I should change. Thanks

sacredbanana avatar Jul 05 '20 04:07 sacredbanana

Seems to work, except I have the same issue maeln had: I need to press Ctrl+= or Ctrl+Shift+! (== Ctrl+8) instead of resp. Ctrl+Shift+: (== Ctrl+/) and Ctrl+Shift+$ (== Ctrl+*). This is Belgian AZERTY. Not exactly intuitive when you have no QWERTY keyboards. Is there any way to fix this? (eg. using SDL has a charcodes<->keycodes distinction, do GLFW etc. have something like that?)

PoroCYon avatar Jul 05 '20 16:07 PoroCYon

If you look at my changes to main.cpp and renderer.cpp, you see the key handling code there. If someone knows of a better way of doing that than my implementation then that would be awesome

sacredbanana avatar Jul 06 '20 02:07 sacredbanana

Tried fixing it unsuccessfully, but, apparently it's a known bug in GLFW. sigh.

PoroCYon avatar Jul 06 '20 15:07 PoroCYon

This sucks. Maybe we could somehow have customisable key commands in the config.json

sacredbanana avatar Jul 07 '20 01:07 sacredbanana

Yeah that'd also be ok I guess.

PoroCYon avatar Jul 07 '20 22:07 PoroCYon