Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add the clear format function to the default rich text editor #5685

Merged
merged 3 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ui/packages/editor/src/dev/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
ExtensionTrailingNode,
ExtensionListKeymap,
ExtensionSearchAndReplace,
ExtensionClearFormat,
} from "../index";

const content = useLocalStorage("content", "");
Expand Down Expand Up @@ -111,6 +112,7 @@ const editor = useEditor({
ExtensionTrailingNode,
ExtensionListKeymap,
ExtensionSearchAndReplace,
ExtensionClearFormat,
],
parseOptions: {
preserveWhitespace: true,
Expand Down
35 changes: 35 additions & 0 deletions ui/packages/editor/src/extensions/clear-format/index.ts
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 3 additions & 0 deletions ui/packages/editor/src/extensions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import ExtensionDraggable from "./draggable";
import ExtensionNodeSelected from "./node-selected";
import ExtensionTrailingNode from "./trailing-node";
import ExtensionSearchAndReplace from "./search-and-replace";
import ExtensionClearFormat from "./clear-format";

const allExtensions = [
ExtensionBlockquote,
Expand Down Expand Up @@ -100,6 +101,7 @@ const allExtensions = [
ExtensionNodeSelected,
ExtensionTrailingNode,
ExtensionSearchAndReplace,
ExtensionClearFormat,
];

export {
Expand Down Expand Up @@ -147,4 +149,5 @@ export {
ExtensionTrailingNode,
ExtensionListKeymap,
ExtensionSearchAndReplace,
ExtensionClearFormat,
};
1 change: 1 addition & 0 deletions ui/packages/editor/src/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,4 @@ editor:
text:
default: Default
line_height: Line height
clear_format: Clear format
1 change: 1 addition & 0 deletions ui/packages/editor/src/locales/zh-CN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,4 @@ editor:
text:
default: 默认
line_height: 行高
clear_format: 清除格式
2 changes: 2 additions & 0 deletions ui/src/components/editor/DefaultEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
DecorationSet,
ExtensionListKeymap,
ExtensionSearchAndReplace,
ExtensionClearFormat,
} from "@halo-dev/richtext-editor";
// ui custom extension
import {
Expand Down Expand Up @@ -396,6 +397,7 @@ onMounted(() => {
ExtensionListKeymap,
UiExtensionUpload,
ExtensionSearchAndReplace,
ExtensionClearFormat,
],
parseOptions: {
preserveWhitespace: true,
Expand Down