feat(admin-web): add Ctrl/Cmd+S save shortcut to article editor
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
import { LeftOutlined } from "@ant-design/icons-vue";
|
import { LeftOutlined } from "@ant-design/icons-vue";
|
||||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/vue-query";
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/vue-query";
|
||||||
import { message } from "ant-design-vue";
|
import { message } from "ant-design-vue";
|
||||||
import { computed, ref, watch } from "vue";
|
import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import { useRoute, useRouter } from "vue-router";
|
import { useRoute, useRouter } from "vue-router";
|
||||||
|
|
||||||
@@ -187,6 +187,20 @@ async function handleSave(): Promise<void> {
|
|||||||
await saveArticle();
|
await saveArticle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleSaveShortcut(event: KeyboardEvent): void {
|
||||||
|
if (!(event.ctrlKey || event.metaKey) || event.key.toLowerCase() !== "s") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
if (event.repeat || saveDisabled.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleSave();
|
||||||
|
}
|
||||||
|
|
||||||
async function handlePublish(): Promise<void> {
|
async function handlePublish(): Promise<void> {
|
||||||
if (editorLocked.value) {
|
if (editorLocked.value) {
|
||||||
return;
|
return;
|
||||||
@@ -344,6 +358,14 @@ function serializePlatformSelection(platformIds: string[]): string {
|
|||||||
.sort()
|
.sort()
|
||||||
.join(",");
|
.join(",");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
window.addEventListener("keydown", handleSaveShortcut);
|
||||||
|
});
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
window.removeEventListener("keydown", handleSaveShortcut);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -355,7 +377,13 @@ function serializePlatformSelection(platformIds: string[]): string {
|
|||||||
</button>
|
</button>
|
||||||
|
|
||||||
<div class="article-editor-view__actions">
|
<div class="article-editor-view__actions">
|
||||||
<a-button :disabled="saveDisabled" :loading="saveMutation.isPending.value" @click="handleSave">
|
<a-button
|
||||||
|
:disabled="saveDisabled"
|
||||||
|
:loading="saveMutation.isPending.value"
|
||||||
|
title="Ctrl/Cmd + S"
|
||||||
|
aria-keyshortcuts="Control+S Meta+S"
|
||||||
|
@click="handleSave"
|
||||||
|
>
|
||||||
{{ t("common.save") }}
|
{{ t("common.save") }}
|
||||||
</a-button>
|
</a-button>
|
||||||
<a-button type="primary" :disabled="editorLocked" @click="handlePublish">
|
<a-button type="primary" :disabled="editorLocked" @click="handlePublish">
|
||||||
|
|||||||
Reference in New Issue
Block a user