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

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sacredbanana
Copy link
Contributor

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 + /

@wayfu
Copy link

wayfu commented May 18, 2019

whats that on non-US keyboards

@sacredbanana
Copy link
Contributor Author

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

@maeln
Copy link

maeln commented May 19, 2019

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.

@Gargaj
Copy link
Owner

Gargaj commented May 19, 2019

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

@sacredbanana
Copy link
Contributor Author

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
Copy link
Contributor Author

I could add the same shortcuts that visual assist has

@Gargaj
Copy link
Owner

Gargaj commented May 19, 2019

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.

@sacredbanana
Copy link
Contributor Author

sacredbanana commented May 19, 2019

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@sacredbanana sacredbanana force-pushed the line-commenting branch 2 times, most recently from 0e5d5bd to e17a254 Compare May 25, 2019 09:58
@Gargaj
Copy link
Owner

Gargaj commented Jun 1, 2019

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

@sacredbanana
Copy link
Contributor Author

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

@Gargaj
Copy link
Owner

Gargaj commented Jun 2, 2019

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.

@sacredbanana
Copy link
Contributor Author

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

@Gargaj
Copy link
Owner

Gargaj commented Jun 2, 2019

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.

@sacredbanana
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@PoroCYon
Copy link
Contributor

PoroCYon commented Jul 5, 2020

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?)

@sacredbanana
Copy link
Contributor Author

sacredbanana commented Jul 6, 2020

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

@PoroCYon
Copy link
Contributor

PoroCYon commented Jul 6, 2020

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

@sacredbanana
Copy link
Contributor Author

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

@PoroCYon
Copy link
Contributor

PoroCYon commented Jul 7, 2020

Yeah that'd also be ok I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants