Sublime Forum

Key binding for Edit Commit Message

#1

When I’m editing a commit message, I can finish and accept the new message with Cmd+Return (super+enter in Sublime key bindings parlance). escape cancels the edit. I want a way to BEGIN editing the commit message with a keystroke.

The default SM key bindings file has these bindings:

    { "keys": ["ctrl+enter"], "command": "commit", "args": { "mode": "commit" },
        "context": [{ "key": "setting.commit_message" }, { "key": "can_commit" }]
    },
    { "keys": ["ctrl+enter"], "command": "edit_commit",
        "context": [{ "key": "setting.commit_message" }, { "key": "read_only" }]
    },
    { "keys": ["ctrl+enter"], "command": "save_commit_message",
        "context": [{ "key": "setting.commit_message" }, { "key": "is_editing_commit" }]
    },
    { "keys": ["escape"], "command": "cancel_edit_commit_message",
        "context": [{ "key": "setting.commit_message" }, { "key": "is_editing_commit" }]

I can see escape, which works as expected, but I don’t understand why ctrl+enter doesn’t work to save the commit message, but super+enter does. This does work to begin editing:

    {   // Edit commit message
        "keys": ["super+enter"],
        "command": "edit_commit",
        "args": { "commit": "$commit" }
    },

Is this correct? Why do the other versions of this in the default file not include the commit?

0 Likes

#2

Are you by any chance on MacOS? The bindings for these operation on MacOS are:

	{ "keys": ["super+enter"], "command": "commit", "args": { "mode": "commit" },
		"context": [{ "key": "setting.commit_message" }, { "key": "can_commit" }]
	},
	{ "keys": ["super+enter"], "command": "edit_commit",
		"context": [{ "key": "setting.commit_message" }, { "key": "read_only" }]
	},
	{ "keys": ["super+enter"], "command": "save_commit_message",
		"context": [{ "key": "setting.commit_message" }, { "key": "is_editing_commit" }]
	},
	{ "keys": ["escape"], "command": "cancel_edit_commit_message",
		"context": [{ "key": "setting.commit_message" }, { "key": "is_editing_commit" }]
	},

Or if you will, Default (OSX).sublime-keymap contains no mappings on the key ctrl+enter and the Windows/Linux versions of the file have no mappings on the key super+enter.

0 Likes

#3

Hi, thanks for the reply!

Yeah, I’m on macOS. The file I consulted was /Applications/Sublime Merge.app/Contents/MacOS/Packages/Default - Merge.sublime-package.

OOOH, and when I look further down in that file, under (as you say) Default (OSX).sublime-keymap, I do see the section you mention. Given that what I want appears to be the default, why do I have to add my own key binding to get super+enter to work?

0 Likes

#4

Well that is an interesting question indeed; I know the binding is there by default but since my Mac has died I can’t verify personally that it actually works.

The only reason I can see for it not doing anything would be if the key is being boosted by some external third party application, which would block Sublime from seeing it. However if that was the case, adding a manual binding for that key would not be seen either.

Does your binding exactly match the one that’s built in (including the context list, which says when the binding should be considered active)?

0 Likes

#5

The plot thickens. When I use this binding I cobbled together, then entering edit mode for the commit message works. However, SAVING the commit message with super+enter stops working. Presumably, that’s because I have no context, so it’s being triggered in the save_commit_message context as well:

    {   // Edit commit message
        "keys": ["super+enter"],
        "command": "edit_commit",
        "args": { "commit": "$commit" }
    },

Is there some way to test my theory and figure out which command is being triggered when I press super+enter?

When I remove the binding, of course, I can’t use super+enter to enter edit mode anymore, but it DOES work for saving if I’m already in edit mode. I also tried adding the four bindings you reproduced into my personal key bindings file. Unsurprisingly, that didn’t change the behavior at all. I also tried adding the commit argument to them, which is missing in the SM default. Example:

{
    "keys": ["super+enter"],
    "command": "commit",
    "args": { "mode": "commit", "commit": "$commit" },
    "context": [{ "key": "setting.commit_message" }, { "key": "can_commit" }]
},

But that was kind of a Hail Mary, and it didn’t help either. I also tried fiddling with the context by removing some of the items, but the behavior didn’t change.

It would be very helpful to understand if this is happening to other Sublime Merge users as well. As you say, it doesn’t seem like this is an issue with conflicting key bindings from other programs.

0 Likes

#6

Given this new data, I’ve filed a bug with Sublime. If anyone can test this on a Mac, please let me know what you find!

0 Likes

#7

Hmm, so after fiddling a bit, I’m able to get all 3 scenarios working (enter edit mode, cancel edit, save edit) with this combination of bindings in my Packages/User/Default (OSX).sublime-keymap:

    {
        "keys": ["super+enter"],
        "command": "edit_commit",
        "args": { "commit": "$commit" },
    },
    {
        "keys": ["super+enter"],
        "command": "save_commit_message",
        "context": [{ "key": "setting.commit_message" }, { "key": "is_editing_commit" }]
    },

Not sure what the read_only rule is about in the default bindings, so I can’t test that. Still seems like a bug to me.

0 Likes

#8

If you add "log_commands": true, to your preferences file, every time a command executes it will get logged into the console.

0 Likes

#9

Ah, great! So with the defaults, I’m seeing this in the console when I press Cmd+Return:

no command for selector: noop:

And, indeed, with only my first edit_commit binding I get this, both when entering commit mode and also on trying to save:

command: edit_commit {"commit": "$commit"}

I’ve refined my binding so that it now works in all 3 cases with a single new binding:

    {
        "keys": ["super+enter"],
        "command": "edit_commit",
        "context": [{ "key": "setting.commit_message" },
                    { "key": "is_editing_commit", "operator": "not_equal" }]
    },

I still think this is a bug in the default bindings, although I can’t quite figure out how to adjust them to make it work. But anyway, thanks for your help!

0 Likes