From 44a24736aa2c474694abc47d3d8c3f867739a113 Mon Sep 17 00:00:00 2001 From: Sakurasan <26715255+Sakurasan@users.noreply.github.com> Date: Tue, 29 Sep 2026 00:36:22 +0800 Subject: [PATCH] =?UTF-8?q?md=20=E5=B7=A5=E5=85=B7=E6=A0=8F=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E9=85=8D=E5=BF=AB=E6=8D=B7=E9=94=AE=EF=BC=9A=E2=8C=98?= =?UTF-8?q?B=20=E5=8A=A0=E7=B2=97=20/=20=E2=8C=98I=20=E6=96=9C=E4=BD=93=20?= =?UTF-8?q?/=20=E2=8C=98E=20=E8=A1=8C=E5=86=85=E4=BB=A3=E7=A0=81=20/=20?= =?UTF-8?q?=E2=8C=98K=20=E9=93=BE=E6=8E=A5=EF=BC=88CodeMirror=20keymap?= =?UTF-8?q?=EF=BC=89=EF=BC=8Ctooltip=20=E8=87=AA=E5=8A=A8=E5=B8=A6?= =?UTF-8?q?=E5=87=BA=EF=BC=88Mod=20=E5=9C=A8=20Mac=20=E6=98=BE=E7=A4=BA=20?= =?UTF-8?q?=E2=8C=98=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/admin/EditorView.vue | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/frontend/src/admin/EditorView.vue b/frontend/src/admin/EditorView.vue index 14e4939..95e5143 100644 --- a/frontend/src/admin/EditorView.vue +++ b/frontend/src/admin/EditorView.vue @@ -458,6 +458,12 @@ function mountCM() { doc: form.content_md, extensions: [ history(), + keymap.of([ + { key: 'Mod-b', run: () => { tbBold(); return true } }, + { key: 'Mod-i', run: () => { tbItalic(); return true } }, + { key: 'Mod-e', run: () => { tbCode(); return true } }, + { key: 'Mod-k', run: () => { openLink(); return true } } + ]), keymap.of([...defaultKeymap, ...historyKeymap, indentWithTab]), markdownLang(), cmTheme, @@ -803,17 +809,26 @@ function insertDate() { } // 工具栏按钮的统一定义(用作 v-for 渲染) +// 快捷键的展示形态(xLog 同款):Mod 在 Mac 上显示 ⌘,其余显示 Ctrl +const isMac = typeof navigator !== 'undefined' && /Mac|iP(hone|ad|od)/.test(navigator.platform || '') +function keyDisplay(shortcut) { + if (!shortcut) return '' + return '(' + shortcut + .replace('Mod', isMac ? '⌘' : 'Ctrl') + .replace(/-([a-z])$/i, (_, c) => c.toUpperCase()) + ')' +} + const tbGroups = computed(() => [ { label: '格式', items: [ - { key: 'b', title: '加粗', run: tbBold, show: mode.value === 'md', + { key: 'b', title: '加粗', shortcut: 'Mod-b', run: tbBold, show: mode.value === 'md', icon: 'M6 4h8a4 4 0 0 1 0 8H6zM6 12h9a4 4 0 0 1 0 8H6z', fill: true }, - { key: 'i', title: '斜体', run: tbItalic, show: mode.value === 'md', + { key: 'i', title: '斜体', shortcut: 'Mod-i', run: tbItalic, show: mode.value === 'md', icon: 'M19 4h-9M14 20H5M15 4L9 20' }, { key: 's', title: '删除线', run: tbStrike, show: mode.value === 'md', icon: 'M16 4H9a3 3 0 0 0-2.83 4M14 12a4 4 0 0 1 0 8H6M4 12h16' }, - { key: 'code', title: '行内代码', run: tbCode, show: mode.value === 'md', + { key: 'code', title: '行内代码', shortcut: 'Mod-e', run: tbCode, show: mode.value === 'md', icon: 'M16 18l6-6-6-6M8 6l-6 6 6 6' }, { key: 'cb', title: '代码块', run: tbCodeBlock, show: mode.value === 'md', icon: 'M9 10l-2 2.5L9 15M15 10l2 2.5-2 2.5M4 5h16a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1z' } @@ -839,7 +854,7 @@ const tbGroups = computed(() => [ { label: '插入', items: [ - { key: 'link', title: '链接', run: openLink, show: mode.value === 'md', + { key: 'link', title: '链接', shortcut: 'Mod-k', run: openLink, show: mode.value === 'md', icon: 'M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71' }, { key: 'img', title: '图片', run: openImage, show: mode.value === 'md', icon: 'M21 15l-5-5L5 21M3 5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2zM8.5 8.5h.01' }, @@ -918,7 +933,7 @@ const tbGroups = computed(() => [ :key="it.key" type="button" class="tb-btn" - :title="it.title" + :title="it.title + keyDisplay(it.shortcut)" :aria-label="it.title" @click="it.run()" >