Skip to content

Commit

Permalink
feat: add the clear format function to the default editor
Browse files Browse the repository at this point in the history
  • Loading branch information
LIlGG committed Apr 10, 2024
1 parent 95ec1c1 commit 31a121d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
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,
};
3 changes: 2 additions & 1 deletion ui/packages/editor/src/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ editor:
audio: Audio
table: Table
no_results: No results
placeholder: "Enter / to select input type"
placeholder: Enter / to select input type
link:
add_link: Add link
edit_link: Edit link
Expand Down Expand Up @@ -131,3 +131,4 @@ editor:
restore_default: Restore default
text:
default: Default
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 @@ -131,3 +131,4 @@ editor:
restore_default: 恢复为默认
text:
default: 默认
clear_format: 清除格式

0 comments on commit 31a121d

Please sign in to comment.