Skip to content

Commit

Permalink
fix: slash menus
Browse files Browse the repository at this point in the history
  • Loading branch information
Seedsa committed Sep 30, 2024
1 parent ece6cb7 commit f8ac087
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/components/Menubars.vue
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,13 @@ const menubarMenus = ref<MenuGroup[]>([
{
type: 'link',
attrs: {
href: 'link',
href: '',
target: '_blank',
},
},
],
})
.setLink({ href: 'link' })
.setLink({ href: '' })
.focus()
.run()
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/icons/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const icons = {
ChevronsUpDown: 'lucide:chevrons-up-down',
LineHeight: 'mdi:format-line-height',
Word: 'mdi:file-word-outline',
Paragraph: 'lucide:text',
Paragraph: 'ci:text',
Heading1: 'lucide:heading-1',
Heading2: 'lucide:heading-2',
Heading3: 'lucide:heading-3',
Expand Down
85 changes: 61 additions & 24 deletions src/extensions/SlashCommand/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ export function renderGroups(editor: Editor) {
name: 'format',
title: t.value('editor.slash.format'),
commands: [
{
name: 'paragraph',
label: t.value('editor.paragraph.tooltip'),
aliases: ['paragraph', 'zw'],
iconName: 'Paragraph',
action: ({ editor, range }) => {
editor.chain().focus().deleteRange(range).setHeading({ level: 1 }).run()
},
},
{
name: 'heading1',
label: t.value('editor.heading.h1.tooltip'),
Expand All @@ -32,7 +41,7 @@ export function renderGroups(editor: Editor) {
{
name: 'heading3',
label: t.value('editor.heading.h3.tooltip'),
aliases: ['h3', 'bt', 'bt3'],
aliases: ['h3', 'bt', 'bt3', 'heading3'],
iconName: 'Heading3',
action: ({ editor, range }) => {
editor.chain().focus().deleteRange(range).setNode('heading', { level: 3 }).run()
Expand All @@ -41,7 +50,7 @@ export function renderGroups(editor: Editor) {
{
name: 'bulletList',
label: t.value('editor.bulletlist.tooltip'),
aliases: ['ul', 'yxlb'],
aliases: ['ul', 'yxlb', 'bulletList'],
iconName: 'List',
action: ({ editor, range }) => {
editor.chain().focus().deleteRange(range).toggleBulletList().run()
Expand All @@ -57,13 +66,14 @@ export function renderGroups(editor: Editor) {
},
},
{
name: 'taskList',
label: t.value('editor.tasklist.tooltip'),
iconName: 'ListTodo',
description: 'Task list with todo items',
aliases: ['todo'],
name: 'codeBlock',
label: t.value('editor.codeblock.tooltip'),
iconName: 'Code2',
aliases: ['codeBlock'],
description: 'Code block with syntax highlighting',
shouldBeHidden: editor => editor.isActive('columns'),
action: ({ editor, range }) => {
editor.chain().focus().deleteRange(range).toggleTaskList().run()
editor.chain().focus().deleteRange(range).setCodeBlock().run()
},
},
{
Expand All @@ -77,13 +87,40 @@ export function renderGroups(editor: Editor) {
},
},
{
name: 'codeBlock',
label: t.value('editor.codeblock.tooltip'),
iconName: 'Code2',
description: 'Code block with syntax highlighting',
shouldBeHidden: editor => editor.isActive('columns'),
name: 'horizontalrule',
label: t.value('editor.horizontalrule.tooltip'),
aliases: ['fgx', 'horizontalRule'],
iconName: 'Minus',
action: ({ editor, range }) => {
editor.chain().focus().deleteRange(range).setCodeBlock().run()
editor.chain().focus().deleteRange(range).setHorizontalRule().run()
},
},
{
name: 'link',
label: t.value('editor.link.tooltip'),
aliases: ['link', 'lianjie', 'lj'],
iconName: 'Link',
action: ({ editor, range }) => {
editor
.chain()
.deleteRange(range)
.extendMarkRange('link')
.insertContent({
type: 'text',
text: 'link',
marks: [
{
type: 'link',
attrs: {
href: '',
target: '_blank',
},
},
],
})
.setLink({ href: '' })
.focus()
.run()
},
},
],
Expand Down Expand Up @@ -114,16 +151,6 @@ export function renderGroups(editor: Editor) {
editor.chain().focus().deleteRange(range).insertTable({ rows: 3, cols: 3, withHeaderRow: false }).run()
},
},
{
name: 'horizontalRule',
label: t.value('editor.horizontalrule.tooltip'),
iconName: 'Minus',
description: 'Insert a horizontal divider',
aliases: ['hr', 'fgx', 'fg'],
action: ({ editor, range }) => {
editor.chain().focus().deleteRange(range).setHorizontalRule().run()
},
},
{
name: 'video',
label: t.value('editor.video.tooltip'),
Expand All @@ -135,6 +162,16 @@ export function renderGroups(editor: Editor) {
editor.chain().focus().deleteRange(range).setVideoUpload().run()
},
},
{
name: 'taskList',
label: t.value('editor.tasklist.tooltip'),
iconName: 'ListTodo',
description: 'Task list with todo items',
aliases: ['todo'],
action: ({ editor, range }) => {
editor.chain().focus().deleteRange(range).toggleTaskList().run()
},
},
{
name: 'columns',
label: t.value('editor.columns.tooltip'),
Expand Down
2 changes: 1 addition & 1 deletion src/locales/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const locale: Record<string, string> = {
'editor.indent.tooltip': '增加缩进',
'editor.outdent.tooltip': '减少缩进',
'editor.columns.tooltip': '分栏',
'editor.link.tooltip': '网络链接',
'editor.link.tooltip': '链接',
'editor.link.unlink.tooltip': '取消链接',
'editor.link.open.tooltip': '打开链接',
'editor.link.edit.tooltip': '编辑链接',
Expand Down

0 comments on commit f8ac087

Please sign in to comment.