Unregistering a Key Binding not working?

I am writing a macro to add certain key bindings. Using the API, I have the following code:

var	kb=require("ko/keybindings");
	kb.unregister('cmd_newlineBare');
	kb.register('cmd_newlineBare', 'Shift+Return', true);	// force

alert(kb.getKeybindFromCommand('cmd_newlineBare'));

I though that unregister would remove existing bindings. However, I find that if I run this command multiple times, the key binding appears multiple times. I only appears once in the preference window, but multiple times in the kkf file, and in the alert() above. That would suggest that unregister is not doing what I thought it would.

Is this the correct method, but not working, or is there a better method?

Seems you might have found a bug in the SDK, best if you report it on our bug tracker.

As for there being a better method, generally I would recommend you use ko/commands instead and then set the keybinding yourself through your preferencecs window. Setting the keybinding explicitly through code is a bit awkward and has to be able to handle a lot of edge cases that you probably don’t want to be dealing with.

Thanks for that. I’m writing a convenience addon for my new students, and I just wanted to be able to modify a few shortcuts for them.

I don’t really need to unregister anything. I just found that in my testing, it was possible to add the shortcut multiple times, so I thought it would be safest to unregister first. I’ll include ko/commands as a link, though.

Following this up, is there a way of removing key bindings using the Legacy API?

You could inspect the SDK module itself and see how it does this: