Repository: wagtail/wagtail
File: wagtail/admin/templatetags/wagtailadmin_tags.py (Python)

Code before:
        return _("Sent to %(task_name)s %(started_at)s") % translation_context

    return _("%(status_display)s %(task_name)s %(started_at)s") % translation_context


@register.inclusion_tag(
    "wagtailadmin/shared/keyboard_shortcuts_dialog.html", takes_context=True
)
def keyboard_shortcuts_dialog(context):
    user_agent = context["request"].headers.get("User-Agent", "")
    is_mac = re.search(r"Mac|iPod|iPhone|iPad", user_agent)
    modifier = "⌘" if is_mac else "Ctrl"
    shortcuts = {
        ("common-actions", _("Common Actions")): [
            {"label": _("Copy"), "shortcut": f"{modifier} + c"},
            {"label": _("Cut"), "shortcut": f"{modifier} + x"},
            {"label": _("Paste"), "shortcut": f"{modifier} + v"},
            {
                "label": _("Paste without formatting"),
                "shortcut": f"{modifier} + shift + v",
            },
            {"label": _("Undo"), "shortcut": f"{modifier} + z"},
            {"label": _("Redo"), "shortcut": f"{modifier} + y"},
        ],
        ("page-editing-actions", _("Page editing actions")): [
            {"label": _("Save"), "shortcut": f"{modifier} + s"},
            {"label": _("Preview"), "shortcut": f"{modifier} + p"},
        ],
        ("text-formatting", _("Text Formatting")): [
            {"label": _("Bold"), "shortcut": f"{modifier} + b"},
            {"label": _("Italic"), "shortcut": f"{modifier} + i"},
            {"label": _("Underline"), "shortcut": f"{modifier} + u"},
            {
                "label": _("Monospace (code)"),
                "shortcut": f"{modifier} + j",
            },
            {
                "label": _("Strike-through"),
                "shortcut": f"{modifier} + x",
            },
            {"label": _("Superscript"), "shortcut": f"{modifier} + ."},
            {"label": _("Subscript"), "shortcut": f"{modifier} + ,"},
        ],
        ("text-content", _("Text Content")): [
            {
                "label": _("Insert or edit a link"),
                "shortcut": f"{modifier} + k",
            }
        ],
    }
    return {

Review comment (suggestion):
I didn't know about `⌘ + s` :clap:

Models (snippets) are saved, but pages `Save draft`. Maybe the label should be `Save (draft)`?

This shortcut overrides the default browser behaviour. And in this specific case, that seems okay. Saving HTML is not a common thing to do. Overriding OS/browser shortcuts is something we should consider when adding more shortcuts.

This shortcut doesn't work when the cursor is inside a text-area. It will use the default, trigger the browser to save the HTML. -- Fixing this might be outside the scope of this PR.




Code after:
        return _("Sent to %(task_name)s %(started_at)s") % translation_context

    return _("%(status_display)s %(task_name)s %(started_at)s") % translation_context


@register.inclusion_tag(
    "wagtailadmin/shared/keyboard_shortcuts_dialog.html",
    takes_context=True,
)
def keyboard_shortcuts_dialog(context):
    """
    Renders the keyboard shortcuts dialog content with the
    appropriate shortcuts for the user's platform.
    Note: Shortcut keys are intentionally not translated.
    """

    user_agent = context["request"].headers.get("User-Agent", "")
    is_mac = re.search(r"Mac|iPod|iPhone|iPad", user_agent)
    modifier = "⌘" if is_mac else "Ctrl"

    return {
        "shortcuts": {
            ("actions-common", _("Common actions")): [
                (_("Copy"), f"{modifier} + c"),
                (_("Cut"), f"{modifier} + x"),
                (_("Paste"), f"{modifier} + v"),
                (
                    _("Paste and match style")
                    if is_mac
                    else _("Paste without formatting"),
                    f"{modifier} + Shift + v",
                ),
                (_("Undo"), f"{modifier} + z"),
                (
                    _("Redo"),
                    f"{modifier} + Shift + z" if is_mac else f"{modifier} + y",
                ),
            ],
            ("actions-model", _("Actions")): [
                (_("Save changes"), f"{modifier} + s"),
                (_("Preview"), f"{modifier} + p"),
            ],
            ("rich-text-content", _("Text content")): [
                (_("Insert or edit a link"), f"{modifier} + k")
            ],
            ("rich-text-formatting", _("Text formatting")): [
                (_("Bold"), f"{modifier} + b"),
                (_("Italic"), f"{modifier} + i"),
                (_("Underline"), f"{modifier} + u"),
                (_("Monospace (code)"), f"{modifier} + j"),
                (_("Strike-through"), f"{modifier} + x"),