Skip to content

Commit bf4be31

Browse files
authored
feat: support more keyboard shortcuts for markdown formatting (#772)
1 parent 028a77b commit bf4be31

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/components/CodemirrorEditor/EditorHeader/index.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ const formatItems = [
4040
kbd: [ctrlSign, `E`],
4141
emitArgs: [`addFormat`, `${ctrlKey}-E`],
4242
},
43+
{
44+
label: `标题`,
45+
kbd: [ctrlSign, `H`],
46+
emitArgs: [`addFormat`, `${ctrlKey}-H`],
47+
},
48+
{
49+
label: `无序列表`,
50+
kbd: [ctrlSign, `U`],
51+
emitArgs: [`addFormat`, `${ctrlKey}-U`],
52+
},
53+
{
54+
label: `有序列表`,
55+
kbd: [ctrlSign, `O`],
56+
emitArgs: [`addFormat`, `${ctrlKey}-O`],
57+
},
4358
{
4459
label: `格式化`,
4560
kbd: [altSign, shiftSign, `F`],

src/components/ai/AIAssistantPanel.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ async function sendMessage() {
562562
<!-- ============ 输入框 ============ -->
563563
<div v-if="!configVisible" class="relative mt-2">
564564
<div
565-
class="item-start bg-background border-border flex flex-col items-baseline gap-2 border rounded-xl px-3 py-2 pr-12 shadow-inner"
565+
class="bg-background item-start border-border flex flex-col items-baseline gap-2 border rounded-xl px-3 py-2 pr-12 shadow-inner"
566566
>
567567
<Textarea
568568
v-model="input"

src/views/CodemirrorEditor.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,21 @@ function initEditor() {
242242
const selected = editor.getSelection()
243243
editor.replaceSelection(`\`${selected}\``)
244244
},
245+
[`${ctrlKey}-H`]: function heading(editor) {
246+
const selected = editor.getSelection()
247+
editor.replaceSelection(`# ${selected}`)
248+
},
249+
[`${ctrlKey}-U`]: function unorderedList(editor) {
250+
const selected = editor.getSelection()
251+
const lines = selected.split(`\n`).map(line => `- ${line}`)
252+
editor.replaceSelection(lines.join(`\n`))
253+
},
254+
255+
[`${ctrlKey}-O`]: function orderedList(editor) {
256+
const selected = editor.getSelection()
257+
const lines = selected.split(`\n`).map((line, i) => `${i + 1}. ${line}`)
258+
editor.replaceSelection(lines.join(`\n`))
259+
},
245260
// 预备弃用
246261
[`${ctrlKey}-L`]: function code(editor) {
247262
const selected = editor.getSelection()

0 commit comments

Comments
 (0)