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

Changed keyboard shortcut for indent/outdent #3835

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tommylenz
Copy link

@tommylenz tommylenz commented Feb 24, 2025

tl;dr: Indent/outdent shortcuts did not work on macOS. Switching from Control + Shift + . to Tab for indent, and from Control + Shift + , to Shift + Tab for outdent. Tests did pass.

As discussed in this Anki forum thread, and many other older forum threads, shortcuts are not working for all systems or keyboard layouts. As Anki is widely used among language learners from different countries, the app is prone to the problem of users having switched their keyboard layout by adjusting system settings (e.g., I am switching between German, English US and Unicode Hex on my MacBook by pressing the fn button). Yet, even with default settings, not all keyboard shortcuts that are displayed as tooltips in the Anki app work. See the thread linked above for a non-exhaustive list of more than ten shortcuts not working on the up-to-date Anki version on macOS for other than standard English keyboard layouts, as the shortcuts are asking for keyboard combinations not possible on those keyboards.

Example: Indent is tool tipped as Control + Shift + ., which works using a standard English keyboard layout. Yet, the. (period) key is a so called writing system key as per W3C, and as such, the result a key press yields is different based on the keyboard layout a users is using: For standard English layout users, the key will yield a period irrespective of Shift being pressed. For German users, pressing the period system key will yield a period only if Shift is not pressed simultaneously. When pressing Shift as well, it will yield a colon. As such, the tool-tipped shortcut cannot be typed using some layouts, amongst them the German keyboard layout. (See more examples for this on the W3C proposed recommendation document linked at the beginning of this paragraph.)

While we are working out the best solution (uniform shortcuts for all keyboard layouts? customisable shortcuts? let users select a locale in the settings? …), I thought it would not hurt to already fix the shortcut for indent/outdent.

Using Tab and Shift + Tab seemed to be natural options to me, as they are used for the mechanic in apps widely known, like Word, Pages, or Obsidian. Those keys are considered so called functional keys by the W3C (cf here), and as such will work on nearly all layouts. Adjusting shortcuts for other buttons is as easy—I successfully tried this with superscript by replacing Control + Shift + = with some other combination, e.g., Control + O–if we were to agree on which combinations the shortcuts should have. In my opinion, the thread seems to be the right place to do that. As for this quick fix, ./ninja checks did pass for me on macOS.

This is my first contribution to Anki code and the first thread in the forums I am taking part in. I am happy for feedback and advice. It would be an honour to contribute to this app that I have been a user of for many years, and no doubt will be for many more to come.

Copy link
Contributor

@GithubAnon0000 GithubAnon0000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one potential problem with this: Tab is used to switch from field1 to field2. This is a pretty standard behavior which is also used to "iterate" over other menu entries of the UI. It might be important for accessibility reasons to keep this behavior functioning.

This old behavior would be overridden with this PR. If this PR would be merged, switching from field1 to field2 instantly throws this:
anki
I think that's an issue.

And if you actually have ordered or unordered lists in your field, then pressing Tab to switch to field2 will indent instead. That's quite unexpected though.

Maybe a solution to this would be using Control+Tab and Control+Shift+Tab for intendation instead?

@dae
Copy link
Member

dae commented Feb 27, 2025

Yes, I'm afraid Tab is a non-starter, as many people use that to switch between fields.

Ctrl+tab may bite us in the future if we offer a tabbed UI, since that's a common shortcut to cycle through tabs, but a brief Google seems to indicate it's not a system-wide shortcut.

@tommylenz
Copy link
Author

Well, sometimes you don't see the forest for the trees. Thanks @GithubAnon0000 for pointing this out. Ctrl + Tab as is would be Meta + Tab for macOS, which is indeed a system-wide shortcut. We maybe could use Alt + Tab, whereas Alt is labeled Option on Mac keyboards, but I'd need to test that first.

@user1823
Copy link
Contributor

We maybe could use Alt + Tab

Alt + Tab is a system-wide shortcut on Windows for switching apps.

@GithubAnon0000
Copy link
Contributor

Alt + Tab is a system-wide shortcut on Windows for switching apps.

Same on linux. Super+Tab is an additional common shortcut for switching apps on linux, so that won't work either.

@tommylenz
Copy link
Author

tommylenz commented Mar 1, 2025

Thanks for the input. As we already discussed in the forum, it's really not that simple to find a combination. But I'd rather have different shortcuts for Win/Mac/Linux than a non-working shortcut on macOS.

As dae pointed out, for macOS, Control + Tab and Control + Shift + Tab (using Macs Control-Button) does not seem to be a good option, if Anki were to (re-)introduce tabbed UI in the future (which I'd appreciate).

How about using ⌥ Option + (Shift +) Tab for Mac? Right now, this combination switches trough the different fields, just as a plain Tab does. I guess users a using plain Tab to cycle trough the fields, so this should stay the way it is.
⌥ Option equals Alt on Windows keyboards. As Anon0000 said before, Alt + Tab is a system-wide shortcut for Windows and Linux. But we could switch for Mac only. If the current shortcut works for Windows and Linux, it can stay this way.
The proposed shortcut is not a system-wide shortcut for macOS as of current version. ⌥ Option is a functional key as well. It is used in some apps to jump to the start of the page (e.g. Safari browser), but this is not the case for Anki, and I don't see the need to introduce that in the future.
How about that?

@blochberger
Copy link

Technically, there are working shortcuts on macOS for indent/outdent: ⌘ Command + Shift + . and ⌘ Command + Shift + ,, tried with Anki 25.02 on macOS.

However, the default behavior is to use Tab and Shift + Tab for text input instead of focus changes, when in a text control, see https://support.apple.com/en-us/102650. Focus navigation would then be done using ⌃ Control + Tab.

@tommylenz
Copy link
Author

Interesting, they do not work for me on macOS. (See my Anki version and system in the forum thread I referenced.) I have asked colleagues of mine to confirm, and it does not work for them either. We'd have to investigate why it works for you, but does not work for some others.

@blochberger
Copy link

I just installed it via brew install anki on macOS 13.7.4. Note that the combination only works, if you are in a list item. It cannot be used to create a new list, but if you try it outside of a list, the following error dialog pops up:

Indent/unindent currently only works with lists.

Debug Info
Anki 25.02 (038d85b)
Python 3.9.18 Qt 6.6.2 PyQt 6.6.1
Platform: macOS-13.7.4-x86_64-i386-64bit

@GithubAnon0000
Copy link
Contributor

Note that the combination only works, if you are in a list item. It cannot be used to create a new list, but if you try it outside of a list, the following error dialog pops up:

Indent/unindent currently only works with lists.

Yes, that's expected behavior. This PR only aims at changing the keyboard shortcut to something that works for most keyboard layouts and languages.


How about using ⌥ Option + (Shift +) Tab for Mac?
[…]
But we could switch for Mac only. If the current shortcut works for Windows and Linux, it can stay this way.

Is it possible to define OS specific shortcuts in Anki with the current code? I might have missed that. If it isn't possible then I don't know whether changing the shortcut to Alt+(Shift+)Tab (or ⌥ Option+(Shift+)Tab) is a wise idea. The current shortcut works for all operating systems (if used with an english layout) but fails with other layouts like a german layout. That sounds better to me than having something work only for one OS.

Since we're trying out shortcuts: I don't see why we'd have to restrict ourselves to the function keys. As I see it the main problem here is that Shift changes the key pressed (e.g. the . key becomes : with Shift pressed on a german keyboard). So why not use something like Control+Alt+, for outdent and Control+Alt+. for indent? This works on linux with my german layout – but I cannot test other OSes and layouts.

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

Successfully merging this pull request may close these issues.

6 participants