mirror of https://github.com/halo-dev/halo
feat: add the clear format function to the default rich text editor (#5685)
#### What type of PR is this? /kind feature /area editor /milestone 2.15.x #### What this PR does / why we need it: 为默认富文本编辑器添加清除格式的功能。快捷键为 `Mod + \`。 #### How to test it? 输入文本,使用加粗、链接、斜体等 mark 相关功能,之后使用清除格式,查看格式是否被清除。 #### Which issue(s) this PR fixes: Fixes #5684 #### Does this PR introduce a user-facing change? ```release-note 为默认富文本编辑器添加清除格式的功能。 ```pull/5697/head
parent
60f113110b
commit
a317ec9563
|
@ -45,6 +45,7 @@ import {
|
||||||
ExtensionTrailingNode,
|
ExtensionTrailingNode,
|
||||||
ExtensionListKeymap,
|
ExtensionListKeymap,
|
||||||
ExtensionSearchAndReplace,
|
ExtensionSearchAndReplace,
|
||||||
|
ExtensionClearFormat,
|
||||||
} from "../index";
|
} from "../index";
|
||||||
|
|
||||||
const content = useLocalStorage("content", "");
|
const content = useLocalStorage("content", "");
|
||||||
|
@ -111,6 +112,7 @@ const editor = useEditor({
|
||||||
ExtensionTrailingNode,
|
ExtensionTrailingNode,
|
||||||
ExtensionListKeymap,
|
ExtensionListKeymap,
|
||||||
ExtensionSearchAndReplace,
|
ExtensionSearchAndReplace,
|
||||||
|
ExtensionClearFormat,
|
||||||
],
|
],
|
||||||
parseOptions: {
|
parseOptions: {
|
||||||
preserveWhitespace: true,
|
preserveWhitespace: true,
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
import { Extension } from "@/tiptap";
|
||||||
|
import type { ExtensionOptions } from "@/types";
|
||||||
|
import type { Editor } from "@/tiptap";
|
||||||
|
import { markRaw } from "vue";
|
||||||
|
import IconParkSolidClearFormat from "~icons/icon-park-solid/clear-format";
|
||||||
|
import ToolbarItem from "@/components/toolbar/ToolbarItem.vue";
|
||||||
|
import { i18n } from "@/locales";
|
||||||
|
|
||||||
|
const clearFormat = Extension.create<ExtensionOptions>({
|
||||||
|
addOptions() {
|
||||||
|
return {
|
||||||
|
getToolbarItems({ editor }: { editor: Editor }) {
|
||||||
|
return {
|
||||||
|
priority: 23,
|
||||||
|
component: markRaw(ToolbarItem),
|
||||||
|
props: {
|
||||||
|
editor,
|
||||||
|
isActive: false,
|
||||||
|
icon: markRaw(IconParkSolidClearFormat),
|
||||||
|
title: i18n.global.t("editor.common.clear_format"),
|
||||||
|
action: () => editor.chain().focus().unsetAllMarks().run(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
addKeyboardShortcuts() {
|
||||||
|
return {
|
||||||
|
"Mod-\\": () => this.editor.chain().focus().unsetAllMarks().run(),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default clearFormat;
|
|
@ -43,6 +43,7 @@ import ExtensionDraggable from "./draggable";
|
||||||
import ExtensionNodeSelected from "./node-selected";
|
import ExtensionNodeSelected from "./node-selected";
|
||||||
import ExtensionTrailingNode from "./trailing-node";
|
import ExtensionTrailingNode from "./trailing-node";
|
||||||
import ExtensionSearchAndReplace from "./search-and-replace";
|
import ExtensionSearchAndReplace from "./search-and-replace";
|
||||||
|
import ExtensionClearFormat from "./clear-format";
|
||||||
|
|
||||||
const allExtensions = [
|
const allExtensions = [
|
||||||
ExtensionBlockquote,
|
ExtensionBlockquote,
|
||||||
|
@ -100,6 +101,7 @@ const allExtensions = [
|
||||||
ExtensionNodeSelected,
|
ExtensionNodeSelected,
|
||||||
ExtensionTrailingNode,
|
ExtensionTrailingNode,
|
||||||
ExtensionSearchAndReplace,
|
ExtensionSearchAndReplace,
|
||||||
|
ExtensionClearFormat,
|
||||||
];
|
];
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
@ -147,4 +149,5 @@ export {
|
||||||
ExtensionTrailingNode,
|
ExtensionTrailingNode,
|
||||||
ExtensionListKeymap,
|
ExtensionListKeymap,
|
||||||
ExtensionSearchAndReplace,
|
ExtensionSearchAndReplace,
|
||||||
|
ExtensionClearFormat,
|
||||||
};
|
};
|
||||||
|
|
|
@ -132,3 +132,4 @@ editor:
|
||||||
text:
|
text:
|
||||||
default: Default
|
default: Default
|
||||||
line_height: Line height
|
line_height: Line height
|
||||||
|
clear_format: Clear format
|
||||||
|
|
|
@ -132,3 +132,4 @@ editor:
|
||||||
text:
|
text:
|
||||||
default: 默认
|
default: 默认
|
||||||
line_height: 行高
|
line_height: 行高
|
||||||
|
clear_format: 清除格式
|
||||||
|
|
|
@ -47,6 +47,7 @@ import {
|
||||||
DecorationSet,
|
DecorationSet,
|
||||||
ExtensionListKeymap,
|
ExtensionListKeymap,
|
||||||
ExtensionSearchAndReplace,
|
ExtensionSearchAndReplace,
|
||||||
|
ExtensionClearFormat,
|
||||||
} from "@halo-dev/richtext-editor";
|
} from "@halo-dev/richtext-editor";
|
||||||
// ui custom extension
|
// ui custom extension
|
||||||
import {
|
import {
|
||||||
|
@ -396,6 +397,7 @@ onMounted(() => {
|
||||||
ExtensionListKeymap,
|
ExtensionListKeymap,
|
||||||
UiExtensionUpload,
|
UiExtensionUpload,
|
||||||
ExtensionSearchAndReplace,
|
ExtensionSearchAndReplace,
|
||||||
|
ExtensionClearFormat,
|
||||||
],
|
],
|
||||||
parseOptions: {
|
parseOptions: {
|
||||||
preserveWhitespace: true,
|
preserveWhitespace: true,
|
||||||
|
|
Loading…
Reference in New Issue