Page MenuHome

Text Editor Missing Hotkey Fix: Comment assigned Ctrl+H, Uncomment assigned Alt+H, Replace Ctrl+R, Find Set Selected Alt + F
AbandonedPublic

Authored by Peter Fog (tintwotin) on Jul 3 2019, 5:53 PM.

Details

Summary

Comment assigned Ctrl+H, since no hotkey was assigned and it mirrors Hide functions(but H doesn't work in a text editor as a hotkey). A common shortcut for this is Ctrl + / but this doesn't work on non English keyboards(Ctrl + Shift + 7(=Ctrl + /) doesn't work in Blender)

Uncomment assigned Alt+H, since it mirrors Show Hidden Objects/Unhide.

Replace assigned Ctrl+R, since Ctrl + H was previously assigned to Replace, and Ctrl + R is standard in ex. pycharm for replace.

Find Set Selected Alt + F, since no hotkey was assigned and this is a useful function with a hotkey.

As far as I can see, will these changes not cause any changes in the current Text Editor manual: https://docs.blender.org/manual/en/dev/editors/text_editor.html

Diff Detail

Event Timeline

Peter Fog (tintwotin) edited the summary of this revision. (Show Details)Jul 3 2019, 6:58 PM
Peter Fog (tintwotin) edited the summary of this revision. (Show Details)Jul 4 2019, 10:10 PM
William Reynish (billreynish) requested changes to this revision.

In my opinion we should probably just use the industry standard hotkeys for comment/uncomment. We do this for other basics like copy/paste.

Although I can see the rationale for using Ctrl-H/Alt-H too.

This revision now requires changes to proceed.Jul 29 2019, 4:11 PM

In my opinion we should probably just use the industry standard hotkeys for comment/uncomment. We do this for other basics like copy/paste.

+1 for using Ctrl-/ to toggle comments. It makes sense to go from one text editor to another and automatically know they hotkeys.

Using Ctrl-H/Alt-H does not make sense because the content is not being "hidden" hence the H key.

Sure I can change it to Ctrl + /, but as mentioned, that keyboard combination does not work on non-English keyboards:

A common shortcut for this is Ctrl + / but this doesn't work on non English keyboards(Ctrl + Shift + 7(=Ctrl + /) doesn't work in Blender)

T66607 is another example of shortcut keys not working on non-English keyboards. Unless the plan is to start adding localized shortcut keymaps, I think we should be careful not to utilize keys which do not work on non-English keyboards.

What do other applications which use Ctrl-/ do for non-English environments

Ctrl + / is actually line comment(in PyCharm), where the location of the cursor determines which line to comment and this is typically a toggle function - this line comment function doesn't exist in Blender.

In Blender you'll have to select what you want to comment - what typically is referred to as 'Block comment' which in PyCharm is Ctrl + Shift + / and in VSCode is Shift + Alt + A and notepad++ Ctrl + Shift + Q

VScode:

PyCharm:

Notepad++:

So actually, there doesn't seem to be any consensus or industry-standart when it comes to a shortcut key for commenting.

Maybe, if we should go with the PyCharm Ctrl + Shift + / for 'block comment' maybe Ctrl + Shift + 7((ctrl+7=/) which is what you end up pressing(on a danish keyboard)), should also be assigned. Question then is what should the combination be to uncomment, Ctrl+Alt+7?(Which doesn't align with any of the mentioned softwares(two of them toggles commenting and one doesn't even have a shortcut for that)).

I don't know what to conclude other that maybe if we should go for industry standarts in shortcuts, maybe we also should go for industry standart functionality(in this case add line comment and make both line and block comment toggle functions). Maybe a target for 2.81 could be to align the current text editing functions in the Text Editor with the mostly used text editors out there? Ex. the Blender Find & Replace and Go to/Jump etc. are working in ways which are pretty far from industry standards?

I checked over a dozen or so text/code editors. Almost all used Cmd or Ctrl-/ for *toggle* comments.

However, our operator currently doesn't toggle, it's separate for comment and uncomment.

If Ctrl + / is it, which is industry standart for Line Comment(?), then this is all it takes(in Python) to add Line Comment to the current comment function. Code by Lapineige:

class BetterComment(bpy.types.Operator):
    """  """
    bl_idname = "text.better_comment"
    bl_label = "Better Comment"

    def execute(self, context):
        base = context.space_data.text.current_line.body
        bpy.ops.text.comment()
        if context.space_data.text.current_line.body == base:
            context.space_data.text.current_line.body = '#' + context.space_data.text.current_line.body
        return {'FINISHED'}

Code ported to 2.80 here(it also contains improved uncomment and indentation): https://gist.github.com/tin2tin/b4be91df8b7001cd3a07439ed3378427

If the Blender Comment operator was turned into a toggle operator the troubles for non-english keyboards could be solved by also adding Ctrl + Shift + 7 as a shortcut (un)commenting.

It's probably simplest to add a toggle-comment operator to Blender, internally it can just call uncomment, if that does nothing, call comment.

These can be made to work on the current line when there is no selection.

Since the Toggle Comment with a shortcut key was implemented, I'll abandon this diff, though I still think 'Find Set Selected' now called 'Find Next" in the menus, could use a shortcut key.