Closed Bug 1520119 Opened 1 year ago Closed 2 months ago

Support removing a shortcut in manage shortcuts

Categories

(WebExtensions :: Frontend, defect, P3)

66 Branch
defect

Tracking

(firefox64 disabled, firefox65 disabled, firefox66 wontfix, firefox67 wontfix, firefox74 verified)

VERIFIED FIXED
mozilla74
Tracking Status
firefox64 --- disabled
firefox65 --- disabled
firefox66 --- wontfix
firefox67 --- wontfix
firefox74 --- verified

People

(Reporter: cbadescu, Assigned: robwu)

References

Details

Attachments

(3 files)

Attached image Delete.gif

[Affected versions]:

  • Firefox 66.0a1 (20190114215201)

[Affected platforms]:

  • Win 7 64-bit
  • Mac OS X 10.13.3

[Steps to reproduce]:

  1. Install https://addons.mozilla.org/en-US/firefox/addon/shortkeys/
  2. Navigate to Extensions from about:addons page.
  3. Click on the “Keyboard” button.
  4. The detailed page with the shortcuts that can assigned to the extension is displayed.
  5. Assign a shortcut key.
  6. Try to delete the assigned shortcut.

[Expected results]:

  • The assigned shortcut is deleted and the input field is empty.

[Actual results]:

  • You can’t delete the assigned shortcut, you are forced to add another shortcut.

Please see the attached video.

Summary: User is forced to type another shortcut key in case he wants to let the input field with no shortcut key assigned → User is forced to type another shortcut key in case he wants to leave the input field with no shortcut key assigned
Summary: User is forced to type another shortcut key in case he wants to leave the input field with no shortcut key assigned → User is forced to type another shortcut key in case he wants to let the input field with no shortcut key assigned
Assignee: nobody → mstriemer
Priority: -- → P2
Summary: User is forced to type another shortcut key in case he wants to let the input field with no shortcut key assigned → Support removing a shortcut in manage shortcuts

Interface suggestion

I think that deleting the custom shortcut should be possible with two interfaces, one for the keyboard and one for the mouse. The keyboard method is convenient and quick after the user has already clicked in the field. The mouse method makes the deletion functionality more discoverable and assures the user that experimentation is safe because deleting the shortcut later is possible.

  • Pressing the Delete key should delete the shortcut when the shortcut field is focused and saying “Type a shortcut”. This will not clash with the user intending to set a shortcut that uses the Delete key because shortcuts are required to have a modifier within them.

  • Clicking a ‘(×)’ button within the field or next to the field should delete the shortcut. As a macOS user, the shortcut widgets I have seen in native apps had Delete buttons that looked just like the ‘(×)’ search cancel button in WebKit browsers. However, since Firefox doesn’t display a cancel button in its search fields, that might not match Firefox’s style. The other option is displaying a ‘(×)’ button to the right of the field, and making the field slightly less wide to keep the Manage Extension Shortcuts interface the same width. In either case, the button should have title text like “Clear this shortcut”.

I’m not sure which is the best terminology for this behavior: Clear, Delete, or Remove the shortcut. That terminology choice would affect only the button title text and the internal code.

Until this is implemented, does anyone know of a workaround to remove shortcuts? Which file in our Firefox Profile can we edit, or what commands can we type into the Browser Console, to delete a registered shortcut?

Not sure how to use that workaround. As a console command it says browser is not defined.
Anyway I can confirm this has still not been fixed. I tried just directly editing my extensions' manifest.json files to remove the "suggested-key" values. But firefox deletes the extensions on boot when I modify them, so I have to install them directly from an xpi file on my desktop, which makes them ineligible for online updates. What I really need is a way to change the local preference for the keyboard shortcut, not to change the extension's default shortcut. I've been trying to find a way to change the shortcut without modifying the actual extension file but I can't get the console command to work.

Anyway if you don't mind not receiving automatic updates for the extension in question, and you don't mind manually repeating this process for every update, then you can remove the default shortcut. Go to the profiles folder under AppData/Roaming/etc., find your profile, go to extensions folder. Locate the extension in question. If the extensions have random gibberish names, then open the extensions folder in 7-zip file manager and double click the xpi files. They are just zip files with a different extension name. The manifest.json is the file you need to edit and it also typically contains the title of the extension. If it doesn't, there are probably some other files in the xpi with clues as to the extension's identity. Icons and stuff. Anyway, open the manifest.json file, and find "commands". This section should have some of these:

    "name-of-command": {
        "suggested_key": {
            "default": "Ctrl+Shift+X",
            "mac": "Command+Shift+X"
        },
        "description": "Do the thing"
    }

Just delete the "suggested_key" section entirely, so it becomes:

    "name-of-command": {
        "description": "Do the thing"
    }

This way the object and description will still exist in the keyboard shortcuts menu, so you can still use it. But instead of it giving you a default hotkey that you can't get rid of, it just starts out blank. I'm not sure what to do if you accidentally fill the shortcut yourself after that. Since I don't think doing so within firefox would edit the manifest.json file, yet I can't find any local, profile-exclusive file that contains user-modified shortcuts, you might just have to uninstall the extension, rename the extension "title" in the manifest.json or rename the XPI, or both, then reinstall it so that firefox doesn't realize you have preexisting settings for the extension.

Anyway after that, save the manifest.json and repack all the files into a zip, then rename it .xpi, then put it on your desktop or something. Then open FF, uninstall the regular version of the extension, and on about:addons click the gear and "install add-on from file" or whatever. Locate your XPI and it should install your version of the extension. May or may not receive auto-updates, if it does then there's probably a reference to the online extension ID (via the store page) written in the XPI that you need to remove, so firefox stops recognizing it as a legit extension. Obviously to do this I think you need to enable unsigned extensions which I don't think you can do in the main or beta builds. But if you're reading this thread in the first place you probably already get all that.

Priority: P2 → P3

https://bugzilla.mozilla.org/show_bug.cgi?id=1520119#c4 is a good start. If it is not the main feature of your Addon to provide a shortcut, then it is also a good idea to not set a default and allow the user to pick whatever he likes best.

This is also the "base" for the only way to get rid of shortcuts, I'm aware of. In your "options_ui" you can add a button which, when clicked, executes something like this:

browser.commands.getAll().then((commands) => {
  commands.forEach((cmd) => {browser.commands.reset(cmd.name);})
});

If a user has set a shortcut for one of your commands, then this code resets it back to "no shortcut". But only if no default is set!

But long story short: This bug really should be fixed with priority. It can't be that difficult to just clear the selected hotkey if the "Del" key is pressed. It's a bit silly that every Addon needs its own button to reset shortcuts...

That's cool, thanks for the snippet. I totally agree, I can't comprehend how this can be considered a low priority. In practice it basically puts an upper limit on the number of extensions someone can use, unless they don't mind having most of their hotkeys taken up by useless features.

(In reply to rugk from comment #3)

Workaround is here: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/commands/update (AFAIK just set a empty string as the hot key.)

Note that I don't seem to be able to set empty string via update in FF 70.0b6:

>>> browser.commands.getAll().then(cmds => cmds.forEach(cmd => browser.commands.update({name: cmd.name, shortcut: ""})));

Error: Type error for parameter detail (Error processing shortcut: Error: Value "" must consist of either a combination
of one or two modifiers, including a mandatory primary modifier and a key, separated by '+', or a media key. For details
see: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json/commands#Key_combinations) for
commands.update.

The method, I've shown in
https://bugzilla.mozilla.org/show_bug.cgi?id=1520119#c5
still works on the latest Nightly.

But it requires that you don't set a default shortcut.
I have a silly "Reset keboard shortcut" button on all my Addons, now. Currently this is the only way to allow the user to get rid of shortcuts he no longer wants to have or wants to rebind to some other Addon.

A rather hacky workaround if you still want default bindings is to use commands.update to assign an existing browser shortcut.

If a key combination is already used by the browser (for example, "Ctrl+P"), or by an existing add-on, then you can't override it. You will be allowed to define it, but your event handler will not be called when the user enters it

https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/commands

For example:

 browser.commands.update({name: "unassign-me1, shortcut: "Ctrl+P"});
 browser.commands.update({name: "unassign-me2, shortcut: "Ctrl+P"});

This effectively "unassigns" it but will produce a "duplicate shortcut" warning in the shortcut manager (even though it cannot be triggered).

What about for users? None of the extensions I use with any shortcuts at all have taken any of this advice unfortunately. Every single one of them has default shortcuts

Duplicate of this bug: 1586554
See Also: → 1475043

In Chrome (77), it doesn't appear to be possible to completely remove a shortcut. At most it's possible to reset a shortcut to the default value of extensions. I'm not going to copy that behavior; the proposed patch allows the user to completely clear a (default) shortcut via the Delete / Backspace key (Backspace is included because the Delete key is not always available on keyboards).

Emanuela, would it be fine to already land the proposed patch (adding the ability to clear the shortcut with Delete / Backspace, and still allowing those keys with modifiers to be used as shortcuts)? That would allow us to support deletion of extension shortcuts in Fx71 already.

I'd also like to add a button near the shortcut input field, but I want to move that to a follow-up bug because the exact appearance and functionality requires more discussion with UX/you (see first four comments at https://phabricator.services.mozilla.com/D48995#1487104 ).

Assignee: mstriemer → rob
Status: NEW → ASSIGNED
Flags: needinfo?(emanuela)
Duplicate of this bug: 1591333

This partially addresses the issues I reported in Bug 1591333, but not completely.

As a developer of many extensions, I would like the commands.update() API to be updated to allow removal of an extension keyboard shortcut. Alternatively, there could be a new API such as commands.remove() or commands.delete().

@dw-dev That functionality is being implemented in bug 1475043 .

71 shipped already, so we can now try to get everything in at once in 72.

I'll needinfo UX again when there is visible UI.

Flags: needinfo?(emanuela)

There's a r+ patch which didn't land and no activity in this bug for 2 weeks.
:robwu, could you have a look please?
For more information, please visit auto_nag documentation.

Flags: needinfo?(rob)
Pushed by rob@robwu.nl:
https://hg.mozilla.org/integration/autoland/rev/11adf9e8a22a
Allow shortcut removal via Del/Backspace key r=mstriemer
https://hg.mozilla.org/integration/autoland/rev/f85f695665e8
Allow shortcut removal via button r=mstriemer
Flags: needinfo?(rob)
Status: ASSIGNED → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla74

Hello,

Verified the fix on the latest Nightly (74.0a1/20200202214642) under Windows 10 Pro 64-bit and macOS Catalina 10.15.

Extension shortcuts can now be properly deleted using either Backspace, Delete or the designated button on the left of the shortcut field, on Windows and either Backspace, Fn+Backspace (Delete equivalent) or the designated button, on macOS.

Status: RESOLVED → VERIFIED
Duplicate of this bug: 1619869
You need to log in before you can comment on or make changes to this bug.